-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Support custom CA roots #1015
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5ef717c
feat: Support custom CA roots
Spice-King 87a5aeb
Pre for test cleanup, move test.sh to subfolder.
Spice-King 93a3a1a
tests: add tests to check customs CAs
Spice-King 4545990
Add test clean up script.
Spice-King 600becb
Refactor
chadwhitacre 1ac17f4
Achieve parity between CI and local
chadwhitacre b85504a
Chad's changes
chadwhitacre 3f713c2
BYK's changes
BYK 31737f3
try going to read-only mount again
BYK 6da9e04
port tests to unittest framework
BYK 59b0cde
fix typo
BYK d2ecb74
bring DEFAULT_CA_BUNDLE back
BYK b353472
add missing final eol
BYK f7bfd12
upgrade ubuntu version on runners for newer openssl
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.