【问题标题】:PHP Access to Private Azure Storage ContainerPHP 访问私有 Azure 存储容器
【发布时间】:2020-03-20 04:22:43
【问题描述】:

托管在 Azure VM 中的我的 PHP 应用程序需要访问存储在私有 Azure 存储容器中的图像。

有人实施了成功的方法吗?我有 3 个想法(如下)。

选项 1 - 使用 Azure 托管标识

  1. 为应用提供托管标识
  2. 为容器授予 RBAC 读取权限
  3. 在 PHP 中向 VM 实例元数据端点发出 curl 请求以获取访问令牌
  4. 在所有图像请求中使用此令牌(如何将令牌保留在我的应用中?)

选项 2 - 使用适用于 PHP 的 Azure BLOB 存储 SDK

  1. 使用 Azure Blob Storage SDK 检索图像
  2. 这需要将存储密钥从我的保管库返回到应用程序

选项 3 - 使用 Azure 共享访问签名

  1. 在 PHP 中为每个图像生成一个新的 SAS
  2. 需要存储帐户密钥

谢谢!

【问题讨论】:

    标签: php azure security storage azure-managed-identity


    【解决方案1】:

    根据您的需要和描述,我认为使用 Azure Managed Identity 访问 Azure 存储比其他方式更好。因为,根据您的描述,如果我们使用第二种或第三种方式,我们需要从 Azure 密钥库中获取存储密钥。它还需要我们使用 MSI 来访问它。此外,关于第三种方式,我们需要考虑 sas token 的生命周期。所以我建议你使用 MSI 来访问 Azure 存储。

    关于如何使用微星访问Azure存储,请参考document

    1. Configure managed identities fro VM vai Azure Portal

    2. Grant the VM access to an Azure Storage container

    3. 获取令牌

    Method: GET
    URL: http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://storage.azure.com/
    Headers: Metadata : true
    

    1. 测试。比如我把剩下的api调用到get blob
    Method: GET
    URL: https://myaccount.blob.core.windows.net/mycontainer/myblob
    Headers: 
             x-ms-version: 2019-02-02
             Authorization : Bearer <access_token> 
    

    【讨论】:

    • 太棒了,感谢您的回复,听起来是最好的选择。我试试看!
    猜你喜欢
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    • 2020-09-05
    • 2017-04-17
    • 2021-08-09
    • 2021-03-18
    • 2021-02-01
    • 1970-01-01
    相关资源
    最近更新 更多