Skip to content

Commit

Permalink
Added alias for getting secret values from GSM (#91)
Browse files Browse the repository at this point in the history
## Summary:
We have migrated our infrastructure to use google secret manager (GSM) for most things. The command to get secrets from GSM is very long and not intuitive so Im adding a small script `gsmget` to make our lives easier.  E.g. `gsmget Test_secret` and that will get you the latest version of the secret.

As noted in the comments with Craig, dotfiles/bin is added to the `PATH` so pulling latest dotfiles will automagically get you `gsmget`.

Issue: "none"

## Test plan:
You should be able to pull latest dotfile and you will automatically get the new script.  You can verify by reading a secret via something like

For default version
`gsmget Test_secret`

For a particular version
`gsmget Test_secret 1`

For usage help
`gsmget`

Author: MiguelCastillo

Reviewers: csilvers, MiguelCastillo, dbraley, nathanjd, jwiesebron

Required Reviewers:

Approved By: csilvers, dbraley, csilvers

Checks:

Pull Request URL: #91
  • Loading branch information
MiguelCastillo authored Oct 14, 2023
1 parent 122a924 commit e3f28f7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bin/gsmget
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

SCRIPT=$(basename $0)

usage() {
cat << EOF
usage: $SCRIPT secretname <version>
secretname is the name of the secret in Google Secret Manager. For a list of
all the secrets, you can visit
https://console.cloud.google.com/security/secret-manager?project=khan-academy
version is optional. If not specified then you get the latest version
$SCRIPT Test_secret
$SCRIPT Test_secret 1
$SCRIPT Test_secret latest
EOF
}

SECRET=$1
VERSION=$2

if [ -z "$SECRET" ]
then
echo "Must provide the name of a GSM secret as the first argument"
echo
usage
exit 1
fi

if [ -z "$VERSION" ]
then
VERSION="latest"
fi

# Command for getting secrets from google secret manager
exec gcloud --project khan-academy secrets versions access "$VERSION" --secret "$SECRET"

0 comments on commit e3f28f7

Please sign in to comment.