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

add AWS Secrets Manager related libraries for use in application configuration #329

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

esuomi
Copy link
Collaborator

@esuomi esuomi commented May 31, 2024

Motivation:

In short, our AWS environment configuration relies on these libraries to keep secrets secret without inclusion in plaintext to project metafiles and also allow for keeping the configuration short :-)

Both of these libraries are visible in configuration only. As a pseudo example, these are utilized like so:

# imports '/uttu/database/credentials' secrets (JSON blob) as structured
# properties into current configuration, with prefix key uttudb.
spring.config.import=aws-secretsmanager:/uttu/database/credentials?prefix=uttudb.

# wrap DataSource driver with AWS Secrets Manager aware driver...
spring.datasource.driver-class-name=com.amazonaws.secretsmanager.sql.AWSSecretsManagerPostgreSQLDriver

# ...which is then given a parameterized special JDBC connection URI...
spring.datasource.url=jdbc-secretsmanager:postgresql://${uttudb.host}:${uttudb.port}/${uttudb.dbname}?currentSchema=${uttudb.dbname}

# ...and Secrets Manager key name to look up database's secrets and other
# parameters without ever including direct values into the application configuration itself
spring.datasource.username=/uttu/database/credentials

Both of these libraries utilize AWS' automatic identity management based on where the code is running, meaning the runtime environment itself has automatically access to specific resources without need to carry e.g. secret key as part of the deployment, only the references to where such key would be found.

On more nifty thing is that this also allows for rotating credentials without redeployment, as AWSSecretsManagerPostgreSQLDriver will re-resolve the credentials on authentication errors.

@testower
Copy link
Collaborator

Just wondering, we use GCP's secret manager for similar purposes, but have avoided including libraries for this by injecting them as kubernetes secrets in the kubernetes cluster. Would you be able to do something similar in your setup?

@esuomi
Copy link
Collaborator Author

esuomi commented May 31, 2024

We use AWS ECS Fargate which doesn't quite have the same concepts as k8s pods, although there are similarities and to some extents some similar facilities are available.

Anyway, AWS' vendor lock-in kinda wants people to do things with these libraries and avoid using static locations (k8s secrets are, to my understanding, specially provided small files in container's filesystem?), and while it should be possible to provide the values from environment variables, I do have to ask our infra person how he sees this + he knows better if it would fit with the overall cloud environment development and administration guidelines.

Lets keep this open for now and come back to this early next week. I'll let you know when I have more to share.

@esuomi
Copy link
Collaborator Author

esuomi commented Jun 3, 2024

@testower Here's what our infra person had to say:

Fargate supports passing secrets as parameters so that they're not exposed through environment making it an "okay" (his quotes, not mine) solution for running services. However for long running services this binds credential lifecycle to the deployment itself, effectively blocking credential rotation. To quote https://docs.aws.amazon.com/AmazonECS/latest/developerguide/security-secrets-management.html

Secrets that are referenced in tasks aren't rotated automatically. If your secret changes, you must force a new deployment or launch a new task to retrieve the latest secret value.

To summarize, AWS recommends one of the these two options for handling credentials:

My recommendation would be to use the programmatic approach because it decouples credential rotation from service lifecycle, and would match with the other infrastructure already built for TIS (=Fintraffic Travel Information Services, our umbrella project) where we already do automatic periodic DB credentials rotation as per customer's security requirements.

@testower testower merged commit c48ad0e into entur:master Jun 4, 2024
2 checks passed
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