Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect aws-config token providers to service config via codegen #3443

Merged

Conversation

jdisanti
Copy link
Collaborator

This PR connects the token providers added in #3442 to the generated service config.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@jdisanti jdisanti marked this pull request as ready for review February 27, 2024 19:08
@jdisanti jdisanti requested a review from a team as a code owner February 27, 2024 19:08
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

Base automatically changed from jdisanti-default-token-provider to feature-sso-token-providers February 28, 2024 20:34
@jdisanti jdisanti force-pushed the jdisanti-wire-up-token-providers branch from 974a8d2 to 48d3ea4 Compare February 28, 2024 20:37
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good—I had some small refactoring suggestions

@@ -22,29 +24,38 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.pre
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization
import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization
import software.amazon.smithy.rust.codegen.core.util.letIf

class CredentialsProviderDecorator : ClientCodegenDecorator {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should rename this to SigV4CredentialsProviderDecorator

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly hesitant to make it more specific, but could be convinced. It applies to both SigV4 and SigV4a right now, and it could apply to more things in the future.

Comment on lines 33 to 36
private fun applies(codegenContext: ClientCodegenContext): Boolean =
ServiceIndex.of(codegenContext.model).getEffectiveAuthSchemes(codegenContext.serviceShape)
.containsKey(SigV4Trait.ID) || codegenContext.serviceShape.usesSigV4a()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are to clean up support for bearer-only services?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. For Code Catalyst, it doesn't make sense to have methods to configure credential providers since it doesn't use SigV4.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a breaking change?

Copy link
Collaborator Author

@jdisanti jdisanti Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it is in a way, in terms of compiling, except for that the service wouldn't have worked to begin with.

Edit: I'll double check that SigV4 auth didn't work with it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the currently released aws-sdk-codecatalyst doesn't actually work:

[src/main.rs:5] client.list_spaces().send().await = Err(
    DispatchFailure(
        DispatchFailure {
            source: ConnectorError {
                kind: Other(
                    None,
                ),
                source: NoMatchingAuthSchemeError(
                    ExploredList {
                        items: [
                            ExploredAuthOption {
                                scheme_id: AuthSchemeId {
                                    scheme_id: "http-bearer-auth",
                                },
                                result: NoIdentityResolver,
                            },
                        ],
                        truncated: false,
                    },
                ),
                connection: Unknown,
            },
        },
    ),
)

Comment on lines +54 to +71
val moduleName = ctx.moduleUseName()
rustTemplate(
"""
// this should compile
let _ = $moduleName::Config::builder()
.token_provider(#{TestToken}::for_tests())
.build();

// this should also compile
$moduleName::Config::builder()
.set_token_provider(Some(#{SharedTokenProvider}::new(#{TestToken}::for_tests())));
""",
"TestToken" to AwsRuntimeType.awsCredentialTypesTestUtil(ctx.runtimeConfig).resolve("Token"),
"SharedTokenProvider" to
AwsRuntimeType.awsCredentialTypes(ctx.runtimeConfig)
.resolve("provider::token::SharedTokenProvider"),
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to also test that the token is actually readable back? or do we have enough other tests of that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's currently no way to read back the other identity resolvers such as credentials providers. Seems like we should probably address that at some point, but the difference between ProvideCredentials and ResolveIdentity makes that difficult.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could have a pub(crate) method on config to read it?

Comment on lines +58 to +60
pub fn for_tests() -> Self {
Self::new("test-token", None)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws-config::ConfigLoader::with_test_credentials should set a token identity as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the test_credentials method? I do have the generated Config::with_test_defaults() method setting a token.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

Comment on lines +25 to +28
class CredentialsProviderDecorator : ConditionalDecorator(
predicate = { codegenContext, _ -> codegenContext?.usesSigAuth() ?: false },
delegateTo =
object : ClientCodegenDecorator {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can make this slightly cleaner like:

private class Unfiltered(....)

class CredentialsProviderDecorator: ConditionalDecorator(Unfiltered.Filter, Unfiltered())

might be a bit cleaner / less nesting? anyway, up to you

/**
* Delegating decorator that only applies when a condition is true
*/
open class ConditionalDecorator(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could actually live in codegen-client

Comment on lines +58 to +60
pub fn for_tests() -> Self {
Self::new("test-token", None)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +54 to +71
val moduleName = ctx.moduleUseName()
rustTemplate(
"""
// this should compile
let _ = $moduleName::Config::builder()
.token_provider(#{TestToken}::for_tests())
.build();

// this should also compile
$moduleName::Config::builder()
.set_token_provider(Some(#{SharedTokenProvider}::new(#{TestToken}::for_tests())));
""",
"TestToken" to AwsRuntimeType.awsCredentialTypesTestUtil(ctx.runtimeConfig).resolve("Token"),
"SharedTokenProvider" to
AwsRuntimeType.awsCredentialTypes(ctx.runtimeConfig)
.resolve("provider::token::SharedTokenProvider"),
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could have a pub(crate) method on config to read it?

Copy link

github-actions bot commented Mar 1, 2024

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@jdisanti jdisanti merged commit b49b88d into feature-sso-token-providers Mar 1, 2024
40 checks passed
@jdisanti jdisanti deleted the jdisanti-wire-up-token-providers branch March 1, 2024 01:54
github-merge-queue bot pushed a commit that referenced this pull request Mar 6, 2024
This PR adds support for SSO bearer token authentication to the AWS SDK,
specifically for Code Catalyst, which requires authentication via SSO
with a Builder ID using a bearer token rather than SigV4.

This functionality was developed in a feature branch, and this PR merely
merges that branch to main. The changes consist of the following
previous PRs:
- #3381
- #3442
- #3443

All these changes have been reviewed in the previous PRs, but it would
be good to review this again as a whole to verify it all looks good.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants