Auth Scheme and Auth Scheme Resolver Customization Guidance #4197
ysaito1001
announced in
Change Log
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What are Auth Scheme and Auth Scheme Resolver?
An Auth Scheme is a data structure that consists of
sigv4
,http-basic-auth
)We define
AuthScheme
as a trait in theaws-smithy-runtime-api
crate.An Auth Scheme Resolver is a runtime component within the orchestrator that determines which auth scheme to use for that service. The following
crate::config::auth::ResolveAuthScheme
trait is code-generated per service.ResolveAuthScheme trait
What's Changing
You may need to customize auth schemes and an auth scheme resolver in scenarios such as:
The Rust SDK now allows you to configure them at the service client level or at the individual operation invocation level.
Note
For brevity, the code examples below demonstrate overriding at the service client level only. Overriding at the individual operation invocation level is also possible just like other configurations, as described here.
Also, the code examples arbitrarily use S3 for demonstration purposes.
How to Customize Auth Scheme
Auth schemes from a given Smithy model are code-generated as documented in the spec, and are recognized by the runtime. To override the default behavior, you can define a custom auth scheme by implementing the AuthScheme trait and pass it to the
.push_auth_scheme
method on a service config builder. Auth scheme customization can be done for two primary reasons: modifying existing schemes or registering new ones.Modifying existing auth scheme
For instance, you can customize the default
sigv4
auth scheme to modify its behavior, such as disabling request signing. Here's an example of how to implement this:Custom sigv4 auth scheme
You can then pass the custom auth scheme
CustomSigv4AuthScheme
to.push_auth_scheme
on the service config builder:Assuming the service models
siv4
, the code-generated default auth scheme resolver recognizesCustomSigv4AuthScheme
by its auth scheme ID, causing the smithy runtime to use itsDisabledSigner
as expected.Registering new auth scheme
You can define a custom auth scheme whose auth scheme ID is not yet known to the runtime.
New auth scheme
You can then pass
CustomAuthScheme
to.push_auth_scheme
on the service config builder.However, this code most likely will not work as expected because the default auth scheme resolver doesn't recognize the
auth scheme ID of
CustomAuthScheme
. To resolve this, you'll need to customize the auth scheme resolver as described in the next section.How to Customize Auth Scheme Resolver
The AWS SDK for Rust provides a code-generated default auth scheme resolver. The default resolver returns an ordered list of AuthSchemeOptions for modeled auth schemes. If you need to register a custom auth scheme with the ID not yet known to the runtime, you should define a custom auth scheme resolver by implementing the
crate::config::auth::ResolveAuthScheme
trait and pass it to the.auth_scheme_resolver
method on a service config builder.Building on the previous example from
Registering new auth scheme
, here's how to define a custom resolver:You can then pass
CustomAuthSchemeResolver
to.auth_scheme_resolver
on the service config builder.The orchestrator will use
CustomAuthSchemeResolver
, which prioritizes theCustomAuthScheme
. As a result, the identity resolver and the signer associated with it will be used during the identity resolution and signing.Beta Was this translation helpful? Give feedback.
All reactions