Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/secrets management scripts, ssl for otp26 #1756

Merged
merged 8 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ gcloud_prod.json
.*.req.*
!.*.cacert.*.enc
!.*.cert.*.enc

# DB ssl certs
.*.*.pem

# google keys
.*.gcloud.json
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@ __start__: decrypt.${ENV}
# make decrypt.{dev,staging,prod} # Decrypt secrets for given environment
# make encrypt.{dev,staging,prod} # Encrypt secrets for given environment

%: %.enc
%: cloudbuild/%.enc
@gcloud kms decrypt --ciphertext-file=$< --plaintext-file=$@ \
--location=${GCLOUD_LOCATION} \
--keyring=${GCLOUD_KEYRING} \
--key=${GCLOUD_KEY} \
--project=${GCLOUD_PROJECT}
@echo "$@ has been decrypted"

%.enc:
@gcloud kms encrypt --ciphertext-file=$@ --plaintext-file=$(@:.enc=) \
@gcloud kms encrypt --ciphertext-file=cloudbuild/$@ --plaintext-file=$(@:.enc=) \
--location=${GCLOUD_LOCATION} \
--keyring=${GCLOUD_KEYRING} \
--key=${GCLOUD_KEY} \
--project=${GCLOUD_PROJECT}
@echo "$@ has been encrypted"

.PRECIOUS: %.enc

Expand All @@ -71,26 +73,35 @@ encrypt.dev: .dev.env.enc

envs = staging prod

%crypt.prod: GCLOUD_KEYRING = logflare-prod-keyring-us-central1
%crypt.prod: GCLOUD_KEY = logflare-prod-secrets-key
%crypt.prod: GCLOUD_PROJECT = logflare-232118

.SECONDEXPANSION:
$(addprefix decrypt.,${envs}): decrypt.%: \
@gcloud_$$*.json \
.$$*.gcloud.json \
.$$*.env \
.$$*.cacert.key \
.$$*.cacert.pem \
.$$*.cert.key \
.$$*.cert.pem

.PHONY: $(addprefix decrypt.,${envs})
.$$*.cert.pem \
.$$*.db-client-cert.pem \
.$$*.db-client-key.pem \
.$$*.db-server-ca.pem

$(addprefix encrypt.,${envs}): encrypt.%: \
@gcloud_$$*.json.enc \
.$$*.gcloud.json.enc \
.$$*.env.enc \
.$$*.cacert.key.enc \
.$$*.cacert.pem.enc \
.$$*.cert.key.enc \
.$$*.cert.pem.enc
.$$*.cert.pem.enc \
.$$*.db-client-cert.pem.enc \
.$$*.db-client-key.pem.enc \
.$$*.db-server-ca.pem.enc

.PHONY: $(addprefix encrypt.,${envs})
.PHONY: $(addprefix decrypt.,${envs})

# OpenTelemetry Protobufs

Expand Down
Binary file modified cloudbuild/.prod.cacert.key.enc
Binary file not shown.
Binary file modified cloudbuild/.prod.cacert.pem.enc
Binary file not shown.
Binary file modified cloudbuild/.prod.cert.key.enc
Binary file not shown.
Binary file modified cloudbuild/.prod.cert.pem.enc
Binary file not shown.
Binary file added cloudbuild/.prod.db-client-cert.pem.enc
Binary file not shown.
Binary file added cloudbuild/.prod.db-client-key.pem.enc
Binary file not shown.
Binary file added cloudbuild/.prod.db-server-ca.pem.enc
Binary file not shown.
Binary file modified cloudbuild/.prod.env.enc
Binary file not shown.
Binary file added cloudbuild/.prod.gcloud.json.enc
Binary file not shown.
Binary file modified cloudbuild/.staging.cacert.key.enc
Binary file not shown.
Binary file modified cloudbuild/.staging.cacert.pem.enc
Binary file not shown.
Binary file modified cloudbuild/.staging.cert.key.enc
Binary file not shown.
Binary file modified cloudbuild/.staging.cert.pem.enc
Binary file not shown.
Binary file added cloudbuild/.staging.db-client-cert.pem.enc
Binary file not shown.
Binary file added cloudbuild/.staging.db-client-key.pem.enc
Binary file not shown.
Binary file added cloudbuild/.staging.db-server-ca.pem.enc
Binary file not shown.
Binary file modified cloudbuild/.staging.env.enc
Binary file not shown.
Binary file added cloudbuild/.staging.gcloud.json.enc
Binary file not shown.
Binary file removed cloudbuild/gcloud_prod.json.enc
Binary file not shown.
Binary file removed cloudbuild/gcloud_staging.json.enc
Binary file not shown.
27 changes: 27 additions & 0 deletions cloudbuild/prod/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ steps:
- "--location=us-central1"
- "--keyring=logflare-prod-keyring-us-central1"
- "--key=logflare-prod-secrets-key"
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=./cloudbuild/.prod.db-client-cert.pem.enc
- --plaintext-file=./db-client-cert.pem
- "--location=us-central1"
- "--keyring=logflare-prod-keyring-us-central1"
- "--key=logflare-prod-secrets-key"
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=./cloudbuild/.prod.db-client-key.pem.enc
- --plaintext-file=./db-client-key.pem
- "--location=us-central1"
- "--keyring=logflare-prod-keyring-us-central1"
- "--key=logflare-prod-secrets-key"
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=./cloudbuild/.prod.db-server-ca.pem.enc
- --plaintext-file=./db-server-ca.pem
- "--location=us-central1"
- "--keyring=logflare-prod-keyring-us-central1"
- "--key=logflare-prod-secrets-key"
- name: "gcr.io/cloud-builders/docker"
args:
[
Expand Down
27 changes: 27 additions & 0 deletions cloudbuild/staging/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ steps:
- --location=us-central1
- --keyring=logflare-keyring-us-central1
- --key=logflare-secrets-key
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=./cloudbuild/.staging.db-client-cert.pem.enc
- --plaintext-file=./db-client-cert.pem
- --location=us-central1
- --keyring=logflare-keyring-us-central1
- --key=logflare-secrets-key
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=./cloudbuild/.staging.db-client-key.pem.enc
- --plaintext-file=./db-client-key.pem
- --location=us-central1
- --keyring=logflare-keyring-us-central1
- --key=logflare-secrets-key
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=./cloudbuild/.staging.db-server-ca.pem.enc
- --plaintext-file=./db-server-ca.pem
- --location=us-central1
- --keyring=logflare-keyring-us-central1
- --key=logflare-secrets-key
- name: "gcr.io/cloud-builders/docker"
args:
[
Expand Down
50 changes: 26 additions & 24 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ config :logflare,
do: String.to_integer(System.get_env("DB_POOL_SIZE")),
else: nil
),
ssl: System.get_env("DB_SSL") == "true",
# ssl_opts:
# if(System.get_env("DB_SSL") == "true",
# do: [
# # ssl opts follow recs here: https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/ssl
# verify: :verify_peer,
# cacerts: :public_key.cacerts_get(),
# # allow intermediate CA
# depth: 3,
# versions: [:"tlsv1.2"],
# # support wildcard
# customize_hostname_check: [
# match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
# ]
# ],
# else: nil
# ),
database: System.get_env("DB_DATABASE"),
hostname: System.get_env("DB_HOSTNAME"),
password: System.get_env("DB_PASSWORD"),
Expand Down Expand Up @@ -227,14 +210,33 @@ cond do
end

if(File.exists?("cacert.pem") && File.exists?("cert.pem") && File.exists?("cert.key")) do
ssl_opts = [
cacertfile: "cacert.pem",
certfile: "cert.pem",
keyfile: "cert.key",
verify: :verify_peer
]
config :logflare,
ssl: [
cacertfile: "cacert.pem",
certfile: "cert.pem",
keyfile: "cert.key",
verify: :verify_peer
]
end

config :logflare, ssl: ssl_opts
if(
System.get_env("DB_SSL") == "true" && File.exists?("db-server-ca.pem") &&
File.exists?("db-client-ca.pem") && File.exists?("db-client-key.pem")
Comment on lines +223 to +224
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that checking for paths like that can fail in release, as these files may not be where we want them to be. Maybe instead use DB_SSL as a path to where these files will be stored? That should make the configuration more flexible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. yes we can update the certfile loading method for both db and grpc, can do this in a separate PR.

) do
config :logflare, Logflare.Repo,
ssl: true,
ssl_opts: [
# ssl opts follow recs here: https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/ssl
verify: :verify_peer,
cacertfile: "db-server-ca.pem",
certfile: "db-client-cert.pem",
keyfile: "db-client-key.pem",
versions: [:"tlsv1.2"],
# support wildcard
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
]
end

case System.get_env("LOGFLARE_FEATURE_FLAG_OVERRIDE") do
Expand Down
Loading