Caution
This app alone is not meant to be used in production!
This is an example Django application that uses GCP Cloud KMS to take mock tokens and store it in an encrypted column of the database.
It currently uses symmetric encryption for each stored token.
Implement envelope encryption- Fix custom Django management command to re-encrypt tokens
You'll need the gcloud CLI installed on your system.
- Create a GCP project.
- Login with gcloud CLI:
gcloud auth login
- Set your project context:
gcloud config set-project <PROJECT ID>
- Enable the KMS API:
gcloud services enable cloudkms.googleapis.com
- Create the keyring:
gcloud kms keyrings create test-keyring --location global
- Create a key (this is using MacOS's version of
date
):
gcloud kms keys create pat-encryption-key \
--location global \
--keyring test-keyring \
--purpose encryption \
--default-algorithm google-symmetric-encryption \
--rotation-period "1d" \
--next-rotation-time "$(date -u -v+1d +"%Y-%m-%dT%H:%M:%S.%4NZ")"
- Login with application default credentials (just for testing!):
gcloud auth application-default login
- Copy
.envrc.example
to.envrc
:cp .envrc .envrc.example
- Setup the environment variables in
.envrc
export GCP_PROJECT_ID="<YOUR PROJECT ID>"
export KMS_LOCATION_ID="global"
export KMS_KEY_RING_ID="test-keyring"
export KMS_CRYPTO_KEY_ID="pat-encryption-key"
- Install dependencies:
pip install -r requirements.txt
- Change directory into the Django project:
cd exampletink
- Setup the database (local SQLite DB):
python manage.py migrate
- Create a superuser:
python manage.py createsuperuser
- Run devserver:
python manage.py runserver
- Access the app at:
http://127.0.0.1:8000/