-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add experimental HTTP template server #109
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
Draft
LaurenceJJones
wants to merge
8
commits into
main
Choose a base branch
from
feature/http-template-server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37730b6
feat: add experimental HTTP template server
LaurenceJJones 642daae
security: remove sensitive header data from logs
LaurenceJJones 4c0742c
feat: return 403 for HEAD requests and .ico files
LaurenceJJones 7be3a1b
Merge main into feature/http-template-server
LaurenceJJones 1edcca1
fix: address Copilot PR review comments
LaurenceJJones 66727ab
fix: use parallel shutdown for services with shared timeout
LaurenceJJones ca65bcc
fix: address all Copilot security and code quality issues
LaurenceJJones 0ab1efd
Merge branch 'main' into feature/http-template-server
LaurenceJJones 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,74 @@ | ||
| # https://www.haproxy.com/documentation/hapee/latest/onepage/#home | ||
| # HAProxy configuration example using HTTP Template Server instead of Lua | ||
| # This demonstrates the experimental HTTP template server feature | ||
|
|
||
| global | ||
| log stdout format raw local0 | ||
|
|
||
| defaults | ||
| log global | ||
| option httplog | ||
| timeout client 1m | ||
| timeout server 1m | ||
| timeout connect 10s | ||
| timeout http-keep-alive 2m | ||
| timeout queue 15s | ||
| timeout tunnel 4h # for websocket | ||
|
|
||
| frontend test | ||
| mode http | ||
| bind *:9090 | ||
|
|
||
| unique-id-format %[uuid()] | ||
| unique-id-header X-Unique-ID | ||
| filter spoe engine crowdsec config /etc/haproxy/crowdsec.cfg | ||
|
|
||
| ## Define ACLs for remediation types | ||
| acl is_ban var(txn.crowdsec.remediation) -m str "ban" | ||
| acl is_captcha var(txn.crowdsec.remediation) -m str "captcha" | ||
| acl is_allow var(txn.crowdsec.remediation) -m str "allow" | ||
|
|
||
| ## Set headers for HTTP template server | ||
| ## IMPORTANT: Remove any user-provided headers first for security, then set from transaction variables | ||
| ## The server will look up host configuration using the Host header (automatically forwarded by HAProxy) | ||
| ## Only the remediation type needs to be sent - all other data comes from host configuration | ||
| http-request del-header X-Crowdsec-Remediation | ||
| http-request set-header X-Crowdsec-Remediation %[var(txn.crowdsec.remediation)] if { var(txn.crowdsec.remediation) -m found } | ||
|
|
||
| ## Set a custom header on the request for upstream services to use | ||
| http-request set-header X-Crowdsec-IsoCode %[var(txn.crowdsec.isocode)] if { var(txn.crowdsec.isocode) -m found } | ||
|
|
||
| ## Handle 302 redirect for successful captcha validation (native HAProxy redirect) | ||
| http-request redirect code 302 location %[var(txn.crowdsec.redirect)] if is_allow { var(txn.crowdsec.redirect) -m found } | ||
|
|
||
| ## Route to HTTP template server for ban and captcha remediations | ||
| ## Instead of using Lua, we proxy to the HTTP template server | ||
| ## The server uses a catch-all route, so no path rewriting is needed | ||
| ## Use OR operator (||) to combine ACLs for cleaner configuration | ||
LaurenceJJones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| use_backend http_template_server if is_ban || is_captcha | ||
|
|
||
| ## Handle captcha cookie management via HAProxy | ||
| ## Set captcha cookie when SPOA provides captcha_status (pending or valid) | ||
| http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_status) -m found } { var(txn.crowdsec.captcha_cookie) -m found } | ||
| ## Clear captcha cookie when cookie exists but no captcha_status (Allow decision) | ||
| http-after-response set-header Set-Cookie %[var(txn.crowdsec.captcha_cookie)] if { var(txn.crowdsec.captcha_cookie) -m found } !{ var(txn.crowdsec.captcha_status) -m found } | ||
|
|
||
| ## Default backend for allowed requests | ||
| use_backend test_backend | ||
|
|
||
| backend test_backend | ||
| mode http | ||
| server s1 whoami:2020 | ||
|
|
||
| backend crowdsec-spoa | ||
| mode tcp | ||
| balance roundrobin | ||
| server s2 spoa:9000 | ||
| server s3 spoa:9001 | ||
|
|
||
| backend http_template_server | ||
| mode http | ||
| # Proxy to the HTTP template server | ||
| # The server will read X-Crowdsec-Remediation header to determine which template to render | ||
| server template_server spoa:8081 | ||
|
|
||
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,68 @@ | ||
| services: | ||
| spoa: | ||
| image: crowdsecurity/crowdsec-spoa:latest | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| depends_on: | ||
| - crowdsec | ||
| volumes: | ||
| - sockets:/run/ | ||
| - geodb:/var/lib/crowdsec/data/ | ||
| - ./config/crowdsec-spoa-bouncer.yaml.local:/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml.local | ||
LaurenceJJones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| networks: | ||
| crowdsec: | ||
| ipv4_address: 10.5.5.254 | ||
| deploy: | ||
| resources: | ||
| limits: | ||
| cpus: "4.0" | ||
| memory: 250M | ||
|
|
||
| whoami: | ||
| image: traefik/whoami:latest | ||
| networks: | ||
| - crowdsec | ||
| command: | ||
| - --port=2020 | ||
|
|
||
| haproxy: | ||
| image: haproxy:2.9.7-alpine | ||
| volumes: | ||
| - ./config/haproxy-httptemplate.cfg:/usr/local/etc/haproxy/haproxy.cfg | ||
| - ./config/crowdsec.cfg:/etc/haproxy/crowdsec.cfg | ||
| - sockets:/run/ | ||
| ports: | ||
| - "9090:9090" | ||
| depends_on: | ||
| - crowdsec | ||
| - spoa | ||
| - whoami | ||
| networks: | ||
| - crowdsec | ||
|
|
||
| crowdsec: | ||
| image: crowdsecurity/crowdsec:latest | ||
| environment: | ||
| - BOUNCER_KEY_SPOA=+4iYgItcalc9+0tWrvrj9R6Wded/W1IRwRtNmcWR9Ws | ||
| - DISABLE_ONLINE_API=true | ||
| - CROWDSEC_BYPASS_DB_VOLUME_CHECK=true | ||
| volumes: | ||
| - geodb:/staging/var/lib/crowdsec/data/ | ||
| networks: | ||
| - crowdsec | ||
|
|
||
| volumes: | ||
| sockets: | ||
| driver: local | ||
| geodb: | ||
| driver: local | ||
|
|
||
| networks: | ||
| crowdsec: | ||
| driver: bridge | ||
| ipam: | ||
| driver: default | ||
| config: | ||
| - subnet: "10.5.5.0/24" | ||
|
|
||
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
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.