Skip to content

aws rds generate-db-auth-token generating invalid token when using .aws/credentials to authenticate #8234

@scott-vandevoorde

Description

@scott-vandevoorde

Describe the bug

When using credentials files (.aws/credentials & .aws/config) to authenticate with aws, aws rds generate-db-auth-token generates an invalid token.

The invalid token is missing the field X-Amz-Security-Token

If I set environment variables AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN, the token is generated successfully and is usable.

Expected Behavior

I expect the cli to generate a working token

Current Behavior

an invalid token is generated. The db says password authentication failed for user "rdsproxyuser"

Reproduction Steps

  1. create an iam user
  2. add unrestricted access to the user { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "*", "Resource": "*" } ] }
  3. run aws configure
  4. enter your access key, secret acccess key and region
  5. test your cli access to aws. For example, run aws s3 ls and ensure it connects ok
  6. stand up an aurora serverless v2 postgres RDS instance
  7. stand up an rds proxy and configure it for IAM authentication
  8. verify you can connect and login to the RDS proxy
  9. on the command line run aws rds generate-db-auth-token --hostname adhoc3-amber-engine.proxy-cfds9ixmayu4.us-east-1.rds.amazonaws.com --port 5432 --region us-east-1 --username rdsproxyuser (replace rds host name, and user name with the appropriate info)
  10. copy the generated token into an RDS connection and it will fail
  11. note that the token does not containt the field X-Amz-Security-Token
  12. Create a role with the following policy: { "Action": [ "rds-db:connect" ], "Resource": "arn:aws:rds-db:us-east-1:*:dbuser:*/*", "Effect": "Allow" }
  13. Update the trust policy so you can assume this role: { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::793478358630:user/scott" }, "Action": "sts:AssumeRole" }
  14. run the following command on the command line to assume the role and set your environment variablesexport $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \ $(aws sts assume-role \ --role-arn arn:aws:iam::793478358630:role/Adhoc3BastionStack-BastionHostRole-JDL6Y8KJ69VB \ --role-session-name Adhoc3BastionSession \ --query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \ --output text))
  15. run generate-db-auth-token again: aws rds generate-db-auth-token --hostname adhoc3-amber-engine.proxy-cfds9ixmayu4.us-east-1.rds.amazonaws.com --port 5432 --region us-east-1 --username rdsproxyuser
  16. copy the generated token and paste it to your rds connection.
  17. this time the token will work.
  18. Note that the token now contains X-Amz-Security-Token.

Possible Solution

trace the cli workflows between the two authentication mechanisms and figure out why the X-Amz-Security-Token is not being included in the token. Also recommend generating an error message instead of a bad tokens.

Additional Information/Context

Two co-workers validated the same behavior. One on windows and one on mac.

CLI version used

aws-cli/2.10.3 Python/3.9.11 Windows/10 exe/AMD64 prompt/off

Environment details (OS name and version, etc.)

tested on windows 10

Metadata

Metadata

Assignees

Labels

closing-soonThis issue will automatically close in 4 days unless further comments are made.p3This is a minor priority issuerds

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions