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

aws rds generate-db-auth-token creates invalid token when executed inside ECS container #3639

Closed
ejoebstl opened this issue Oct 7, 2018 · 6 comments
Assignees
Labels
assume-role rds service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@ejoebstl
Copy link

ejoebstl commented Oct 7, 2018

I've created a small service which uses IAM to connect to a postgres database, according to the documentation.

export PGPASSWORD=$(aws rds generate-db-auth-token --hostname ${POSTGRES_HOST} --port ${POSTGRES_PORT} --username ${POSTGRES_USER} --region ${REGION})
psql -h "${POSTGRES_HOST}" -p "${POSTGRES_PORT}" -U ${POSTGRES_USER} "dbname=${POSTGRES_DATABASE}  sslmode=verify-full sslrootcert=rds_root.pem"

This works fine when I execute it on the local machine using the same policy.

However, when I execute inside a container deployed to ECS, authentication fails with the returned token. The error is: psql: FATAL: PAM authentication failed for user "backup_user".

Also, the token returned by the command is significantly longer when invoked on ECS. More specifically, it contains an additional very large parameter called X-Amz-Security-Token=.

I have verified that all environment variables are equal. When the extra parameter is removed, the created tokens are equal except timestamps and signatures.

When the token from ECS is copied to a local machine (where the commands work), the authentication also fails.

@ejoebstl ejoebstl changed the title aws rds generate-db-auth-token creates invalid token when executed inside ECS container aws rds generate-db-auth-token creates invalid token when executed inside ECS container Oct 7, 2018
@justnance
Copy link

@ejoebstl - Thank you for reaching out. Based on the information provided so far it appears the IAM role and related policies on the ECS containers may not have sufficient permission to connect to the RDS database. Please review the online documentation below and confirm the container has the correct IAM permissions. Just wanted to add:

Thanks.

ECS IAM Policies
Amazon ECS Task Role

@justnance justnance self-assigned this Oct 10, 2018
@justnance justnance added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 10, 2018
@ejoebstl
Copy link
Author

ejoebstl commented Oct 10, 2018

Hello,

yes, while I initially assumed that this is a cli issue, it seems like a permission issue. I'm currently investigating together with the ecs agent team here.

I'm closing this issue.

Thanks!

@no-response no-response bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 10, 2018
@Matv1989
Copy link

Matv1989 commented Oct 13, 2018

Hi @ejoebstl ,
I've spent about a week on this problem with AWS support and they confirm that there is an AWS issue. In my case I was not able to create from EC2, but I hope my forum thread would be helpful to you.
https://forums.aws.amazon.com/thread.jspa?threadID=291106
Basically, the thing is that role attached to EC2 generates incorrect token until role assumed explicitlycfrom either cli or sdk, and request to RDS (aws rds generate-db-auth-token) is made with temporary credentials generated by this explicit operation.

@ejoebstl
Copy link
Author

Thank you - we came to the same conclusion from the other issue.

@ejoebstl
Copy link
Author

ejoebstl commented May 1, 2019

No, the discussion continued in the referenced issue. I will ask to re-open it.

@justnance justnance added the service-api This issue is due to a problem in a service API, not the SDK implementation. label May 3, 2019
@priyeshn
Copy link

priyeshn commented Mar 1, 2023

Is there a solution for this issue ? Im facing same problem when connecting to RDS from ECS/Fargate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assume-role rds service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

4 participants