Documentation
¶
Overview ¶
Package lbprotect is a project's traffic protection on its load balancers (Phase 25): Traefik rate limits (shared through a Valkey, with a fallback to per-node counters while it is down), concurrent-request and body limits, block and bypass lists, and a network guard on the project's own load-balancer nodes.
Index ¶
- func NewSecret() string
- func ValidFirewallGuard(g *agentv1.FirewallGuard) error
- type Bypass
- type ClientIP
- type ComponentState
- type Guard
- type Manager
- func (m *Manager) AutoBan(node string, port uint32) (time.Duration, string, bool)
- func (m *Manager) Components() []ComponentState
- func (m *Manager) Get(project string) Spec
- func (m *Manager) Guards(node string) []*agentv1.FirewallGuard
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) Middlewares() map[string]traefik.Middleware
- func (m *Manager) Protection(project string) *traefik.Protection
- func (m *Manager) Put(ctx context.Context, p store.Project, s Spec, sec SecretUpdate) (Spec, error)
- func (m *Manager) Redis(project string) RedisState
- func (m *Manager) Run(ctx context.Context)
- type RateLimit
- type Redis
- type RedisState
- type SecretUpdate
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidFirewallGuard ¶
func ValidFirewallGuard(g *agentv1.FirewallGuard) error
ValidFirewallGuard reports whether a guard renders (for tests).
Types ¶
type Bypass ¶
type Bypass struct {
IPs []string `json:"ips"`
Header string `json:"header"` // header name; its value is the secret
// HasSecret is set when a secret is stored (it is never returned).
HasSecret bool `json:"hasSecret"`
Paths []string `json:"paths"`
}
Bypass are requests that skip the limits (never the block list).
type ClientIP ¶
type ClientIP struct {
// Source: connection (its address), forwarded (X-Forwarded-For at
// Depth, behind a proxy or CDN) or header (e.g. CF-Connecting-IP).
Source string `json:"source"`
Depth int `json:"depth"`
Header string `json:"header"`
}
ClientIP says how clients are told apart.
type ComponentState ¶
type ComponentState struct{ ID, Name, State, Error string }
ComponentState mirrors alerts.ComponentState (this package does not depend on alerts).
type Guard ¶
type Guard struct {
// Rate is new connections per second and source (0 = no limit).
Rate int `json:"rate"`
Burst int `json:"burst"`
MaxConnections int `json:"maxConnections"` // concurrent per source (0 = no cap)
// BanMinutes blocks a source over the guard on that node (0 = no ban).
BanMinutes int `json:"banMinutes"`
}
Guard is the network guard on the project's own load-balancer nodes.
type Manager ¶
type Manager struct {
// Valkey looks a Valkey up (nil: no shared counters).
Valkey func(ctx context.Context, id string) (dbs.ValkeyTarget, error)
// IngressNodes are a project's own load-balancer nodes (by project name).
IngressNodes func(project string) []string
// Assigned maps each load-balancer node to the projects it serves.
Assigned func() map[string][]string
// OnChange runs after a change that firewalls must follow (guards).
OnChange func()
// contains filtered or unexported fields
}
Manager keeps every project's protection in memory: Traefik's config asks for it every poll.
func (*Manager) Components ¶
func (m *Manager) Components() []ComponentState
Components report each project whose shared counters fell back, for the system component alert.
func (*Manager) Guards ¶
func (m *Manager) Guards(node string) []*agentv1.FirewallGuard
Guards are the network guards of a node's 80/443 (its projects').
func (*Manager) Middlewares ¶
func (m *Manager) Middlewares() map[string]traefik.Middleware
Middlewares are every project's protection middlewares.
func (*Manager) Protection ¶
func (m *Manager) Protection(project string) *traefik.Protection
Protection is what a project's routes carry (nil: none).
func (*Manager) Redis ¶
func (m *Manager) Redis(project string) RedisState
Redis returns a project's shared-counter state.
type RateLimit ¶
type RateLimit struct {
Average int `json:"average"`
Burst int `json:"burst"`
Period string `json:"period"` // 1s | 1m | 1h
}
RateLimit is requests per Period and client (Average 0 = off).
type Redis ¶
type Redis struct {
DatabaseID string `json:"databaseId"`
}
Redis is the Valkey that keeps shared counters ("" = per node).
type RedisState ¶
type RedisState struct {
Name string `json:"name,omitempty"`
Health string `json:"health,omitempty"`
Active bool `json:"active"` // counters are shared now
Fallback bool `json:"fallback"` // its Valkey is down: per-node counters
}
RedisState is a project's shared-counter state.
type SecretUpdate ¶
SecretUpdate changes the bypass secret: Keep it, Set a new one, or Clear it.
type Spec ¶
type Spec struct {
// Enabled off keeps the settings but applies none of them.
Enabled bool `json:"enabled"`
RateLimit RateLimit `json:"rateLimit"`
ClientIP ClientIP `json:"clientIp"`
// MaxConcurrent caps a client's requests in flight (0 = no cap).
MaxConcurrent int `json:"maxConcurrent"`
// MaxBodyMB caps request bodies (0 = no cap).
MaxBodyMB int `json:"maxBodyMb"`
// Block are client IPs/CIDRs answered with 403.
Block []string `json:"block"`
Bypass Bypass `json:"bypass"`
// Redis shares the rate-limit counters between load balancers.
Redis Redis `json:"redis"`
// Guard limits connections per source on the project's own nodes.
Guard Guard `json:"guard"`
}
Spec is a project's protection.