java azure blobs sas_azure-storage

我试图创建SAS的URI /令牌,让我的Azure存储的Blob下载。

我想这样做的一个blob级,为了不给无意中访问一个意想不到的资源。

当前的代码我用它来做到这一点:

public static string GetBlobSasUri(string containerName, string reference)

{

// Create the CloudBlobContainer object

CloudBlobContainer container = blobClient.GetContainerReference(containerName);

container.CreateIfNotExists();

// Get a reference to a blob within the container.

CloudBlockBlob blob = container.GetBlockBlobReference(reference);

// Set the expiry time and permissions for the blob.

// In this case, the start time is specified as a few minutes in the past, to mitigate clock skew.

// The shared access signature will be valid immediately.

SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();

sasConstraints.SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5);

sasConstraints.SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMonths(1);

sasConstraints.Permissions = SharedAccessBlobPermissions.Read;

// Generate the shared access signature on the blob, setting the constraints directly on the signature.

string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

// Return the URI string for the container, including the SAS token.

return blob.Uri + sasBlobToken;

}

这在很大程度上是基于在此文档中的例子:

这工作。但是,我看到其他SAS文件,它可以限制在一定的IP范围,以及:

我的SAS令牌的理解是,签名的标牌参数,所以我不认为这是因为刚刚追加我的IP范围到SAS URI从我上面贴的代码返回,因为签名会那么不匹配一样容易。

然而,SharedAccessBlobPolicy只有三个领域,这是访问的开始/结束时间,以及权限。我没有看到有关的IP范围任何东西。

是否有可能在BLOB水平产生SAS的URI时,没有一个完整的帐户设置这些许可的范围?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值