Skip to content

Commit

Permalink
storage: configure resource identifier for storage at runtime, so tha…
Browse files Browse the repository at this point in the history
…t tokens are scoped to a particular storage account in the configured cloud
  • Loading branch information
manicminer committed Apr 9, 2024
1 parent faa31a2 commit e398ec6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func Build(ctx context.Context, builder ClientBuilder) (*Client, error) {
AuthorizerFunc: authorizerFunc,
},

AuthConfig: builder.AuthConfig,
Environment: builder.AuthConfig.Environment,
Features: builder.Features,

Expand Down
1 change: 1 addition & 0 deletions internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ApiAuthorizerFunc func(api environments.Api) (auth.Authorizer, error)

type ClientOptions struct {
Authorizers *Authorizers
AuthConfig *auth.Credentials
Environment environments.Environment
Features features.UserFeatures

Expand Down
4 changes: 2 additions & 2 deletions internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Client struct {
BlobServicesClient *storage.BlobServicesClient
FileServicesClient *storage.FileServicesClient

authorizerForAad auth.Authorizer
authConfig *auth.Credentials
}

func NewClient(o *common.ClientOptions) (*Client, error) {
Expand Down Expand Up @@ -95,7 +95,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}

if o.StorageUseAzureAD {
client.authorizerForAad = o.Authorizers.Storage
client.authConfig = o.AuthConfig
}

return &client, nil
Expand Down
34 changes: 20 additions & 14 deletions internal/services/storage/client/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ func (Client) DataPlaneOperationSupportingOnlySharedKeyAuth() DataPlaneOperation
}
}

func (c Client) configureDataPlane(ctx context.Context, clientName string, baseClient client.BaseClient, account accountDetails, operation DataPlaneOperation) error {
if operation.SupportsAadAuthentication && c.authorizerForAad != nil {
baseClient.SetAuthorizer(c.authorizerForAad)
func (c Client) configureDataPlane(ctx context.Context, clientName, resourceIdentifier string, baseClient client.BaseClient, account accountDetails, operation DataPlaneOperation) error {
if operation.SupportsAadAuthentication && c.authConfig != nil {
api := c.authConfig.Environment.Storage.WithResourceIdentifier(resourceIdentifier)
storageAuth, err := auth.NewAuthorizerFromCredentials(ctx, *c.authConfig, api)
if err != nil {
return fmt.Errorf("unable to build authorizer for Storage API: %+v", err)
}

baseClient.SetAuthorizer(storageAuth)
return nil
}

Expand Down Expand Up @@ -82,7 +88,7 @@ func (c Client) AccountsDataPlaneClient(ctx context.Context, account accountDeta
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -104,7 +110,7 @@ func (c Client) BlobsDataPlaneClient(ctx context.Context, account accountDetails
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -126,7 +132,7 @@ func (c Client) ContainersDataPlaneClient(ctx context.Context, account accountDe
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -148,7 +154,7 @@ func (c Client) DataLakeFilesystemsDataPlaneClient(ctx context.Context, account
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -170,7 +176,7 @@ func (c Client) DataLakePathsDataPlaneClient(ctx context.Context, account accoun
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -192,7 +198,7 @@ func (c Client) FileShareDirectoriesDataPlaneClient(ctx context.Context, account
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -214,7 +220,7 @@ func (c Client) FileShareFilesDataPlaneClient(ctx context.Context, account accou
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -236,7 +242,7 @@ func (c Client) FileSharesDataPlaneClient(ctx context.Context, account accountDe
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -258,7 +264,7 @@ func (c Client) QueuesDataPlaneClient(ctx context.Context, account accountDetail
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -280,7 +286,7 @@ func (c Client) TableEntityDataPlaneClient(ctx context.Context, account accountD
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand All @@ -302,7 +308,7 @@ func (c Client) TablesDataPlaneClient(ctx context.Context, account accountDetail
return nil, fmt.Errorf("building %s client: %+v", clientName, err)
}

err = c.configureDataPlane(ctx, clientName, apiClient.Client, account, operation)
err = c.configureDataPlane(ctx, clientName, *baseUri, apiClient.Client, account, operation)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e398ec6

Please sign in to comment.