-
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "github.com/crowdsecurity/crowdsec-spoa/pkg/cfg" | ||
| "github.com/crowdsecurity/crowdsec-spoa/pkg/dataset" | ||
| "github.com/crowdsecurity/crowdsec-spoa/pkg/host" | ||
| "github.com/crowdsecurity/crowdsec-spoa/pkg/httptemplate" | ||
| "github.com/crowdsecurity/crowdsec-spoa/pkg/metrics" | ||
| "github.com/crowdsecurity/crowdsec-spoa/pkg/spoa" | ||
| csbouncer "github.com/crowdsecurity/go-cs-bouncer" | ||
|
|
@@ -194,6 +195,24 @@ func Execute() error { | |
| } | ||
| } | ||
|
|
||
| // Create and start HTTP template server if enabled (after HostManager is created) | ||
| var httpTemplateServer *httptemplate.Server | ||
| if config.HTTPTemplateServer.Enabled { | ||
| httpTemplateLogger := log.WithField("component", "http_template_server") | ||
| var err error | ||
| httpTemplateServer, err = httptemplate.NewServer(&config.HTTPTemplateServer, HostManager, httpTemplateLogger) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create HTTP template server: %w", err) | ||
| } | ||
|
|
||
| g.Go(func() error { | ||
| if err := httpTemplateServer.Serve(ctx); err != nil { | ||
| return fmt.Errorf("HTTP template server failed: %w", err) | ||
| } | ||
| return nil | ||
| }) | ||
| } | ||
|
Comment on lines
+198
to
+214
|
||
|
|
||
| if config.HostsDir != "" { | ||
| if err := HostManager.LoadFromDirectory(config.HostsDir); err != nil { | ||
| return fmt.Errorf("failed to load hosts from directory: %w", err) | ||
|
|
@@ -252,6 +271,14 @@ func Execute() error { | |
| log.Errorf("Failed to shutdown SPOA: %v", shutdownErr) | ||
| } | ||
|
|
||
| // Shutdown HTTP template server if it was started | ||
| if httpTemplateServer != nil { | ||
| log.Info("Shutting down HTTP template server") | ||
| if shutdownErr := httpTemplateServer.Shutdown(shutdownCtx); shutdownErr != nil { | ||
| log.Errorf("Failed to shutdown HTTP template server: %v", shutdownErr) | ||
| } | ||
| } | ||
|
|
||
| // Return error only if it was unexpected | ||
| if err != nil && !isExpectedShutdown { | ||
| return err | ||
|
|
||
| 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 | ||||||||||||||||||||||
|
Comment on lines
+12
to
+16
|
||||||||||||||||||||||
| timeout server 1m | |
| timeout connect 10s | |
| timeout http-keep-alive 2m | |
| timeout queue 15s | |
| timeout tunnel 4h # for websocket | |
| timeout server 1m | |
| timeout connect 10s | |
| timeout http-keep-alive 2m | |
| timeout queue 15s | |
| timeout tunnel 4h # for websocket |
| 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 | ||||||||
|
||||||||
| - ./config/crowdsec-spoa-bouncer.yaml.local:/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml.local | |
| - ./config/crowdsec-spoa-bouncer.yaml.local:/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml.local | |
| - templates:/var/lib/crowdsec-haproxy-spoa-bouncer/html/ |
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.
The Dockerfile now only copies
.tmpltemplate files explicitly, but the old Dockerfile copied all templates withtemplates/*which would have includedban.htmlandcaptcha.html. These HTML templates are still needed for Lua-based rendering (as evidenced by the HAProxy configs that setCROWDSEC_BAN_TEMPLATE_PATHto.htmlfiles). Either add explicit COPY commands for the.htmltemplates, or revert to usingtemplates/*to copy all template files.