Berglas
A tool for managing secrets on Google Cloud
Install / Use
/learn @GoogleCloudPlatform/BerglasREADME
Berglas
Berglas is a command line tool and library for storing and retrieving secrets on Google Cloud. Secrets are encrypted with [Cloud KMS][cloud-kms] and stored in [Cloud Storage][cloud-storage]. An interoperable layer also exists with [Secret Manager][secret-manager].
-
As a CLI,
berglasautomates the process of encrypting, decrypting, and storing data on Google Cloud. -
As a library,
berglasautomates the inclusion of secrets into various Google Cloud runtimes.
Berglas is not an officially supported Google product.
Setup
Prerequisites
-
Install the [Cloud SDK][cloud-sdk] for your operating system. Alternatively, you can run these commands from [Cloud Shell][cloud-shell], which has the SDK and other popular tools pre-installed.
If you are running from your local machine, you also need Default Application Credentials:
gcloud auth application-default loginThis will open a web browser and prompt for a login to your Google account. On headless devices, you will need to create a service account. For more information, please see the authentication section.
-
Install the
berglasCLI using one of the following methods:-
Install a pre-compiled binary for your operating system from the latest releases.
-
Use an official Docker container:
docker run -it us-docker.pkg.dev/berglas/berglas/berglasNote: older Docker container images are available on Container Registry and Artifact Registry, but new versions are not published there.
-
Use Homebrew on macOS:
brew install berglasNote: sometimes the Homebrew formula can be several versions behind.
-
Install from source (requires a working Go installation):
go install github.com/GoogleCloudPlatform/berglas/v2@latest
-
-
Export your project ID as an environment variable. The rest of this setup guide assumes this environment variable is set:
export PROJECT_ID=my-gcp-project-idPlease note, this is the project ID, not the project name or project number. You can find the project ID by running
gcloud projects listor in the web UI.
Secret Manager Storage
-
Enable required services on the project:
gcloud services enable --project ${PROJECT_ID} \ secretmanager.googleapis.com
Cloud Storage Storage
-
Export your desired Cloud Storage bucket name. The rest of this setup guide assumes this environment variable is set:
export BUCKET_ID=my-secretsReplace
my-secretswith the name of your bucket. Set only the name, without thegs://prefix. This bucket should not exist yet! -
Enable required services on the project:
gcloud services enable --project ${PROJECT_ID} \ cloudkms.googleapis.com \ storage-api.googleapis.com \ storage-component.googleapis.com -
Bootstrap a Berglas environment. This will create a new Cloud Storage bucket for storing secrets and a Cloud KMS key for encrypting data.
berglas bootstrap --project $PROJECT_ID --bucket $BUCKET_IDThis command uses the default values. You can customize the storage bucket and KMS key configuration using the optional flags. Run
berglas bootstrap -hfor more details.If you want full control over the creation of the Cloud Storage and Cloud KMS keys, please see the [custom setup documentation][custom-setup].
-
(Optional) Bootstrap a Berglas environment specifying a bucket location. By default the berglas bucket is created in the multi-regional location
US. You can specify your location by using the following command. Please see the list of supported locations in the GCP bucket location documentation pageexport BUCKET_LOCATION=europe-west1 berglas bootstrap \ --project $PROJECT_ID \ --bucket $BUCKET_ID \ --bucket-location $BUCKET_LOCATIONThis command uses the default values. You can customize the storage bucket and KMS key configuration using the optional flags. Run
berglas bootstrap -hfor more details.If you want full control over the creation of the Cloud Storage and Cloud KMS keys, please see the [custom setup documentation][custom-setup].
-
(Optional) Enable [Cloud Audit logging][cloud-audit] on the bucket:
Please note this will enable audit logging on all Cloud KMS keys and all Cloud Storage buckets in the project, which may incur additional costs.
-
Download the exiting project IAM policy:
gcloud projects get-iam-policy ${PROJECT_ID} > policy.yaml -
Add Cloud Audit logging for Cloud KMS and Cloud Storage:
cat <<EOF >> policy.yaml auditConfigs: - auditLogConfigs: - logType: DATA_READ - logType: ADMIN_READ - logType: DATA_WRITE service: cloudkms.googleapis.com - auditLogConfigs: - logType: ADMIN_READ - logType: DATA_READ - logType: DATA_WRITE service: storage.googleapis.com EOF -
Submit the new policy:
gcloud projects set-iam-policy ${PROJECT_ID} policy.yaml -
Remove the updated policy from local disk:
rm policy.yaml
-
CLI Usage
-
Create a secret:
Using Secret Manager storage:
berglas create sm://${PROJECT_ID}/foo my-secret-dataUsing Cloud Storage storage:
berglas create ${BUCKET_ID}/foo my-secret-data \ --key projects/${PROJECT_ID}/locations/global/keyRings/berglas/cryptoKeys/berglas-key -
Grant access to a secret:
Using Secret Manager storage:
berglas grant sm://${PROJECT_ID}/foo --member user:user@mydomain.comUsing Cloud Storage storage:
berglas grant ${BUCKET_ID}/foo --member user:user@mydomain.com -
Access a secret's data:
Using Secret Manager storage:
berglas access sm://${PROJECT_ID}/foo my-secret-dataUsing Cloud Storage storage:
berglas access ${BUCKET_ID}/foo my-secret-data -
Spawn a child process with secrets populated in the child's environment:
berglas exec -- myapp --flag-a --flag-bThis will spawn
myappwith an environment parsed by berglas. -
Access data from a specific version/generation of a secret:
Using Secret Manager storage:
berglas access sm://${PROJECT_ID}/foo#1 my-previous-secret-dataUsing Cloud Storage storage:
berglas access ${BUCKET_ID}/foo#1563925940580201 my-previous-secret-data -
Revoke access to a secret:
Using Secret Manager storage:
berglas revoke sm://${PROJECT_ID}/foo --member user:user@mydomain.com my-previous-secret-dataUsing Cloud Storage storage:
berglas revoke ${BUCKET_ID}/foo --member user:user@mydomain.com -
Delete a secret:
Using Secret Manager storage:
berglas delete sm://${PROJECT_ID}/fooUsing Cloud Storage storage:
berglas delete ${BUCKET_ID}/foo
In addition to standard Unix exit codes, if the CLI exits with a known error, Berglas will exit with one of the following:
-
60- API error. Berglas got a bad response when communicating with an upstream API. -
61- Misuse error. You gave unexpected input or behavior. Please read the error message. Open an issue if you think this is a mistake.
The only exception is berglas exec, which will exit with the exit status of
its child command, if one was provided.
Integrations
-
App Engine (Flex) - When invoked via [App Engine Flex][app-engine-flex], Berglas resolves environment variables to their plaintext values using the [`berglas://reference syntax][reference-syntax]. This integration works with any language runtime because berglas serves as the entrypoint to the Docker container.
-
App Engine (Standard) - When invoked via [App Engine][app-engine], Berglas resolves environment variables to their plaintext values using the [
berglas://reference syntax][reference-syntax]. This integration only works with the Go language runtime because it requires importing theauto/package. -
Cloud Run - When invoked via [Cloud Run][cloud-run], Berglas resolves environment variables to their plaintext values using the [
berglas://reference syntax][reference-syntax]. This integration works with any language runtime because berglas serves as the entrypoint to the Docker container. -
Cloud Functions - When invoked via [Cloud Functions][cloud-functions], Berglas resolves environment variables to their plaintext values using the [
berglas://reference syntax][reference-syntax]. This integration only works with the Go language runtime because it requires importing theauto/package. -
Cloud Build - When invoked via [Cloud Build][cloud-build], Berglas resolves environment variables to plaintext values using the [
berglas://reference syntax][reference-syntax]. This integration only works with vo
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
