To maintain good security, we will periodically rotate the following secret keys, which are used to control authentication and authorization to our application:
- CF deployer keys (for continuous delivery)
- JWT keys (external user auth)
- ACF AMS keys (internal user auth)
- Django secret keys (cryptographic signing)
This document outlines the process for doing this for each set of keys.
Recommendation: Create a new issue to track key rotation for team awareness.
Warning(s):
- Production sites will need to be taken down for maintenance when rotating keys, as the rotation will automatically invalidate all current sessions.
- As of June 2022, CircleCI supplies environment variable key-value pairs to multiple environments (e.g. Raft's CircleCI deploys applications to dev and staging environments). The values from CircleCI are expected to be unique per environment, so until #1826 is researched and addressed, these values will need to be manually corrected in cloud.gov immediately following the execution of the
<env>-deployment
CircleCI workflow. This workaround applies to backend applications in the TDP staging environment.
CF deployer keys
There are unique cloud foundry (CF) credentials for each cloud.gov space (tanf-dev
, tanf-staging
, tanf-prod
) for deployments. These are stored in the tanf-keys
service instance in cloud.gov. The steps below should be followed to rotate the credentials for the relevant space(s). Note: <ENV>
:= DEV
, STAGING
, or PROD
.
- verify existing credentials for
deployer
key intanf-keys
service instance (these are the values forCF_USERNAME_<ENV>
andCF_PASSWORD_<ENV>
in circleci project settings
# target env space
cf target -o hhs-acf-ofa -s tanf-<env>
# verify deployment credentials
cf service-key tanf-keys deployer
- remove the current username associated the the
deployer
tanf-keys
service instance from cloud.gov space (this is the same value asCF_USERNAME_<env>
). This task can also be done from the dashboard.
cf delete-user <<insert USERNAME value for deployer key>>
- delete the
deployer
service key associated withtanf-keys
service instance (reference)
# delete
cf delete-service-key tanf-keys deployer
# verify deletion
cf service-keys tanf-keys
- create new
deployer
service key withintanf-keys
instance (reference link above)
cf create-service-key tanf-keys deployer
- add username for newly generated
deployer
service key to space as a user to relevant space and assign as an org user and space developer. This task can also be done from the dashboard.
# add user
cf create-user <<insert USERNAME value for deployer key>>
# add as a user to org
cf set-org-role <<insert USERNAME value for deployer key>> hhs-acf-ofa OrgUser
# add as developer to prod space
cf set-space-role <<insert USERNAME value for deployer key>> hhs-acf-ofa tanf-prod SpaceDeveloper
- Confirm that the new deployment credentials work in CircleCI (re-run deployment workflow after adding
CF_USERNAME_<env>
andCF_PASSWORD_<env>
back to CircleCI with rotated values)
JWT Keys
The following steps are applicable for lower environments (dev and staging) only. See here for prod environment procedure.
In your Mac terminal (or bash terminal in Windows), enter the following command:
yes 'XX' | openssl req -nodes -x509 -days 100 -newkey rsa:4096 -keyout jwtRS256prv.pem -out jwtRS256pub.crt
You can now check the contents of your keys with these commands
cat jwtRS256prv.pem
# returns private key
cat jwtRS256pub.crt
# returns public key
We use Base64 Encoded Private Keys to make it easier to save to cloud environments and local .env
files.
openssl enc -base64 -in jwtRS256prv.pem -out jwtRS256prv.pem.base64
cat jwtRS256prv.pem.base64
NOTE: Linux users must disable line wrapping by adding the argument -w 0
to get a properly formatted one-line value.
cat jwtRS256prv.pem | base64 -w 0 > jwtRS256prv.pem.base64
cat jwtRS256prv.pem.base64
- Distribute the private key to development staff securely to copy to
.env
files as the value for keyJWT_KEY
- Update the environment variables
JWT_KEY
with the base64-encoded private key andJWT_CERT
in cloud.gov backend development and staging environments
cf set-env $cgbackendappname JWT_KEY $JWT_KEY_VALUE
cf set-env $cgbackendappname JWT_CERT "$JWT_CERT_VALUE\
> _IS_TYPICALLY_\
>MULTILINE"
- Login to the Login.gov Sandbox and verify the values are updated across all environments (4 dev + 2 staging)
Note: Login.gov requires the key to be uploaded in PEM format, which is the format we produced in the jwtRS256pub.crt
file.
Note Please generate a separate set of keys for the staging environments. The steps here will be the same as development but you will need to generate a separate key-value pair and upload them to the separate app listing in Login.gov's dashboard as linked above.
- Distribute the private key to development staff securely to copy to
.env
- Update the variables
JWT_KEY
andJWT_CERT_TEST
in CircleCI with the new keypair.
Note: Please generate a separate set of keys for the Production environment.The steps here will be the same as development but you will need to generate a separate key-value pair and upload them to the separate app listing in Login.gov's dashboard as linked above.
Production environment key generation, change requests, and distribution will be handled by Government-authorized personnel with Government computers and PIV access (e.g. TDP sys admins)
- Copy the private key to cloud.gov backend environment variable
JWT_KEY
- Copy the public key to the login.gov production environment
- In order for the key change to take effect, a change request must be submitted to the login.gov support portal. These requests can take approx. 2 weeks to be completed.
References
- More information on
openssl
can be found at openssl.org
ACF AMS Keys
The ACF OCIO Ops team manages these credentials for all environments (dev, staging, and prod), so we will need to submit a service request ticket whenever we need keys rotated.Service requests tickets must be submitted by Government-authorized personnel with Government computers and PIV access (e.g. Raft tech lead for lower environments and TDP sys admins for production environment). Please follow the procedures below:
- Submit request tickets from government-issued email address and use the email template located on page 2 of this document. cc OFA tech lead on lower environment requests.
- Update environment variables in CircleCI and relevant cloud.gov backend applications after ticket completed by OCIO. Restage applications.
Django secret keys
DJANGO_SECRET_KEY
is dynamically generated since #1151, so all that needs to be done to rotate this key in any environment is to re-run the relevant environment's deployment workflow in CircleCI. These are as follows:
- dev environment workflow (
dev-deployment
) is run from CircleCI for raft-tech/TANF-app. - staging environment workflow (
staging-deployment
) is run from CircleCI for raft-tech/TANF-app viadeploy-develop
. - staging environment workflow (
staging-deployment
) is run from CircleCI for HHS/TANF-app viadeploy-staging
. - prod environment workflow (
production-deployment
) is run from CircleCI for HHS/TANF-app.