-
Notifications
You must be signed in to change notification settings - Fork 77
Act as a local network reverse proxy #843
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
Closed
Closed
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
4b86dff
Add caddy as internal proxy
felipecrs c1f43e0
Refactor some stuff
felipecrs 7b2a15c
Handle auto https
felipecrs f84bbcb
Clean some things up
felipecrs f642b84
More cleanup
felipecrs 77da04c
Fix initial certificate generation again
felipecrs 95b5f53
More cleanup
felipecrs e3d3202
Handle SSL in service and HA
felipecrs 529a625
Update docs and avoid starting caddy when built-in proxy is disabled
felipecrs 5f6abbb
Prettified Code!
felipecrs 539b3e2
Setup catch all service
felipecrs 01f3a39
Restore addon version
felipecrs 681e655
Fix some markdown lint
felipecrs 51150d6
Fix another one
felipecrs 11c6521
Add bullet point for internalOnly
felipecrs c48b07a
Fix some @coderabiitai comments
felipecrs f5a9965
Address some comments
felipecrs 53f0e16
Merge branch 'main' into caddy-internal-proxy
felipecrs 2990d75
Refactor Caddyfile
felipecrs 8ce1028
Improve condition name
felipecrs fb43445
Handle catch all service with https
felipecrs 91f7d00
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 159cb8e
Fix 127.0.0.1 login notifications with Caddy
felipecrs 97ea8a6
Wait for Caddy to be ready before starting Cloudflared
felipecrs 8b95267
Enable HTTP/2 between Cloudflared and Caddy
felipecrs 8a32111
Avoid using noTLSVerify for communication between Cloudflared and Caddy
felipecrs c265f15
Avoid unnecessary attempt to install root CA
felipecrs dbb2c8b
Disable persisting the generated json config
felipecrs c99fe1a
Disable unused admin API
felipecrs 966ebf7
Improve log format, including colors
felipecrs 2db2e97
Use HTTPS for catchall
felipecrs df9734f
Update cloudflared/rootfs/etc/s6-overlay/s6-rc.d/prepare/run.sh
felipecrs d91e8fb
Refactor tls on_demand for wildcard cert
felipecrs 107b530
Simplify caddy healthcheck
felipecrs c718e11
Stop using Caddy for catch-all
felipecrs 9bd4ca0
Cleanup some code
felipecrs 780ad44
Merge branch 'main' into caddy-internal-proxy
elcajon 35f9635
Merge branch 'main' into caddy-internal-proxy
felipecrs d51978f
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 611bd1c
Prettified Code!
felipecrs e3a9ad0
Prepare for remotely managed tunnels
felipecrs c653629
Use bashio to get forwarded addon port 443
felipecrs f1e854f
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 38d0344
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs ff62946
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 81962c4
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 58980fd
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 90a217f
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 17dc293
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 857425f
Merge branch 'main' into caddy-internal-proxy
elcajon c0a721c
Update Caddy to 2.10.1
felipecrs 22804ec
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs f0a9d60
Implement s6-overlay native readiness check for caddy service
felipecrs e5e40d7
Update Caddy to 2.10.2
felipecrs bdc0cd2
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs a2098f4
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 46c3f37
Translations: replace Nginx with Caddy
elcajon 121a222
Merge branch 'remove-nginx' of https://github.com/brenner-tobias/addo…
felipecrs 114cf56
Add checks to prevent startup with invalid use_builtin_proxy settings
felipecrs 30326eb
Update use_builtin_proxy docs and disable it by default
felipecrs fdf185c
Remove unnecessary check and fix tunnel_token check
felipecrs fc94a2f
Fix S6 starting Caddy if tunnel_token is set
felipecrs a0522f3
Add translations for new network ports
felipecrs 1df0fc3
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs cf32f7d
Fix resolving Home Assistant port before it starts
felipecrs 6ce229b
Merge branch 'fix-ha-port' of https://github.com/brenner-tobias/addon…
felipecrs 4a20230
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 9208c10
Avoid failing add-on startup if internalOnly is set without Caddy
felipecrs 9208a37
Fix add-on not starting if use_builtin_proxy is disabled
felipecrs 8088f1c
Combine checkConfig with setGlobalVars and optimize additional_hosts …
felipecrs 9407332
Fix some order changes
felipecrs 697bcac
Oops
felipecrs f32d720
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs ca37848
Remove useless code
felipecrs 8c4c3c3
Allow running Caddy with additional_hosts only
felipecrs 71dcbb3
Avoid parsing HA config if not needed (external_hostname unset)
felipecrs 882a593
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs d10b0e4
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs 49faad1
Merge branch 'main' of https://github.com/brenner-tobias/addon-cloudf…
felipecrs b47d2d3
Merge branch 'main' into caddy-internal-proxy
felipecrs 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
Some comments aren't visible on the classic Files Changed page.
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
felipecrs marked this conversation as resolved.
Show resolved
Hide resolved
|
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,74 @@ | ||
| { | ||
| # We don't use the admin API | ||
| admin off | ||
| # There is no need to persist the generate json configuration | ||
| persist_config off | ||
| # There is no need to attempt installing the root CA | ||
| skip_install_trust | ||
| {{ if not .auto_https }} | ||
| # Disable automatic generation of Let's Encrypt certificates | ||
| local_certs | ||
| {{ end }} | ||
| log { | ||
| # More friendly logging format than the default json | ||
| format console | ||
| } | ||
| } | ||
|
|
||
| # Used for communication between Cloudflared and Caddy | ||
| https://caddy.localhost { | ||
| tls internal | ||
|
|
||
| # Used to ensure Caddy is ready before starting Cloudflared | ||
| respond /healthz 200 | ||
|
|
||
| respond 403 | ||
| } | ||
|
|
||
| {{ if .ha_external_hostname }} | ||
| {{ .ha_external_hostname }} { | ||
| @cloudflared remote_ip 127.0.0.1 | ||
|
|
||
| reverse_proxy @cloudflared {{ .ha_service_url }} { | ||
| # https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/#caddy | ||
| header_up X-Forwarded-For {http.request.header.CF-Connecting-IP} | ||
felipecrs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{ if hasPrefix "https://" .ha_service_url }} | ||
| transport http { | ||
| tls_insecure_skip_verify | ||
| } | ||
| {{ end }} | ||
| } | ||
|
|
||
| reverse_proxy {{ .ha_service_url }} {{ if hasPrefix "https://" .ha_service_url }}{ | ||
| transport http { | ||
| tls_insecure_skip_verify | ||
| } | ||
| }{{ end }} | ||
| } | ||
| {{ end }} | ||
|
|
||
| {{ range $i, $e := .additional_hosts }} | ||
| {{ $e.hostname }} { | ||
| @cloudflared remote_ip 127.0.0.1 | ||
| {{ if $e.internalOnly }} | ||
| # Block connections from Cloudflared as service is internal only | ||
| handle @cloudflared { | ||
| respond 403 | ||
| } | ||
| {{ else }} | ||
| reverse_proxy @cloudflared {{ $e.service }} { | ||
| header_up X-Forwarded-For {http.request.header.CF-Connecting-IP} | ||
| {{ if hasPrefix "https://" $e.service }} | ||
| transport http { | ||
| tls_insecure_skip_verify | ||
| } | ||
| {{ end }} | ||
| } | ||
| {{ end }} | ||
| reverse_proxy {{ $e.service }} {{ if hasPrefix "https://" $e.service }}{ | ||
| transport http { | ||
| tls_insecure_skip_verify | ||
| } | ||
| }{{ end }} | ||
| } | ||
| {{ end }} | ||
5 changes: 5 additions & 0 deletions
5
cloudflared/rootfs/etc/s6-overlay/s6-rc.d/caddy/check_readiness.sh
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,5 @@ | ||
| #!/bin/bash | ||
|
|
||
| exec curl --fail --silent --output /dev/null --max-time 1 \ | ||
| --cacert /data/caddy/pki/authorities/local/root.crt \ | ||
| https://caddy.localhost/healthz |
11 changes: 11 additions & 0 deletions
11
cloudflared/rootfs/etc/s6-overlay/s6-rc.d/caddy/condition_caddy.sh
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,11 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| # ============================================================================== | ||
| # Home Assistant Add-on: Cloudflared | ||
| # | ||
| # Decides whether to run Caddy based on the use_builtin_proxy setting or not. | ||
| # ============================================================================== | ||
|
|
||
| if bashio::config.true 'use_builtin_proxy'; then | ||
| touch /etc/s6-overlay/s6-rc.d/user/contents.d/caddy | ||
| fi |
Empty 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,30 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| # ============================================================================== | ||
| # Home Assistant Add-on: Cloudflared | ||
| # Take down the S6 supervision tree when Caddy fails | ||
| # ============================================================================== | ||
|
|
||
| readonly exit_code_service="${1}" | ||
| readonly exit_code_signal="${2}" | ||
| exit_code_container=$(cat /run/s6-linux-init-container-results/exitcode) | ||
| readonly exit_code_container | ||
| readonly service="caddy" | ||
|
|
||
| bashio::log.info \ | ||
| "Service ${service} exited with code ${exit_code_service}" \ | ||
| "(by signal ${exit_code_signal})" | ||
|
|
||
| if [[ "${exit_code_service}" -eq 256 ]]; then | ||
| if [[ "${exit_code_container}" -eq 0 ]]; then | ||
| echo $((128 + exit_code_signal)) >/run/s6-linux-init-container-results/exitcode | ||
| fi | ||
| if [[ "${exit_code_signal}" -eq 15 ]]; then | ||
| exec /run/s6/basedir/bin/halt | ||
| fi | ||
| elif [[ "${exit_code_service}" -ne 0 ]]; then | ||
| if [[ "${exit_code_container}" -eq 0 ]]; then | ||
| echo "${exit_code_service}" >/run/s6-linux-init-container-results/exitcode | ||
| fi | ||
| exec /run/s6/basedir/bin/halt | ||
| fi |
1 change: 1 addition & 0 deletions
1
cloudflared/rootfs/etc/s6-overlay/s6-rc.d/caddy/notification-fd
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 @@ | ||
| 3 |
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,6 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
|
|
||
| bashio::log.info "Starting Caddy..." | ||
| exec s6-notifyoncheck -c /etc/s6-overlay/s6-rc.d/caddy/check_readiness.sh \ | ||
| env XDG_DATA_HOME=/data caddy run --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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 15000 |
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 @@ | ||
| 15000 |
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 @@ | ||
| longrun |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.