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

SaaS Boost API access via OAuth client credentials grant #450

Merged
merged 21 commits into from
Jan 10, 2023

Conversation

brtrvn
Copy link
Contributor

@brtrvn brtrvn commented Dec 13, 2022

When we upgraded the System User Service to use OAuth authorization_code grant for access to the SaaS Boost API instead of Amazon Cognito native authorization, we removed the lesser-known private API /token endpoint that returned an Identity Token for the SaaS Boost admin user.

This PR generates an application client with a secret to be used for client_credentials grant against the SaaS Boost API. It will return an Access Token with the equivalent permissions as the SaaS Boost admin user. This token can be used as a bearer token for any of the public SaaS Boost API resources.

The client's details are stored in Secrets Manager at /saas-boost/${ENVIRONMENT}/API_APP_CLIENT. Any client code wanting to perform computer-to-computer invocation of the SaaS Boost API will need to be given explicit allow permissions via IAM to access that secret.

DO NOT use this secret in a public client such as a JavaScript web app or a mobile application. This should only be used in backend server side code that is authorized.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

runtime. Add the API Gateway invoke URL to the app client secret details
so a client doesn't have to make another call to some other service to
figure it out.
@brtrvn brtrvn mentioned this pull request Jan 5, 2023
@@ -846,6 +846,7 @@ Resources:
CustomDomainName: !If [HasSystemIdPCustomDomain, !Ref SystemIdentityProviderDomain, '']
CustomDomainHostedZone: !If [HasSystemIdPCustomDomain, !Ref SystemIdentityProviderHostedZone, '']
CustomDomainCertificate: !If [HasSystemIdPCustomDomain, !Ref SystemIdentityProviderCertificate, '']
ApiGatewayUrl: !Sub https://${core.Outputs.SaaSBoostPublicApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/${PublicApiStage} #!GetAtt publicapi.Outputs.PublicApiGatewayEndpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we just use !GetAtt here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it would make a circular dependency with the saas-boost-public-api.yaml stack

Properties:
LogGroupName: !Sub /aws/lambda/sb-${Environment}-cognito-client-details
RetentionInDays: 30
CognitoAppClientDetailsExecRole:
Copy link
Contributor

Choose a reason for hiding this comment

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

We need Condition: UseCognito for this, since we refer to UserPool in the cognito-idp Allow.

Copy link
Contributor

@PoeppingT PoeppingT left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! Excited to see what we can do with automated testing using this change.

@PoeppingT PoeppingT merged commit 29dde04 into awslabs:main Jan 10, 2023
@brtrvn brtrvn deleted the api-client branch January 11, 2023 00:07
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.

2 participants