Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit e013f21

Browse files
authored
Use new filesystem key manager (#488)
* Use new filesystem key manager * Update
1 parent 752cbb7 commit e013f21

File tree

7 files changed

+316
-68
lines changed

7 files changed

+316
-68
lines changed

docs/development.md

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,36 @@ represent best practices.
3333

3434
Use the same Google credentials as you used in the previous steps.
3535

36-
1. Create a Google Cloud KMS key ring and two signing keys:
36+
1. Change directory into this repository:
3737

38-
```sh
39-
gcloud kms keyrings create "signing" \
40-
--location "us"
41-
42-
gcloud kms keys create "token-signing" \
43-
--location "us" \
44-
--keyring "signing" \
45-
--purpose "asymmetric-signing" \
46-
--default-algorithm "ec-sign-p256-sha256"
47-
48-
gcloud kms keys create "certificate-signing" \
49-
--location "us" \
50-
--keyring "signing" \
51-
--purpose "asymmetric-signing" \
52-
--default-algorithm "ec-sign-p256-sha256" \
38+
```text
39+
cd /path/to/exposure-notifications-verification-server
5340
```
5441

55-
To get the resource names to the keys (for use below):
56-
57-
```sh
58-
gcloud kms keys describe "token-signing" \
59-
--location "us" \
60-
--keyring "signing"
42+
1. Bootstrap the local key management system:
6143

62-
gcloud kms keys describe "certificate-signing" \
63-
--location "us" \
64-
--keyring "signing"
44+
```text
45+
go run ./tools/gen-keys
6546
```
6647

48+
This will output some environment variables. **Save these environment
49+
variables for the next step!**
50+
51+
The default development setup uses a local, on-disk key manager to persist
52+
across server restarts. The production installation recommends a hosted key
53+
management service like Google Cloud KMS. It is possible to use Google Cloud
54+
KMS locally by following the instructions in the production setup guide.
55+
6756
1. Create a `.env` file with your configuration. This will aid future
6857
development since you can `source` this file instead of trying to find all
6958
these values again.
7059

7160
```sh
72-
# Create a file named .env with these contents
73-
export PROJECT_ID="YOUR_PROJECT_ID" # TODO: replace
61+
# Google project configuration.
62+
export PROJECT_ID="TODO"
7463
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
7564
76-
# Get these values from the firebase console
65+
# Get these values from the firebase console.
7766
export FIREBASE_API_KEY="TODO"
7867
export FIREBASE_PROJECT_ID="${PROJECT_ID}"
7968
export FIREBASE_MESSAGE_SENDER_ID="TODO"
@@ -85,35 +74,58 @@ represent best practices.
8574
export FIREBASE_PRIVACY_POLICY_URL="TODO"
8675
export FIREBASE_TERMS_OF_SERVICE_URL="TODO"
8776
88-
# Populate these with the resource IDs from above. These values will be of
89-
# the format:
90-
#
91-
# projects/ID/locations/us/keyRings/signing/cryptoKeys/token-signing/cryptoKeyVersions/1Z
92-
export TOKEN_SIGNING_KEY="TODO"
93-
export CERTIFICATE_SIGNING_KEY="TODO"
94-
95-
# Disable local observability
77+
# Disable local observability.
9678
export OBSERVABILITY_EXPORTER="NOOP"
9779
98-
# Configure a CSRF auth key. Create your own with `openssl rand -base64 32`.
80+
# Configure CSRF for preventing request forgery. Create your own with:
81+
#
82+
# openssl rand -base64 32
83+
#
9984
export CSRF_AUTH_KEY="RcCNhTkS9tSDMSGcl4UCa1FUg9GmctkJpdI+eqZ+3v4="
10085
10186
# Configure cookie encryption, the first is 64 bytes, the second is 32.
102-
# Create your own with `openssl rand -base64 NUM` where NUM is 32 or 64
87+
# Create your own values with:
88+
#
89+
# openssl rand -base64 NUM
90+
#
91+
# where NUM is 32 or 64, respectively.
10392
export COOKIE_KEYS="ARLaFwAqBGIkm5pLjAveJuahtCnX2NLoAUz2kCZKrScUaUkEaxHSvJLVYb5yAPCc441Cho5n5yp8jdEmy6hyig==,RLjcRZeqc07s6dh3OK4CM1POjHDZHC+usNU1w/XNTjM="
10493
94+
# Configure certificate key management. The CERTIFICATE_SIGNING_KEY should
95+
# be the value output in the previous step.
96+
export CERTIFICATE_KEY_MANAGER="FILESYSTEM"
97+
export CERTIFICATE_KEY_FILESYSTEM_ROOT="$(pwd)/local"
98+
export CERTIFICATE_SIGNING_KEY="TODO" # (e.g. "/system/certificate-signing/1122334455")
99+
100+
# Configure token key management. The TOKEN_SIGNING_KEY should be the value
101+
# output in the previous step.
102+
export TOKEN_KEY_MANAGER="FILESYSTEM"
103+
export TOKEN_KEY_FILESYSTEM_ROOT="$(pwd)/local"
104+
export TOKEN_SIGNING_KEY="TODO" # (e.g. "/system/token-signing/1122334455")
105+
106+
# Configure the database key manager. The CERTIFICATE_SIGNING_KEYRING and
107+
# DB_ENCRYPTION_KEY should be the values output in the previous step.
108+
export DB_KEY_MANAGER="FILESYSTEM"
109+
export DB_KEY_FILESYSTEM_ROOT="$(pwd)/local"
110+
export CERTIFICATE_SIGNING_KEYRING="TODO" # (e.g. "/realm")
111+
export DB_ENCRYPTION_KEY="TODO" # (e.g. "/system/database-encryption")
112+
105113
# Use an in-memory key manager for encrypting values in the database. Create
106114
# your own encryption key with `openssl rand -base64 64`.
107115
export KEY_MANAGER="IN_MEMORY"
108116
export DB_ENCRYPTION_KEY="O04ZjG4WuoceRd0k2pTqDN0r8omr6sbFL0U3T5b12Lo="
109117
110-
# Database HMAC keys - these should be at least 64 bytes, preferably 128
111-
# Create your own with `openssl rand -base64 128`.
118+
# Database HMAC keys - these should be at least 64 bytes, preferably 128.
119+
# Create your own with:
120+
#
121+
# openssl rand -base64 128
122+
#
112123
export DB_APIKEY_DATABASE_KEY="RlV/RBEt0lDeK54r8U9Zi7EDFZid3fiKM2HFgjR9sZGMb+duuQomjGdNKYnzrNyKgeTBcc1V4qVs6fBrN6IFTLbgkp/u52MGhSooAQI4EuZ6JFuyxQBeu54Ia3mihF111BMcCWpHDg2MAh8k8f669plEQaqoQFg3GThP/Lx1OY0="
113124
export DB_APIKEY_SIGNATURE_KEY="HFeglmupbtv/I2X04OQRl1V7mcvfAXuv8XtmIFYV6aYsPuwQVFtXDlfFrjouYT2Z6kYln7B90RcutHJNjpPDRkyBQ28HtWmid3dr0tpJ1KiiK5NGG7JS9mU8fCvEYklw5RV+1f8qN13nWzHpW8/RQw9rR/vQGy90yL5/aydBuVA="
114125
export DB_VERIFICATION_CODE_DATABASE_KEY="YEN4+tnuf1DzQPryRzrPVilqT0Q2TO8IIg3C8prvXWGAaoABOWACl79hS40OneuaU8GsQHwhJ13wM2A5ooyOq+uqxCjrqVJZZXPU5xzl/6USEYAp4z2b0ZYrfkx2SRk1o9HfFi1RMqpaBf1TRIbsNOK9hNRG3nS2It49y6mR1ho="
115126
116-
# Enable dev mode
127+
# Enable dev mode. Do not enable dev mode or database dev mode in production
128+
# environments.
117129
export DEV_MODE=1
118130
export DB_DEBUG=1
119131
```

docs/production.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,81 @@
22

33
This page includes helpful tips for configuring things in production:
44

5+
## Key management
6+
7+
The default production key management solution is [Google Cloud KMS][gcp-kms].
8+
If you are using the Terraform configurations, the system will automatically
9+
bootstrap and create the key rings and keys in Cloud KMS. If you are not using
10+
the Terraform configurations, follow this guide to create the keys manually:
11+
12+
1. Create a Google Cloud KMS key ring
13+
14+
```sh
15+
gcloud kms keyrings create "en-verification" \
16+
--location "us"
17+
```
18+
19+
Note that the "us" location is configurable. If you choose a different
20+
location, substitute it in all future commands.
21+
22+
1. Create two signing keys - one for tokens and one for certificates:
23+
24+
```sh
25+
gcloud kms keys create "token-signing" \
26+
--location "us" \
27+
--keyring "en-verification" \
28+
--purpose "asymmetric-signing" \
29+
--default-algorithm "ec-sign-p256-sha256" \
30+
--protection-level "hsm"
31+
```
32+
33+
```sh
34+
gcloud kms keys create "certificate-signing" \
35+
--location "us" \
36+
--keyring "en-verification" \
37+
--purpose "asymmetric-signing" \
38+
--default-algorithm "ec-sign-p256-sha256" \
39+
--protection-level "hsm"
40+
```
41+
42+
Note the "us" location is configurable, but the key purpose and algorithm
43+
must be the same as above.
44+
45+
1. Create an encryption key for encrypting values in the database:
46+
47+
```sh
48+
gcloud kms keys create "database-encrypter" \
49+
--location "us" \
50+
--keyring "en-verification" \
51+
--purpose "encryption" \
52+
--rotation-period "30d" \
53+
--protection-level "hsm"
54+
```
55+
56+
1. Get the resource names to the keys:
57+
58+
```sh
59+
gcloud kms keys describe "token-signing" \
60+
--location "us" \
61+
--keyring "en-verification"
62+
```
63+
64+
```sh
65+
gcloud kms keys describe "certificate-signing" \
66+
--location "us" \
67+
--keyring "en-verification"
68+
```
69+
70+
```sh
71+
gcloud kms keys describe "database-encrypter" \
72+
--location "us" \
73+
--keyring "en-verification"
74+
```
75+
76+
1. Provide these values as the `TOKEN_SIGNING_KEY`, `CERTIFICATE_SIGNING_KEY`,
77+
and `DB_ENCRYPTION_KEY` respectively in the environment where the services
78+
will run. You also need to grant the service permission to use the keys.
79+
580

681
## Observability (tracing and metrics)
782

@@ -220,3 +295,5 @@ lifetime is short, it is probably safe to remove the key beyond 30 days.
220295
221296
If you are using system keys, the system administrator will handle rotation. If
222297
you are using realm keys, you can generate new keys in the UI.
298+
299+
[gcp-kms]: https://cloud.google.com/kms

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ require (
1111
firebase.google.com/go v3.13.0+incompatible
1212
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect
1313
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
14+
github.com/aws/aws-sdk-go v1.34.18 // indirect
1415
github.com/client9/misspell v0.3.4
1516
github.com/dgrijalva/jwt-go v3.2.0+incompatible
1617
github.com/frankban/quicktest v1.8.1 // indirect
17-
github.com/google/exposure-notifications-server v0.6.2-0.20200901223640-ce4572602269
18+
github.com/google/exposure-notifications-server v0.7.0
1819
github.com/google/go-cmp v0.5.2
1920
github.com/gorilla/csrf v1.7.0
2021
github.com/gorilla/handlers v1.5.0
2122
github.com/gorilla/mux v1.8.0
2223
github.com/gorilla/schema v1.2.0
2324
github.com/gorilla/sessions v1.2.1
25+
github.com/grpc-ecosystem/grpc-gateway v1.14.8 // indirect
2426
github.com/jinzhu/gorm v1.9.16
2527
github.com/jinzhu/now v1.1.1 // indirect
2628
github.com/kelseyhightower/envconfig v1.4.0 // indirect
@@ -39,9 +41,11 @@ require (
3941
github.com/unrolled/secure v1.0.8
4042
go.opencensus.io v0.22.4
4143
go.uber.org/zap v1.16.0
44+
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
45+
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
4246
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
43-
golang.org/x/tools v0.0.0-20200901201813-cf97e2b30f39
44-
google.golang.org/genproto v0.0.0-20200901141002-b3bf27a9dbd1
47+
golang.org/x/tools v0.0.0-20200908163505-ea3a2cdbfbeb
48+
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d
4549
gopkg.in/gormigrate.v1 v1.6.0
4650
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
4751
honnef.co/go/tools v0.0.1-2020.1.5

0 commit comments

Comments
 (0)