Teaching vacancies - # Application secrets
Application secrets
The application requires sensitive configuration which may be specific to each environment. It is stored securely in AWS SSM parameter store.
To read the whole application configuration of an environment (e.g. qa), run:
% aws-vault exec SecretEditor -- make qa print-env
To edit the application secrets of an environment (e.g. qa), run:
% aws-vault exec SecretEditor -- make qa edit-app-secrets
You will have the opportunity to verify and confirm before pushing the change. All the secrets are versioned, so in case of issue, a previous version can be restored.
cloudwatch_slack_hook_url
Terraform variable containing encrypted URL to the Slack webhook. cloudwatch_ops_genie_api_key is not actually used but is commonly set to the same value as cloudwatch_slack_hook_url. They need to be in an encrypted and base64 encoded format. There currently isn't a way to do this with Terraform, so to work around this:
- Set
cloudwatch_slack_hook_url
andcloudwatch_ops_genie_api_key
as their clear text values and apply, making sure to strip the protocol offcloudwatch_slack_hook_url
. - Go to the Lambda function settings within the AWS Console.
- Under 'Environment Variables', expand 'Encryption configuration' and select 'Enable helpers for encryption in transit'.
- Select the 'tvs2-<env>-cloudwatch-lambda' key.
- Select 'Encrypt' on both the
opsGenieApiKey
andslackHookUrl
(or if editing, the one that's changed). - Click 'Save'.
- Reload the page, and copy both of the (now encrypted) values, and replace
cloudwatch_slack_hook_url
andcloudwatch_ops_genie_api_key
in your terraform variables file. - Run a terraform plan to ensure everything has been done correctly (You should not have any changes required for the lambda resource).
SECRET_KEY_BASE
The secret_key_base is used as the input secret to the application's key generator, which in turn is used to create all MessageVerifiers/MessageEncryptors, including the ones that sign and encrypt cookies. If you change this key, all old signed cookies will become invalid! In order to generate a new secret key:
- Run the
rails secret
task from the repo, it will generate a new secret key - You need to generate a different key per environment
- Update
SECRET_KEY_BASE
in AWS Systems Manager Parameter Store/teaching-vacancies/<env>/app/secrets
files
DFE_SIGN_IN_PASSWORD and DFE_SIGN_IN_SECRET
- DFE_SIGN_IN_PASSWORD is used to encrypt JWT tokens to authorise a user with DFE sign-in.
- DFE_SIGN_IN_SECRET is OAuth2 client secret. It is only know to the application and the authorising server.
In order to update the password you need to have access to the DSI Manage console, it is specific to the environment (test, preprod, prod). This is the URL for test: https://test-manage.signin.education.gov.uk
Once you are inside:
- Follow the
Service configuration
link - Regenerate the
Client secret
(DFE_SIGN_IN_SECRET
env variable) andAPI secret
(DFE_SIGN_IN_PASSWORD
env variable) - Update
DFE_SIGN_IN_SECRET
andDFE_SIGN_IN_PASSWORD
in AWS Systems Manager Parameter Store/teaching-vacancies/<env>/app/secrets
files
Google API Keys
There are several different API keys in use in different environments. There are keys for Google Maps, as well as service accounts for Google Analytics, BigQuery and Google Drive.
-
GOOGLE_LOCATION_SEARCH_API_KEY
is used for both the Google Places API and the Google Geocoding API -
GOOGLE_MAPS_API_KEY
is used for Google Maps -
GOOGLE_API_JSON_KEY
is used for analytics, indexing and drive -
BIG_QUERY_API_JSON_KEY
is used for writing tables into BigQuery
NOTE: Keys with JSON
in the name are JSON
objects, not simple strings. They will need to be normalized in to JSON
strings to be used in ENV variables.
- Go to the Google Cloud Console API credentials section
- Always use your own login if it has sufficient permissions.
- If it does not, request them on #digital-tools-support
- Please only use teachingjobs@digital.education.gov.uk as a last resort.
For a string-based API key follow this workflow:
- Click 'CREATE CREDENTIALS' in the toolbar at the top of the page
- Choose 'API key'
- Click 'RESTRICT KEY' in the modal that appears
- In 'Name' give the key a clear, descriptive name including environment details where applicable
- Under 'Application Restrictions' select 'HTTP referrers (web sites)'
- Click 'ADD AN ITEM' under 'Website restrictions' and put in desired URL pattern.
- Under 'API restrictions' choose 'Restrict key'
- Select the API and access level for the key
- Create one key per API and environment and use the minimum necessary permission(s) for that key
- Click 'Save'
- Copy your new key from the table and update it in AWS Systems Manager Parameter Store
/teaching-vacancies/<env>/app/secrets
files - Do a rolling restart on the updated environment for the application
- Check that everything works as expected
- Delete the old API key from the Credentials table in the Google Cloud console
- Notify anyone who needs to know that the key has been changed
For a JSON
API keys follow this workflow:
To change a key on an existing service account (most common scenario):
- You are now back on the dashboard. Find your new service account and click on it.
- Click 'ADD KEY'
- Pick 'Create new key'
- Choose 'JSON' and click CREATE
- The new key will be automatically downloaded. Once you have it, you can click 'CLOSE' on the modal
- If you are on a mac, the easiest way to get the key into an
ENV
friendly format is using thejq
tool. In a terminal:brew install jq cd <key download directory> jq -c . teacher-vacancy-service-<some UID>.json | pbcopy
- Copy the full body of the new key as a json string (not necessary if you used
...| pbcopy
in thejq
example, above) - Paste the full string of the new key in AWS Systems Manager Parameter Store
/teaching-vacancies/<env>/app/BIG_QUERY_API_JSON_KEY
or/teaching-vacancies/<env>/app/GOOGLE_API_JSON_KEY
files - Do a rolling restart on the updated environment for the application
- Check that everything works as expected
- Delete the old key from the 'Keys' section in the Service Account window
- Notify anyone who needs to know that the key has been changed
To create a new service account (usually not necessary):
- Click 'CREATE CREDENTIALS' in the toolbar at the top of the page
- Choose 'Service Account'
- In 'Service account name' give the account a clear, descriptive name including environment details where applicable
- Add a concise description of what the service account is for and what environments it is to be used in 'Service account description'.
- Click 'Create'
- Add at least one role to restrict the service account to a service. Use the minimum necessary permission(s) for the role.
- Click 'Continue'
- So far, our service account have not required user or group access, so you can skip the next step (click 'DONE'). This may change in the future.
ORDNANCE_SURVEY_API_KEY
Used for geocoding. The key cannot be revoked through the portal. Contact Ordnance survey support.
To create a new key:
- Connect to https://developer.ordnancesurvey.co.uk/
- Navigate to My Keys > Add a new key
- Enter key name, select
OS Names API
and clickSave Key
- Update
ORDNANCE_SURVEY_API_KEY
in AWS Systems Manager Parameter Store/teaching-vacancies/<env>/app/secrets
files
SENTRY_DSN and SENTRY_FRONTEND_DSN
Two separate DSNs for Sentry:
-
SENTRY_DSN
is used by thesentry-ruby
gem -
SENTRY_FRONTEND_DSN
is used to track Javascript errors
They don't necessarily need to be separate, but as SENTRY_FRONTEND_DSN
must by definition be
public, this gives us some kind of separation. These are identical for all environments for the sake
of simplicity, and Rails.application.configuration.app_role
is used to set Sentry's concept of
environment.
Locally, you shouldn't need those API keys as you wouldn't want to do error tracking, but you can
set them for testing purposes in .env.local
if needed.
To rotate keys:
- Go to https://sentry.io/settings/teaching-vacancies/projects/teaching-vacancies/keys/
- Revoke/recreate the key you want to change
- Update the values in Parameter Store in all of the environments' secrets files
SKYLIGHT_AUTHENTICATION
Used by the app to report performance data to Skylight. Managed by digital-tools.
NOTIFY_KEY
Used to integrate with the GovUK Notify API.
- Access https://www.notifications.service.gov.uk/
- Navigate to API integration > API keys
- Click
Revoke
on the old key - Click Create an API key
- Add a specific name, select the type of key and click
Continue
- Update
NOTIFY_KEY
in AWS Systems Manager Parameter Store/teaching-vacancies/<env>/app/secrets
files