-
Notifications
You must be signed in to change notification settings - Fork 4.5k
aws rds generate-db-auth-token generating invalid token when using .aws/credentials to authenticate #8234
Description
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
- create an iam user
- add unrestricted access to the user
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "*", "Resource": "*" } ] } - run
aws configure - enter your access key, secret acccess key and region
- test your cli access to aws. For example, run
aws s3 lsand ensure it connects ok - stand up an aurora serverless v2 postgres RDS instance
- stand up an rds proxy and configure it for IAM authentication
- verify you can connect and login to the RDS proxy
- 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) - copy the generated token into an RDS connection and it will fail
- note that the token does not containt the field X-Amz-Security-Token
- Create a role with the following policy:
{ "Action": [ "rds-db:connect" ], "Resource": "arn:aws:rds-db:us-east-1:*:dbuser:*/*", "Effect": "Allow" } - Update the trust policy so you can assume this role:
{ "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::793478358630:user/scott" }, "Action": "sts:AssumeRole" } - run the following command on the command line to assume the role and set your environment variables
export $(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)) - 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 - copy the generated token and paste it to your rds connection.
- this time the token will work.
- 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