-
-
Notifications
You must be signed in to change notification settings - Fork 0
hotfix: Caddy HandShake #105
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
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,68 @@ | ||
| .PHONY: caddy-gen-certs caddy-del-certs caddy-validate | ||
| .PHONY: caddy-gen-certs caddy-del-certs caddy-validate caddy-fresh | ||
|
|
||
| CADDY_MTLS_DIR = $(ROOT_PATH)/caddy/mtls | ||
| APP_CADDY_CONFIG_PROD_FILE ?= caddy/Caddyfile.prod | ||
| APP_CADDY_CONFIG_LOCAL_FILE ?= caddy/Caddyfile.local | ||
|
|
||
| caddy-fresh: | ||
| @make caddy-del-certs | ||
| @make caddy-gen-certs | ||
|
|
||
| caddy-gen-certs: | ||
| @set -eu; \ | ||
| mkdir -p "$(CADDY_MTLS_DIR)"; chmod 700 "$(CADDY_MTLS_DIR)"; \ | ||
| if [ -d "$(CADDY_MTLS_DIR)/ca.pem" ]; then \ | ||
| printf "$(RED)✘ ERROR:$(NC) %s is a directory. Move or remove it.\n" "$(CADDY_MTLS_DIR)/ca.pem"; \ | ||
| exit 1; \ | ||
| fi; \ | ||
| if [ -e "$(CADDY_MTLS_DIR)/ca.key" ] || [ -e "$(CADDY_MTLS_DIR)/ca.pem" ]; then \ | ||
| printf "$(YELLOW)⚠️ CA already exists in %s.$(NC)\n" "$(CADDY_MTLS_DIR)"; \ | ||
| printf "$(CYAN)👉 Remove it with 'make caddy-clean-certs' if you want to recreate.$(NC)\n"; \ | ||
| printf "$(CYAN)👉 Remove it with 'make caddy-del-certs' if you want to recreate.$(NC)\n"; \ | ||
| else \ | ||
| umask 077; \ | ||
| printf "$(BLUE)🔑 Generating CA private key...$(NC)\n"; \ | ||
| openssl genrsa -out "$(CADDY_MTLS_DIR)/ca.key" 4096 >/dev/null 2>&1; \ | ||
| openssl genrsa -out "$(CADDY_MTLS_DIR)/ca.key" 4096; \ | ||
| printf "$(BLUE)📜 Creating self-signed CA certificate...$(NC)\n"; \ | ||
| openssl req -x509 -new -key "$(CADDY_MTLS_DIR)/ca.key" -sha256 -days 3650 \ | ||
| -subj "/CN=oullin-mtls-ca" -out "$(CADDY_MTLS_DIR)/ca.pem" >/dev/null 2>&1; \ | ||
| -subj "/CN=oullin-mtls-ca" -out "$(CADDY_MTLS_DIR)/ca.pem"; \ | ||
| printf '01\n' > "$(CADDY_MTLS_DIR)/ca.srl"; \ | ||
| chmod 600 "$(CADDY_MTLS_DIR)/ca.key"; \ | ||
| chmod 644 "$(CADDY_MTLS_DIR)/ca.pem" "$(CADDY_MTLS_DIR)/ca.srl"; \ | ||
| printf "$(GREEN)✅ CA written to %s$(NC)\n" "$(CADDY_MTLS_DIR)"; \ | ||
| printf "$(WHITE)🔍 CA fingerprint:$(NC)\n"; \ | ||
| openssl x509 -noout -fingerprint -sha256 -in "$(CADDY_MTLS_DIR)/ca.pem" | sed 's/^/ /'; \ | ||
| fi | ||
| fi; \ | ||
| if [ -e "$(CADDY_MTLS_DIR)/server.key" ] || [ -e "$(CADDY_MTLS_DIR)/server.pem" ]; then \ | ||
| printf "$(YELLOW)⚠️ Server certificate already exists.$(NC)\n"; \ | ||
| else \ | ||
| umask 077; \ | ||
| printf "$(BLUE)🔑 Generating Server private key...$(NC)\n"; \ | ||
| openssl genrsa -out "$(CADDY_MTLS_DIR)/server.key" 4096; \ | ||
| printf "$(WHITE)📜 Creating Server signing request...$(NC)\n"; \ | ||
| openssl req -new -key "$(CADDY_MTLS_DIR)/server.key" -subj "/CN=oullin_proxy_prod" -out "$(CADDY_MTLS_DIR)/server.csr"; \ | ||
| printf "$(NC)🖊️ Signing Server certificate with CA...$(NC)\n"; \ | ||
| openssl x509 -req -in "$(CADDY_MTLS_DIR)/server.csr" \ | ||
| -CA "$(CADDY_MTLS_DIR)/ca.pem" -CAkey "$(CADDY_MTLS_DIR)/ca.key" -CAserial "$(CADDY_MTLS_DIR)/ca.srl" \ | ||
| -out "$(CADDY_MTLS_DIR)/server.pem" -days 1095 -sha256; \ | ||
| chmod 600 "$(CADDY_MTLS_DIR)/server.key"; \ | ||
| chmod 644 "$(CADDY_MTLS_DIR)/server.pem"; \ | ||
| rm "$(CADDY_MTLS_DIR)/server.csr"; \ | ||
| printf "$(GREEN)✅ Server certificate written to %s$(NC)\n" "$(CADDY_MTLS_DIR)"; \ | ||
| fi; \ | ||
| printf "$(NC)🔎 Verifying server cert against CA...$(NC)\n"; \ | ||
| openssl verify -CAfile "$(CADDY_MTLS_DIR)/ca.pem" "$(CADDY_MTLS_DIR)/server.pem" | ||
|
|
||
| caddy-del-certs: | ||
| @set -eu; \ | ||
| rm -f "$(CADDY_MTLS_DIR)/ca.key" "$(CADDY_MTLS_DIR)/ca.pem" "$(CADDY_MTLS_DIR)/ca.srl"; \ | ||
| rm -f "$(CADDY_MTLS_DIR)/ca.key" \ | ||
| "$(CADDY_MTLS_DIR)/ca.pem" \ | ||
| "$(CADDY_MTLS_DIR)/ca.srl" \ | ||
| "$(CADDY_MTLS_DIR)/server.key" \ | ||
| "$(CADDY_MTLS_DIR)/server.pem"; \ | ||
| printf "$(BLUE)✅ files removed from [$(NC)$(CADDY_MTLS_DIR)$(BLUE)]$(NC)\n" | ||
|
|
||
| caddy-validate: | ||
| docker run --rm \ | ||
| -v "$(ROOT_PATH)/caddy/Caddyfile.prod:/etc/caddy/Caddyfile:ro" \ | ||
| -v "$(ROOT_PATH)/caddy/mtls:/etc/caddy/mtls:ro" \ | ||
| caddy:2.10.0 caddy validate --config /etc/caddy/Caddyfile | ||
| @docker run --rm \ | ||
| -v "$(ROOT_PATH)/caddy/Caddyfile.prod:/etc/caddy/Caddyfile:ro" \ | ||
| -v "$(ROOT_PATH)/caddy/mtls:/etc/caddy/mtls:ro" \ | ||
| caddy:2.10.0 caddy validate --config /etc/caddy/Caddyfile |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking issue: server.pem must have SANs matching the SNI clients use.
Your Makefile generates a server cert with only CN=
oullin_proxy_prodand no subjectAltName. Modern clients (Chrome 58+, Go 1.15+) ignore CN for hostname verification; without SANs, the TLS handshake will fail even before HTTP routing/mTLS verification. See my Makefile comment with a patch to add SAN/EKU. (alexanderzeitler.com)🤖 Prompt for AI Agents