我正在尝试使用多重应用程序和azcopy工具来同步不同帐户中的Azure容器中的数据。
同步通过"azcopy“进行,并对源存储帐户和目标存储帐户使用单独的SAS令牌。
我正在使用Java按照用户委托密钥方法生成短暂的sas令牌。
下面是一个场景:
Account1 (目的地)注册了App1。也就是说,Account1是App1的家租户。Account1已经配置了StorageAccount1和Container1,App1在StorageAccount1上被赋予了“存储块数据贡献者”的角色
Account2 (源)配置了StorageAccount2和Container2。它是我们的数据源。在这里,App1是通过以下方式作为ServicePrincipal添加的:
az ad sp create --id client-id-of-App1-in-Account1在Account2中,对于这个SP,我们还赋予了角色如下:
az role assignment create \
--assignee-object-id <object-id-for-this-sp> \
--role 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1 \
--scope /subscriptions/<subsid-account2>/resourceGroups/<resgrpname>/providers/Microsoft.Storage/storageAccounts/<storagename>这就完成了设置。
现在,使用Java,我为源和目的地生成了一个用户委托键。片段看起来如下所示。
genSasToken(String storageAccountName, String containerName,
String tenantId,
String azureAppClientId,
String azureAppClientSecret,
boolean isDestinationAccount) {
BlobContainerSasPermission blobContainerSasPermission =
new BlobContainerSasPermission().setReadPermission(true).setListPermission(true);
if (isDestinationAccount) {
blobContainerSasPermission.setCreatePermission(true)
.setAddPermission(true)
.setWritePermission(true)
.setExecutePermission(true);
}
BlobServiceSasSignatureValues builder =
new BlobServiceSasSignatureValues(OffsetDateTime.now().plusHours(1), blobContainerSasPermission)
.setProtocol(SasProtocol.HTTPS_ONLY);
// Create a BlobServiceClient object which will be used to create a container client
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net",
storageAccountName);
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(azureAppClientId)
.clientSecret(azureAppClientSecret)
.tenantId(tenantId)
.build();
BlobServiceClient blobServiceClient =
new BlobServiceClientBuilder().endpoint(endpoint).credential(clientSecretCredential).buildClient();
BlobContainerClient blobContainerClient =
blobServiceClient.getBlobContainerClient(containerName);
// Get a user delegation key for the Blob service that's valid for one hour.
// You can use the key to generate any number of shared access signatures over the lifetime of the key.
OffsetDateTime keyStart = OffsetDateTime.now();
OffsetDateTime keyExpiry = OffsetDateTime.now().plusHours(1);
UserDelegationKey userDelegationKey = blobServiceClient.getUserDelegationKey(keyStart, keyExpiry);
String sas = blobContainerClient.generateUserDelegationSas(builder, userDelegationKey);
return sas;
}对源和目的地都调用了上述方法,并为我们提供了以编程方式生成的SAS令牌。
有趣的事情是:
偶联同步https://storageaccount2/container2/?sas-token-for2 https://storageaccount1/container1/?sas-token-for1
以上同步错误为
INFO: Authentication failed, it is either not correct, or expired, or does not have the correct permission -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /Users/runner/go/pkg/mod/github.com/!azure/azure-storage-blob-go@v0.10.1-0.20201022074806-8d8fc11be726/azblob/zc_storage_error.go:42
===== RESPONSE ERROR (ServiceCode=AuthorizationFailure) =====
Description=This request is not authorized to perform this operation.
RequestId:xxx
Time:2021-01-27T10:26:34.9282634Z, Details:
Code: AuthorizationFailure
GET https://storageaccount1.blob.core.windows.net/container1/?comp=properties&restype=account&se=2021-01-27t11%3A10%3A12z&sig=-REDACTED-&ske=2021-01-27t11%3A10%3A12z&skoid=xxx&sks=b&skt=2021-01-27t10%3A10%3A12z&sktid=xxx&skv=2020-02-10&sp=racwle&spr=https&sr=c&sv=2020-02-10&timeout=901
User-Agent: [AzCopy/10.8.0 Azure-Storage/0.10 (go1.13; darwin)]
X-Ms-Client-Request-Id: [xxx]
X-Ms-Version: [2019-12-12]
--------------------------------------------------------------------------------
RESPONSE Status: 403 This request is not authorized to perform this operation.
Content-Length: [246]
Content-Type: [application/xml]
Date: [Wed, 27 Jan 2021 10:26:34 GMT]
Server: [Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0]
X-Ms-Client-Request-Id: [xxx]
X-Ms-Error-Code: [AuthorizationFailure]
X-Ms-Request-Id: [xxx]
X-Ms-Version: [2019-12-12]但是,当我尝试使用相同的sas令牌2从源复制到本地主机时,它可以工作。
偶联同步https://storageaccount2/container2/sas-token-for2 /tmp
和
当我尝试使用相同的sas令牌将localhost文件夹复制到目的地时,它也可以工作。
偶联同步/tmp https://storageaccount1/container1/sas-token-for1
所以这些代币像上面那样单独工作。
但是azcopy https://storageaccount2/container2/sas-token-for2 https://storageaccount1/container1/sas-token-for1
失败.
有什么建议,这里有什么问题吗?
发布于 2021-02-07 15:13:07
为了同步,您不需要执行权限(在任何情况下,该权限仍然处于预览状态)。只要去掉.setExecutePermission(true),你就应该很好。事实上,同步应该只在目标上使用读、写和列表权限。
https://stackoverflow.com/questions/65923143
复制相似问题