Skip to content

Commit 663da87

Browse files
authored
[aztables] Fix the token audiences of aztables for sovereign clouds (#25534)
Fix the token audiences of aztables in sovereign cloud. Unlike Cosmos, Azure Storage uses the same audience for all clouds, sovereign and public. Fixes #25542
1 parent 0193851 commit 663da87

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

sdk/data/aztables/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
* Fix an issue that the Storage Table token audiences for sovereign clouds are incorrect.
1011

1112
### Other Changes
1213

sdk/data/aztables/cloud_config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
1111
const ServiceName cloud.ServiceName = "data/aztables"
1212

1313
func init() {
14+
// for Azure Table Storage endpoints, these values are ignored as the audience is always "https://storage.azure.com"
15+
// for Cosmos endpoints, we will use the audiences as specified here
1416
cloud.AzureChina.Services[ServiceName] = cloud.ServiceConfiguration{
15-
Audience: "https://storage.azure.cn",
17+
Audience: "https://cosmos.azure.cn",
1618
}
1719
cloud.AzureGovernment.Services[ServiceName] = cloud.ServiceConfiguration{
18-
Audience: "https://storage.azure.us",
20+
Audience: "https://cosmos.azure.us",
1921
}
2022
cloud.AzurePublic.Services[ServiceName] = cloud.ServiceConfiguration{
21-
Audience: "https://storage.azure.com",
23+
Audience: "https://cosmos.azure.com",
2224
}
2325
}

sdk/data/aztables/service_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ func NewServiceClient(serviceURL string, cred azcore.TokenCredential, options *C
3939
return nil, errors.New("cloud configuration is missing for Azure Tables")
4040
}
4141

42-
audience := cfg.Audience
42+
// unlike Cosmos, Azure Table Storage uses the same audience for all clouds, public and sovereign.
43+
audience := "https://storage.azure.com"
4344
if isCosmosEndpoint(serviceURL) {
44-
audience = strings.Replace(audience, "storage", "cosmos", 1)
45+
audience = cfg.Audience
4546
}
4647

4748
plOpts := runtime.PipelineOptions{

sdk/data/aztables/service_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func TestNewServiceClient_sovereignClouds(t *testing.T) {
482482
{
483483
label: "storage China",
484484
endpoint: "https://myAccountName.table.core.windows.net",
485-
scope: "https://storage.azure.cn/.default",
485+
scope: "https://storage.azure.com/.default",
486486
cfg: cloud.AzureChina,
487487
},
488488
{
@@ -494,7 +494,7 @@ func TestNewServiceClient_sovereignClouds(t *testing.T) {
494494
{
495495
label: "storage USGov",
496496
endpoint: "https://myAccountName.table.core.windows.net",
497-
scope: "https://storage.azure.us/.default",
497+
scope: "https://storage.azure.com/.default",
498498
cfg: cloud.AzureGovernment,
499499
},
500500
{

0 commit comments

Comments
 (0)