Skip to content

Commit a554ef0

Browse files
authored
Remove azcore multitenant auth API (Azure#20572)
1 parent 0a42300 commit a554ef0

17 files changed

+22
-58
lines changed

sdk/azcore/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
### Breaking Changes
99
> These changes affect only code written against a beta version such as v1.5.0-beta.1
10-
* Removed `TokenRequestOptions.Claims`
11-
* Removed CAE support for ARM clients
10+
> These features will return in v1.6.0-beta.1.
11+
* Removed `TokenRequestOptions.Claims` and `.TenantID`
12+
* Removed ARM client support for CAE and cross-tenant auth.
1213

1314
### Bugs Fixed
1415
* Added non-conformant LRO terminal states `Cancelled` and `Completed`.

sdk/azcore/arm/policy/policy.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ import (
1414

1515
// BearerTokenOptions configures the bearer token policy's behavior.
1616
type BearerTokenOptions struct {
17-
// AuxiliaryTenants are additional tenant IDs for authenticating cross-tenant requests.
18-
// The policy will add a token from each of these tenants to every request. The
19-
// authenticating user or service principal must be a guest in these tenants, and the
20-
// policy's credential must support multitenant authentication.
21-
AuxiliaryTenants []string
22-
2317
// Scopes contains the list of permission scopes required for the token.
2418
Scopes []string
2519
}

sdk/azcore/arm/runtime/pipeline.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ func NewPipeline(module, version string, cred azcore.TokenCredential, plOpts azr
2929
return azruntime.Pipeline{}, err
3030
}
3131
authPolicy := NewBearerTokenPolicy(cred, &armpolicy.BearerTokenOptions{
32-
AuxiliaryTenants: options.AuxiliaryTenants,
33-
Scopes: []string{conf.Audience + "/.default"},
32+
Scopes: []string{conf.Audience + "/.default"},
3433
})
3534
perRetry := make([]azpolicy.Policy, len(plOpts.PerRetry), len(plOpts.PerRetry)+1)
3635
copy(perRetry, plOpts.PerRetry)

sdk/azcore/arm/runtime/policy_bearer_token.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"strings"
11-
"time"
1211

1312
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
1413
armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy"
@@ -27,19 +26,6 @@ type acquiringResourceState struct {
2726
tenant string
2827
}
2928

30-
// acquire acquires or updates the resource; only one
31-
// thread/goroutine at a time ever calls this function
32-
func acquire(state acquiringResourceState) (newResource azcore.AccessToken, newExpiration time.Time, err error) {
33-
tk, err := state.p.cred.GetToken(state.ctx, azpolicy.TokenRequestOptions{
34-
Scopes: state.p.scopes,
35-
TenantID: state.tenant,
36-
})
37-
if err != nil {
38-
return azcore.AccessToken{}, time.Time{}, err
39-
}
40-
return tk, tk.ExpiresOn, nil
41-
}
42-
4329
// BearerTokenPolicy authorizes requests with bearer tokens acquired from a TokenCredential.
4430
type BearerTokenPolicy struct {
4531
auxResources map[string]*temporal.Resource[azcore.AccessToken, acquiringResourceState]
@@ -56,10 +42,6 @@ func NewBearerTokenPolicy(cred azcore.TokenCredential, opts *armpolicy.BearerTok
5642
opts = &armpolicy.BearerTokenOptions{}
5743
}
5844
p := &BearerTokenPolicy{cred: cred}
59-
p.auxResources = make(map[string]*temporal.Resource[azcore.AccessToken, acquiringResourceState], len(opts.AuxiliaryTenants))
60-
for _, t := range opts.AuxiliaryTenants {
61-
p.auxResources[t] = temporal.NewResource(acquire)
62-
}
6345
p.scopes = make([]string, len(opts.Scopes))
6446
copy(p.scopes, opts.Scopes)
6547
p.btp = azruntime.NewBearerTokenPolicy(cred, opts.Scopes, &azpolicy.BearerTokenOptions{

sdk/azcore/arm/runtime/policy_bearer_token_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func TestBearerPolicy_GetTokenFailsNoDeadlock(t *testing.T) {
163163
}
164164

165165
func TestAuxiliaryTenants(t *testing.T) {
166+
t.Skip("unskip this test after restoring cross-tenant auth support")
166167
srv, close := mock.NewTLSServer()
167168
defer close()
168169
srv.SetResponse(mock.WithStatusCode(http.StatusOK))
@@ -176,13 +177,13 @@ func TestAuxiliaryTenants(t *testing.T) {
176177
getTokenImpl: func(ctx context.Context, options azpolicy.TokenRequestOptions) (azcore.AccessToken, error) {
177178
require.False(t, expectCache, "client should have used a cached token instead of requesting another")
178179
tenant := primary
179-
if options.TenantID != "" {
180-
tenant = options.TenantID
181-
}
180+
// if options.TenantID != "" {
181+
// tenant = options.TenantID
182+
// }
182183
return azcore.AccessToken{Token: tenant, ExpiresOn: time.Now().Add(time.Hour).UTC()}, nil
183184
},
184185
},
185-
&armpolicy.BearerTokenOptions{AuxiliaryTenants: auxTenants, Scopes: []string{scope}},
186+
&armpolicy.BearerTokenOptions{ /*AuxiliaryTenants: auxTenants,*/ Scopes: []string{scope}},
186187
)
187188
pipeline := newTestPipeline(&azpolicy.ClientOptions{Transport: srv, PerRetryPolicies: []azpolicy.Policy{b}})
188189
expected := strings.Split(shared.BearerTokenPrefix+strings.Join(auxTenants, ","+shared.BearerTokenPrefix), ",")

sdk/azcore/internal/exported/exported.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ type AccessToken struct {
5353
type TokenRequestOptions struct {
5454
// Scopes contains the list of permission scopes required for the token.
5555
Scopes []string
56-
57-
// TenantID identifies the tenant from which to request the token. azidentity credentials authenticate in
58-
// their configured default tenants when this field isn't set.
59-
TenantID string
6056
}
6157

6258
// TokenCredential represents a credential capable of providing an OAuth token.

sdk/azidentity/azidentity_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ func Test_NonHTTPSAuthorityHost(t *testing.T) {
279279
}
280280

281281
func TestAdditionallyAllowedTenants(t *testing.T) {
282+
t.Skip("unskip this test after restoring TokenRequestOptions.TenantID")
282283
af := filepath.Join(t.TempDir(), t.Name()+credNameWorkloadIdentity)
283284
if err := os.WriteFile(af, []byte("assertion"), os.ModePerm); err != nil {
284285
t.Fatal(err)
@@ -320,7 +321,7 @@ func TestAdditionallyAllowedTenants(t *testing.T) {
320321
err: true,
321322
},
322323
} {
323-
tro := policy.TokenRequestOptions{Scopes: []string{liveTestScope}, TenantID: test.tenant}
324+
tro := policy.TokenRequestOptions{Scopes: []string{liveTestScope}}
324325
for _, subtest := range []struct {
325326
ctor func(azcore.ClientOptions) (azcore.TokenCredential, error)
326327
env map[string]string

sdk/azidentity/azure_cli_credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *AzureCLICredential) GetToken(ctx context.Context, opts policy.TokenRequ
8181
}
8282

8383
func (c *AzureCLICredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
84-
b, err := c.tokenProvider(ctx, opts.Scopes[0], opts.TenantID)
84+
b, err := c.tokenProvider(ctx, opts.Scopes[0], "")
8585
if err != nil {
8686
return azcore.AccessToken{}, err
8787
}

sdk/azidentity/azure_cli_credential_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestAzureCLICredential_GetTokenInvalidToken(t *testing.T) {
6565
}
6666

6767
func TestAzureCLICredential_TenantID(t *testing.T) {
68+
t.Skip("unskip this test after restoring TokenRequestOptions.TenantID")
6869
expected := "expected-tenant-id"
6970
called := false
7071
options := AzureCLICredentialOptions{

sdk/azidentity/client_assertion_credential.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ func (c *ClientAssertionCredential) GetToken(ctx context.Context, opts policy.To
6868
}
6969

7070
func (c *ClientAssertionCredential) silentAuth(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
71-
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
71+
ar, err := c.client.AcquireTokenSilent(ctx, opts.Scopes)
7272
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
7373
}
7474

7575
func (c *ClientAssertionCredential) requestToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
76-
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes, confidential.WithTenantID(opts.TenantID))
76+
ar, err := c.client.AcquireTokenByCredential(ctx, opts.Scopes)
7777
return azcore.AccessToken{Token: ar.AccessToken, ExpiresOn: ar.ExpiresOn.UTC()}, err
7878
}
7979

0 commit comments

Comments
 (0)