diff --git a/docs/operations/runbooks/add_secrets_to_existing_sandbox.md b/docs/operations/runbooks/add_secrets_to_existing_sandbox.md new file mode 100644 index 000000000..411f9c90a --- /dev/null +++ b/docs/operations/runbooks/add_secrets_to_existing_sandbox.md @@ -0,0 +1,73 @@ +# HOWTO Add secrets to an existing sandbox + + +### Check if you need to add secrets +Run this command to get the environment variables from a sandbox: + +```sh +cf env +``` +For example `cf env getgov-development` + +Check that these environment variables exist: +``` +{ + "DJANGO_SECRET_KEY": "EXAMPLE", + "DJANGO_SECRET_LOGIN_KEY": "EXAMPLE", + "AWS_ACCESS_KEY_ID": "EXAMPLE", + "AWS_SECRET_ACCESS_KEY": "EXAMPLE", + "REGISTRY_KEY": "EXAMPLE, + ... +} +``` + +If those variable are not present, use the following steps to set secrets by creating a new `credentials-.json` file and uploading it. +(Note that many of these commands were taken from the [`create_dev_sandbox.sh`](../../../ops/scripts/create_dev_sandbox.sh) script and were tested on MacOS) + +### Create a new Django key +```sh +django_key=$(python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())') +``` + +### Replace the existing certificate +Create a certificate: +```sh +openssl req -nodes -x509 -days 365 -newkey rsa:2048 -keyout private-.pem -out public-.crt +``` + +Fill in the following for the prompts: + +Note: for "Common Name" you should put the name of the sandbox and for "Email Address" it should be the address of who owns that sandbox (such as the developer's email, if it's a developer sandbox, or whoever ran this action otherwise) + +```sh +Country Name (2 letter code) [AU]: US +State or Province Name (full name) [Some-State]: DC +Locality Name (eg, city) []: DC +Organization Name (eg, company) [Internet Widgits Pty Ltd]: DHS +Organizational Unit Name (eg, section) []: CISA +Common Name (e.g. server FQDN or YOUR name) []: +Email Address []: +``` +Go to https://dashboard.int.identitysandbox.gov/service_providers/2640/edit to remove the old certificate and upload the new one. + +### Create the login key +```sh +login_key=$(base64 -i private-.pem) +``` + +### Create the credentials file +```sh +jq -n --arg django_key "$django_key" --arg login_key "$login_key" '{"DJANGO_SECRET_KEY":$django_key,"DJANGO_SECRET_LOGIN_KEY":$login_key}' > credentials-.json +``` + +Copy `REGISTRY_*` credentials from another sandbox into your `credentials-.json` file. Also add your `AWS_*` credentials if you have them, otherwise also copy them from another sandbox. You can either use the cloud.gov dashboard or the command `cf env ` to find other credentials. + +### Update the `getgov-credentials` service tied to your environment. +```sh +cf uups getgov-credentials -p credentials-.json +``` + +### Restage your application +```sh +cf restage getgov- --strategy rolling +``` \ No newline at end of file diff --git a/ops/scripts/create_dev_sandbox.sh b/ops/scripts/create_dev_sandbox.sh index 6cbad9c4f..1796817a8 100755 --- a/ops/scripts/create_dev_sandbox.sh +++ b/ops/scripts/create_dev_sandbox.sh @@ -136,6 +136,7 @@ then fi cf service-key github-cd-account github-cd-key | sed 1,2d | jq -r '[.username, .password]|@tsv' | + while read -r username password; do gh secret --repo cisagov/getgov set CF_${upcase_name}_USERNAME --body $username gh secret --repo cisagov/getgov set CF_${upcase_name}_PASSWORD --body $password