-
Notifications
You must be signed in to change notification settings - Fork 23
Add tutorial on using Google Cloud Secret Manager with Okteto #996
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
Open
codyjlandstrom
wants to merge
5
commits into
main
Choose a base branch
from
cody/gcp-secrets-manager-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
299b9ae
add page on integration with GCP Secrets Manager
codyjlandstrom 07f04e6
add the new page
codyjlandstrom aa6f5ae
Merge remote-tracking branch 'origin/main' into cody/gcp-secrets-mana…
codyjlandstrom a6f1a54
docs(tutorials): add Google Cloud Secret Manager tutorial
codyjlandstrom 6d5d1dc
docs(tutorials): move GCP Secret Manager page out of admin integrations
codyjlandstrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| --- | ||
| title: Using Google Cloud Secret Manager with Okteto | ||
| description: Inject secrets stored in Google Cloud Secret Manager into your Okteto Development and Preview Environments | ||
| id: gcp-secret-manager | ||
| --- | ||
|
|
||
| [Google Cloud Secret Manager](https://cloud.google.com/security/products/secret-manager) stores API keys, passwords, certificates, and other sensitive data in your GCP account. Okteto can retrieve these secrets when deploying your application, so your Development and Preview Environments use the same secret store as the rest of your infrastructure and developers never handle the secret values directly. | ||
|
|
||
| This tutorial deploys the [okteto-community/gcp-secret-manager](https://github.com/okteto-community/gcp-secret-manager) sample application: a Go web server that reads its configuration from an `.env` file created at deploy time from a secret stored in Secret Manager. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Admin access to an Okteto instance | ||
| - A GCP project with the [Secret Manager API enabled](https://cloud.google.com/secret-manager/docs/configuring-secret-manager) | ||
| - The [gcloud CLI](https://cloud.google.com/sdk/docs/install) installed and authenticated against your GCP project | ||
| - The [Okteto CLI](/docs/get-started/install-okteto-cli/) installed and configured | ||
|
|
||
| ## Giving your Okteto instance access to your GCP account | ||
|
|
||
| Okteto authenticates to GCP with a dedicated service account whose key you store as [Admin Variables](/docs/core/okteto-variables/#admin-variables). Admin Variables are available to the deploy commands of every Development and Preview Environment in your Okteto instance. | ||
|
|
||
| 1. [Create a service account](https://cloud.google.com/iam/docs/service-accounts-create) for your Okteto instance. Grant it the minimum set of permissions it needs — for this tutorial, the `Secret Manager Secret Accessor` role is enough. | ||
| 2. [Create a service account key](https://cloud.google.com/iam/docs/keys-create-delete) and save it locally. | ||
| 3. In the Okteto Admin Dashboard, navigate to **Admin → Variables** and create the following Admin Variables: | ||
| - `GCP_PROJECT_ID`: the ID of the GCP project you are using | ||
| - `GCP_SERVICE_KEY`: the base64-encoded value of the service account key you created | ||
|
|
||
| You can generate the base64 value of the key with: | ||
|
|
||
| ```bash | ||
| base64 -i <path-to-your-service-account-key>.json | ||
| ``` | ||
|
|
||
| :::tip | ||
| If you prefer not to manage long-lived service account keys, you can configure keyless authentication with [Workload Identity Federation](/docs/admin/cloud-credentials/gcp-cloud-credentials/) instead. The rest of this tutorial uses the service account key approach. | ||
| ::: | ||
|
|
||
| ## Creating the secret | ||
|
|
||
| The sample application expects a secret named `top-secret-information` containing an `.env` file with two values. Create a local file with the secret content: | ||
|
|
||
| ```bash | ||
| echo -e "MY_NAME=cindy\nMY_COLOR=valencia green" > top-secret-information.txt | ||
| ``` | ||
|
|
||
| Create the secret in Secret Manager: | ||
|
|
||
| ```bash | ||
| gcloud secrets create top-secret-information --replication-policy="automatic" | ||
| ``` | ||
|
|
||
| Upload the file as the first version of the secret: | ||
|
|
||
| ```bash | ||
| gcloud secrets versions add top-secret-information --data-file=top-secret-information.txt | ||
| ``` | ||
|
|
||
| Verify the secret by retrieving it: | ||
|
|
||
| ```bash | ||
| gcloud secrets versions access latest --secret=top-secret-information | ||
| ``` | ||
|
|
||
| ## Deploying the Development Environment | ||
|
|
||
| Clone the sample repository and deploy it: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/okteto-community/gcp-secret-manager.git | ||
| cd gcp-secret-manager | ||
| okteto deploy | ||
| ``` | ||
|
|
||
| You can also deploy the repository directly from the Okteto UI. | ||
|
|
||
| The deploy section of the `okteto.yaml` in the sample repository authenticates to GCP using the Admin Variables you created, downloads the secret into an `.env` file, and deploys the application with it: | ||
|
|
||
| ```yaml | ||
| deploy: | ||
| # this image already contains the gcloud CLI, so developers don't need to | ||
| # install or configure anything except the Okteto CLI | ||
| image: google/cloud-sdk:alpine | ||
| commands: | ||
| - name: Configure GCP credentials | ||
| command: | | ||
| echo ${GCP_SERVICE_KEY} | base64 -d | gcloud auth activate-service-account --key-file=- | ||
| gcloud --quiet config set project ${GCP_PROJECT_ID} | ||
|
|
||
| - name: Create the .env file using the secrets stored in Secret Manager | ||
| command: gcloud secrets versions access "latest" --secret=top-secret-information > .env-okteto | ||
|
|
||
| - name: Deploy the application | ||
| command: okteto deploy --file docker-compose.yaml | ||
| ``` | ||
|
|
||
| When the deploy finishes, open the endpoint Okteto created for you from the Okteto UI. The application reads `MY_NAME` and `MY_COLOR` from the `.env` file built from your secret: | ||
|
|
||
| ``` | ||
| Hi, my name is cindy, and my favorite color is valencia green | ||
| ``` | ||
|
|
||
| To use a different secret in your own application, change the `--secret` flag in the deploy command to the name of your secret. Secrets are downloaded only during deployment — rotate a secret in Secret Manager and redeploy to pick up the new value. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do this with https://www.okteto.com/docs/1.43/admin/cloud-credentials/ instead.