forked from getsentry/self-hosted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support custom CA roots (getsentry#1015)
Mount a certificate folder to local ca storage in containers, and add update command to cron image's entrypoint. Result of poking and prodding from getsentry/sentry#26851
- Loading branch information
1 parent
bd6f573
commit 17b675c
Showing
13 changed files
with
157 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.4' | ||
services: | ||
fixture-custom-ca-roots: | ||
image: nginx:1.21.0-alpine | ||
restart: unless-stopped | ||
volumes: | ||
- ./_integration-test/custom-ca-roots/nginx:/etc/nginx:ro | ||
networks: | ||
default: | ||
aliases: | ||
- self.test | ||
- fail.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
user nginx; | ||
worker_processes 1; | ||
|
||
error_log /var/log/nginx/error.log warn; | ||
pid /var/run/nginx.pid; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 443 ssl; | ||
server_name "self.test"; | ||
ssl_certificate "/etc/nginx/self.test.crt"; | ||
ssl_certificate_key "/etc/nginx/self.test.key"; | ||
location / { | ||
add_header Content-Type text/plain; | ||
return 200 'ok'; | ||
} | ||
} | ||
server { | ||
listen 443 ssl; | ||
server_name "fake.test"; | ||
ssl_certificate "/etc/nginx/fake.test.crt"; | ||
ssl_certificate_key "/etc/nginx/fake.test.key"; | ||
location / { | ||
add_header Content-Type text/plain; | ||
return 200 'bad'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#! /usr/bin/env bash | ||
set -e | ||
|
||
export COMPOSE_FILE="../docker-compose.yml:./custom-ca-roots/docker-compose.test.yml" | ||
|
||
TEST_NGINX_CONF_PATH="./custom-ca-roots/nginx" | ||
CUSTOM_CERTS_PATH="../certificates" | ||
|
||
# generate tightly constrained CA | ||
# NB: `-addext` requires LibreSSL 3.1.0+, or OpenSSL (brew install openssl) | ||
openssl req -x509 -new -nodes -newkey rsa:2048 -keyout $TEST_NGINX_CONF_PATH/ca.key \ | ||
-sha256 -days 1 -out $TEST_NGINX_CONF_PATH/ca.crt -batch \ | ||
-subj "/CN=TEST CA *DO NOT TRUST*" \ | ||
-addext "keyUsage = critical, keyCertSign, cRLSign" \ | ||
-addext "nameConstraints = critical, permitted;DNS:self.test" | ||
|
||
## Lines like the following are debug helpers ... | ||
# openssl x509 -in nginx/ca.crt -text -noout | ||
|
||
mkdir -p $CUSTOM_CERTS_PATH | ||
cp $TEST_NGINX_CONF_PATH/ca.crt $CUSTOM_CERTS_PATH/test-custom-ca-roots.crt | ||
|
||
# generate server certificate | ||
openssl req -new -nodes -newkey rsa:2048 -keyout $TEST_NGINX_CONF_PATH/self.test.key \ | ||
-addext "subjectAltName=DNS:self.test" \ | ||
-out $TEST_NGINX_CONF_PATH/self.test.req -batch -subj "/CN=Self Signed with CA Test Server" | ||
|
||
# openssl req -in nginx/self.test.req -text -noout | ||
|
||
openssl x509 -req -in $TEST_NGINX_CONF_PATH/self.test.req -CA $TEST_NGINX_CONF_PATH/ca.crt -CAkey $TEST_NGINX_CONF_PATH/ca.key \ | ||
-extfile <(printf "subjectAltName=DNS:self.test") \ | ||
-CAcreateserial -out $TEST_NGINX_CONF_PATH/self.test.crt -days 1 -sha256 | ||
|
||
# openssl x509 -in nginx/self.test.crt -text -noout | ||
|
||
# sanity check that signed certificate passes OpenSSL's validation | ||
openssl verify -CAfile $TEST_NGINX_CONF_PATH/ca.crt $TEST_NGINX_CONF_PATH/self.test.crt | ||
|
||
# self signed certificate, for sanity check of not just accepting all certs | ||
openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/fake.test.key \ | ||
-out $TEST_NGINX_CONF_PATH/fake.test.crt -addext "subjectAltName=DNS:fake.test" -subj "/CN=Self Signed Test Server" | ||
|
||
# openssl x509 -in nginx/fake.test.crt -text -noout | ||
|
||
cp ./custom-ca-roots/test.py ../sentry/test-custom-ca-roots.py | ||
|
||
$dc up -d fixture-custom-ca-roots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
$dc rm -s -f -v fixture-custom-ca-roots | ||
rm -f ../certificates/test-custom-ca-roots.crt ../sentry/test-custom-ca-roots.py | ||
unset COMPOSE_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest | ||
import requests | ||
|
||
|
||
class CustomCATests(unittest.TestCase): | ||
def test_valid_self_signed(self): | ||
self.assertEqual(requests.get("https://self.test").text, 'ok') | ||
|
||
def test_invalid_self_signed(self): | ||
with self.assertRaises(requests.exceptions.SSLError): | ||
requests.get("https://fail.test") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters