【问题标题】:Active Directory access Azure Storage from browserActive Directory 从浏览器访问 Azure 存储
【发布时间】:2021-12-13 22:48:46
【问题描述】:

我想使用 Azure Active Directory 允许用户从单页 Web 应用读取和写入 Azure 存储(特别是所有 Blob 和表)。

我是这样开始的:

import { InteractiveBrowserCredential } from '@azure/identity';
import { TableClient, TableServiceClient } from '@azure/data-tables';

const credentials = new InteractiveBrowserCredential({
  clientId: myAuthConfig.clientId,
  tenantId: myAuthConfig.tenantId,
});

const client = new TableServiceClient(
  `https://${myAuthConfig.storageAccountName}.table.core.windows.net`,
  credentials
);
client.listTables().byPage().next().then(console.log);

这完全没问题!我可以看到帐户上的所有表格。但后来我想列出表中的一些数据in。所以我做了:

const client = new TableClient(
  `https://${myAuthConfig.storageAccountName}.table.core.windows.net`,
  '<table name>',
  credentials
);
client.listEntities().byPage().next().then(console.log);

但这会报错:

{
  "odata.error": {
    "code":"AuthorizationPermissionMismatch",
    "message": {
      "lang":"en-US",
      "value":"This request is not authorized to perform this operation using this permission.\nRequestId:<uuid>\nTime:2021-10-28T18:04:00.0737419Z"
    }
  }
}

我对这个错误感到非常困惑。据我所知,我做的一切都是对的。我遵循了每个教程。我为我的应用设置了 Active Directory 权限以使用存储 API,我的 Microsoft 帐户有权访问表,启用了 OCRS,等等。

我不知道为什么我可以看到一张桌子,但看不到里面有什么。我尝试使用InteractiveBrowserCredential.authenticate 来明确设置这样的范围:

const scopes = ["User.Read"]

credentials.authenticate(scopes).then(console.log);

它适用于User.Read,但我无法弄清楚哪些范围对应于存储读/写访问。如果我添加了一个像 "Microsoft.Storage" 这样的 scopy,它会告诉我它不存在

以前有没有人遇到过这样的错误?我应该在这里做什么?

【问题讨论】:

标签: javascript azure azure-active-directory azure-storage azure-table-storage


【解决方案1】:

谢谢@gaurav mantri,在评论中发布您的建议作为答案。

从错误来看,您的服务主体似乎没有访问您的表存储数据的权限。您应该使用 RBAC 角色授予对存储帐户资源(添加到存储帐户参与者或读者)的权限,如下所示。或使用存储资源管理器授予权限。

在您的存储帐户中,请检查您是否按照@gaurav mantri 的评论分配了存储表数据贡献者/存储表数据读取者角色

如果没有,您可以添加它们 进入您的存储帐户 > IAM > 添加角色分配,并添加特殊权限

如果角色已分配,问题可能是由于存储帐户受到防火墙保护。请尝试在您的存储帐户的防火墙和虚拟网络中进行配置,以添加现有的虚拟网络或创建新的 vnet。如果没有问题,您可以允许从所有网络访问。

参考资料:

  1. Authorize access to tables using Active Directory - Azure Storage | Microsoft Docs
  2. Assign an Azure role for access to table data using powershell - Azure Storage | Microsoft Docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多