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

Fix for local-exec failure when updating trust policies. #237

Merged
merged 6 commits into from
Mar 22, 2023

Conversation

julialawrence
Copy link
Contributor

@julialawrence julialawrence commented Mar 22, 2023

https://dsdmoj.atlassian.net/browse/ANPL-1449

There were a few issues with the local-exec resource that is used to update trust policies of app roles:

  1. The arn that sts assume role was being passed as a parameter wasn't a role arn but the arn of the session (ie: had assumed-role in the arn)
  2. There was a problem with environment variables when using aws-vault to run locally, reporting an invalid session token error. This PR resolves both issues.

Changes in the PR

  • Instead of using aws_caller_identity terraform datasource to get the caller arn, this uses aws_session_context which converts the session arn to the role arn used to the session. Passing this into the sts assume role command resolves the Access Denied and can't assume role errors.
  • Inserts an if block into the local-exec command which unsets the AWS_SECURITY_TOKEN envvar if the caller identity is an SSO role (meaning the code is being run locally.) AWS cli appears to treat this envvar as higher priority than AWS_SESSION_TOKEN which caused Session token invalid errors. (ref: Pass credentials to local-exec OR extract credentials via properties hashicorp/terraform-provider-aws#8242 (comment))

Assuming no further errors, this PR has been tested to successfully amend trust policies of existing app roles to add the clause allowing assumption by CP service accounts.

@julialawrence julialawrence requested a review from a team March 22, 2023 19:11
@julialawrence julialawrence merged commit 7849666 into main Mar 22, 2023
@julialawrence julialawrence deleted the feature/fix-trust-policies branch March 22, 2023 21:24
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