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 GCP Secret Manager adapter #1236

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

andrelaszlo
Copy link

@andrelaszlo andrelaszlo commented Nov 20, 2024

GCP Secret Manager adapter

This PR adds the gcp_secret_manager adapter (aliased to gcp and secret_manager). It uses the gcloud CLI to fetch secrets from Google Cloud Platform's Secret Manager.

The motivation to add this comes from my experience deploying apps to GCP using Kamal. Suggestions are welcome.

Some features like secret versioning, service account impersonation, and delegation chains are specific to GCP so I spent some time experimenting with various ways to specify these things without changing the kamal secrets fetch interface. An alternative route might be to add a way to pass options other than --account to the adapter.

In addition to the unit tests I've also tested this a bit with my personal GCP projects, but it hasn't been used in production.

Features:

Usage:

# Fetch `my-secret` from the default project using the default credentials, these commands are equivalent
kamal secrets fetch --adapter=gcp_secret_manager --account=default my-secret
kamal secrets fetch --adapter=gcp --account=default my-secret
kamal secrets fetch --adapter=gcp_secret_manager --account=default default/my-secret
kamal secrets fetch --adapter=gcp_secret_manager --account=default default/my-secret/latest
kamal secrets fetch --adapter=gcp_secret_manager --account=default --from=default my-secret/latest

# Fetch `my-secret` and `another-secret` from the project `my-project`
kamal secrets fetch --adapter=gcp_secret_manager --account=default --from=my-project my-secret another-secret

# Fetch from multiple projects, using default to refer to the default project
kamal secrets fetch --adapter=gcp_secret_manager --account=default default/my-secret my-project/another-secret

# Fetch version 123 of the secret `my-secret` in the default project (the default behavior is to fetch `latest`)
kamal secrets fetch --adapter=gcp_secret_manager --account=default default/my-secret/123

# Fetch a secret using the `user@example.com` credentials
kamal secrets fetch --adapter=gcp_secret_manager --account=user@example.com my-secret

# Fetch a secret as `user@example.com`, impersonating ´service-account@example.com` with `delegate@example.com` as a delegate
kamal secrets fetch --adapter=gcp_secret_manager --account="user@example.com|delegate@example.com,service-account@example.com" my-secret

@andrelaszlo
Copy link
Author

@djmb I noticed you wrote the other adapters. Do you think this PR would be of use to the project?

Copy link
Collaborator

@djmb djmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @andrelaszlo!

GCP Secret Manager is definitely something we'd want to support, so would be happy to get this added.

I've made some suggestions for changes to the PR to get it ready to merge.

lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
lib/kamal/secrets/adapters/gcp_secret_manager.rb Outdated Show resolved Hide resolved
@andrelaszlo andrelaszlo requested a review from djmb December 6, 2024 16:54
@andrelaszlo
Copy link
Author

Thanks for the PR @andrelaszlo!

GCP Secret Manager is definitely something we'd want to support, so would be happy to get this added.

I've made some suggestions for changes to the PR to get it ready to merge.

Thank you for your thoughtful review @djmb. I've made all the changes you requested, synced with main, and made sure to run the full test suite as well ✔️

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