Documentation
¶
Overview ¶
Package render produces the OpenResty nginx.conf from a validated plan.
The rendered file depends on structural settings and the set of site IDs, which determines reserved rate-limit partitions. Ordinary site rules and lists remain hot updates through the control socket.
Index ¶
- Constants
- func ConfID(conf []byte) string
- func EarlyHintsProbe(p Params) ([]byte, error)
- func IsModSecurityConf(name string) bool
- func ModSecurityConf(p Params, plan *configir.Plan) (string, []byte, error)
- func ModSecurityProbe(p Params, modsecConf string) ([]byte, error)
- func OriginCAPath(prefix string, ca *configir.OriginCA) string
- func OriginCRLPath(prefix string, ca *configir.OriginCA) string
- func OriginClientCertPath(prefix, id, fingerprint string) string
- func OriginClientKeyPath(prefix, id, fingerprint string) string
- func ParseResolvConf(r io.Reader) []string
- func Render(p Params, plan *configir.Plan) ([]byte, error)
- func Resolvers(path string) []string
- func TicketKeyPath(prefix, id string) string
- func TierFiles(prefix, fingerprint string) (cert, key, ca string)
- func UpstreamProxyProtocolProbe(p Params) ([]byte, error)
- type Params
- func (p Params) ExtensionSidecarSockets(id string) (dir, sidecar, origin string)
- func (p Params) OriginLayerSockets() []string
- func (p Params) OriginLayerSocketsByName() map[string]string
- func (p Params) SidecarFallthroughSocket() string
- func (p Params) Validate() error
- func (p Params) WithDefaults() Params
Constants ¶
const ( DefaultCRSDir = "/usr/share/edgeweir-openresty/crs" DefaultUnicodeMap = "/usr/share/edgeweir-openresty/modsecurity/unicode.mapping" )
Default locations of the edgeweir-openresty packages.
const ( DefaultBanDictMB = 32 DefaultBanCapacity = 100000 MaxBanCapacity = 10000000 // CC and challenge store defaults (--cc-dict-mb, --challenge-dict-mb). DefaultCCDictMB = 32 DefaultChallengeDictMB = 8 // DefaultTagDictMB sizes the Cache-Tag index (--tag-dict-mb). DefaultTagDictMB = 64 // DefaultSitesDictMB sizes the site table store (--sites-dict-mb): the // current and the previous table, error page templates included. DefaultSitesDictMB = 64 // DefaultStatsDictMB sizes the statistics counters (--stats-dict-mb): // per site and minute until the agent drains them. DefaultStatsDictMB = 16 // DefaultL4DictMB sizes the layer-4 table store (--l4-dict-mb): the // current and the previous layer-4 table with their IP lists. DefaultL4DictMB = 32 // Rate-limit partition size of each published site (--rate-limit-dict-kb) // and its bounds. DefaultRateLimitDictKB = 256 MinRateLimitDictKB = 64 MaxRateLimitDictKB = 65536 )
Ban store defaults (--ban-dict-mb, --ban-capacity) and the capacity bounds.
const OriginCADir = "conf/origin-ca"
OriginCADir is the directory of the Origin CA's certificate and CRL under the nginx prefix (the agent writes them before rendering). nginx reads them when it loads a configuration: the file names follow their content, so a revocation changes nginx.conf and reloads.
const OriginClientDir = "conf/origin-client"
OriginClientDir is the directory of the origin client certificates' files under the nginx prefix; OriginClientCertPath and OriginClientKeyPath the files of one (the agent writes them; workers read them for new connections, proxy_ssl_certificate with variables).
const TicketKeyDir = "conf/tls-tickets"
TicketKeyDir is the directory of the session ticket key files under the nginx prefix; TicketKeyPath the file of one key (the agent writes it).
const TierDir = "conf/tier"
TierDir is the directory of the copies of the node certificate, its key and the node CA nginx reads for the tiered cache (the agent writes them before rendering). The names follow the certificate, so a renewal changes nginx.conf and reloads.
const WAFExclusionHeader = "X-Edgeweir-Waf-Ex"
WAFExclusionHeader is the internal request header in which the edge layer names the exclusion entries (SiteWaf.exclusions) that apply to a request's normalized path: their tokens between commas (",<token>,").
const WAFHeader = "X-Edgeweir-Waf"
WAFHeader is the internal request header in which the edge layer hands ModSecurity a request's site, CRS mode, paranoia level and anomaly threshold ("<site>;<mode>;<paranoia>;<threshold>"). Clients cannot send X-Edgeweir-* headers: the edge layer removes them first.
Variables ¶
This section is empty.
Functions ¶
func EarlyHintsProbe ¶ added in v1.9.0
EarlyHintsProbe resolves the private FFI symbol without opening a listener.
func IsModSecurityConf ¶
IsModSecurityConf reports whether name is a file name ModSecurityConf generates (the agent removes the ones nginx.conf no longer uses).
func ModSecurityConf ¶
ModSecurityConf returns the path (in the nginx prefix's conf directory, named after its content) and the contents of the ModSecurity configuration nginx.conf loads when a site of plan runs the OWASP CRS, or "" and nil when none does. The file holds the engine settings, the per-request settings rule reading WAFHeader, each site's excluded rules and the CRS itself.
func ModSecurityProbe ¶
ModSecurityProbe returns an nginx.conf that loads the ModSecurity module and the CRS configuration at modsecConf (see ModSecurityConf) without listening anywhere: `nginx -t` on it tells whether the node can run the CRS.
func OriginCAPath ¶ added in v1.3.0
OriginCAPath and OriginCRLPath are the files of the Origin CA's certificate and CRL.
func OriginCRLPath ¶ added in v1.3.0
func OriginClientCertPath ¶ added in v1.3.0
func OriginClientKeyPath ¶ added in v1.3.0
func ParseResolvConf ¶
ParseResolvConf extracts nameserver addresses from resolv.conf content in nginx `resolver` syntax: IPv4 as is, IPv6 in brackets. Scoped IPv6 addresses (fe80::1%eth0) are skipped because nginx cannot use them. Docker's embedded DNS (127.0.0.11) is returned like any other address.
func Resolvers ¶
Resolvers reads nameservers from path. When the file is missing or has no usable entry it returns 127.0.0.1, matching the resolv.conf(5) default of querying the local host.
func TicketKeyPath ¶ added in v1.0.0
func TierFiles ¶ added in v1.7.0
TierFiles returns the paths of the node certificate, key and CA copies for a certificate with the given SHA-256 fingerprint (hex).
func UpstreamProxyProtocolProbe ¶ added in v1.6.0
UpstreamProxyProtocolProbe returns an nginx.conf with an upstream that writes a PROXY protocol header (proxy_protocol_header, edgeweir-openresty's nginx-upstream-proxy-protocol.patch) without listening anywhere: `nginx -t` on it tells whether the node can send PROXY protocol to HTTP origins (feature origin-proxy-protocol-v1).
Types ¶
type Params ¶
type Params struct {
// Prefix is the nginx prefix directory (-p); holds logs/ and tmp/.
Prefix string
// LuaDir contains the edgeweir/*.lua modules.
LuaDir string
// CacheDir is the parent directory of all proxy_cache_path zones.
CacheDir string
// ControlSocket is the unix socket of the control API.
ControlSocket string
// ExtensionSocketDir holds a directory per extension sidecar with its
// socket and the origin socket nginx serves for it (default: the
// control socket's directory + "-ext"; outside it, so that sidecars
// never reach the control sockets).
ExtensionSocketDir string
// EdgeSocket and EdgeTLSSocket are the local edge listeners (plain
// and TLS) of the agent's prefetch requests (default: edge.sock next
// to ControlSocket, edge-tls.sock next to EdgeSocket). Requests there
// skip bans, CC, challenges, access-denying rules and statistics
// (edgeweir.router).
EdgeSocket string
EdgeTLSSocket string
// GeoIPSocket is the agent's GeoIP lookup socket (default:
// ControlSocket + ".geo"). nginx.conf names it only when GeoIPServed
// is set: without a GeoIP database the agent serves nothing there, and
// an empty geoip_socket keeps the workers from trying to connect.
GeoIPSocket string
GeoIPServed bool
// AgentSocket is the agent's unix socket for the data plane's requests
// (PURGE method; default: agent.sock next to ControlSocket).
AgentSocket string
// ImageSocket is the agent's image converter between the edge and the
// origin layer (upstream edgeweir_image, ADR-0043; default: image.sock
// next to ControlSocket).
ImageSocket string
// MarkdownSocket is the agent's Markdown converter between the edge and
// the origin layer (upstream edgeweir_markdown; default: markdown.sock
// next to ControlSocket).
MarkdownSocket string
// OriginSocket is the unix socket of the internal origin layer.
OriginSocket string
// OriginSocketNoVerify is the unix socket of the origin layer for sites
// that skip TLS verification (default: origin-noverify.sock next to
// OriginSocket).
OriginSocketNoVerify string
// OriginSocketH2 and OriginSocketNoVerifyH2 are the origin layers of
// sites that send their requests to the origins over HTTP/2 (default:
// origin-h2.sock and origin-noverify-h2.sock next to OriginSocket).
OriginSocketH2 string
OriginSocketNoVerifyH2 string
// OriginSocketGRPC and OriginSocketNoVerifyGRPC are the origin layers
// of gRPC requests, which the edge reaches over HTTP/2 (default:
// origin-grpc.sock and origin-noverify-grpc.sock next to OriginSocket).
OriginSocketGRPC string
OriginSocketNoVerifyGRPC string
// OriginSocketOriginCA, OriginSocketOriginCAH2 and
// OriginSocketOriginCAGRPC are the origin layers of sites that verify
// their origins against the Origin CA alone (feature origin-ca-v1;
// default: origin-oca.sock, origin-oca-h2.sock and origin-oca-grpc.sock
// next to OriginSocket), rendered while a site trusts it.
OriginSocketOriginCA string
OriginSocketOriginCAH2 string
OriginSocketOriginCAGRPC string
// TierSocket is the unix socket of the tier layer, through which the
// edge fetches from upper tiers (default: tier.sock next to
// OriginSocket); rendered while a site of the node has upper tiers.
TierSocket string
// TrustedCA is the CA bundle used to verify HTTPS origins. Empty means
// none was found: origins that must be verified then fail closed.
TrustedCA string
// ResolvConf is the file the resolvers were read from (comment only).
ResolvConf string
// Resolvers are nginx resolver addresses (IPv6 bracketed).
Resolvers []string
// ResolverIPv6 enables AAAA lookups for origins.
ResolverIPv6 bool
// ListenIPv6 adds `listen [::]:port` for every listener.
ListenIPv6 bool
// User is rendered as the `user` directive when the master runs as
// root; empty keeps nginx's default.
User string
WorkerProcesses string
// WorkerRlimitNofile raises the workers' open file limit (0: unset).
WorkerRlimitNofile uint64
// WorkerConnections is the connections of a worker besides the
// listening sockets: Render adds those (nginx counts every listening
// socket, each reuseport clone too, against worker_connections).
WorkerConnections int
// CPUs bounds the workers of `worker_processes auto` when counting
// reuseport clones (0: runtime.NumCPU()).
CPUs int
ErrorLogLevel string
SitesDictMB int
StatsDictMB int
PurgeDictMB int
// BanDictMB sizes lua_shared_dict edgeweir_bans; BanCapacity is the
// number of bans it may hold (edgeweir.bans).
BanDictMB int
BanCapacity int
// CCDictMB sizes lua_shared_dict edgeweir_cc (CC counters, levels and
// events), ChallengeDictMB edgeweir_challenge (keys, captcha pool and
// used challenge nonces).
CCDictMB int
ChallengeDictMB int
// TagDictMB sizes lua_shared_dict edgeweir_tags, the Cache-Tag index
// (tags and key epoch of cached objects, for purges by tag).
TagDictMB int
// RateLimitDictKB sizes the rate-limit partition (lua_shared_dict
// edgeweir_rate_<hex site id>) of every published site, in KiB.
RateLimitDictKB int
// ModSecurityModule is the ModSecurity-nginx dynamic module; nginx.conf
// loads it only while a site runs the OWASP CRS. Empty: the node has
// none (such configurations are rejected earlier, see configir).
ModSecurityModule string
// CRSDir holds crs-setup.conf and rules/ of the OWASP CRS.
CRSDir string
// ModSecurityUnicodeMap is ModSecurity's unicode.mapping (optional).
ModSecurityUnicodeMap string
// L4Socket is the unix socket of the stream subsystem's control relay
// (default: l4.sock next to ControlSocket); the control API forwards
// /v1/l4 requests to it. L4DictMB sizes lua_shared_dict edgeweir_l4
// (the current and the previous layer-4 table with their IP lists).
L4Socket string
L4DictMB int
// WorkerShutdownTimeout bounds the graceful shutdown of the workers a
// reload replaces (worker_shutdown_timeout, every connection they still
// serve); 0 leaves it unset: old workers serve their connections until
// these end.
WorkerShutdownTimeout time.Duration
}
Params are the node-local settings of the rendered configuration.
func (Params) ExtensionSidecarSockets ¶ added in v1.7.0
ExtensionSidecarSockets returns an extension's sidecar socket directory, its socket and the origin socket (Params.ExtensionSocketDir/<id>).
func (Params) OriginLayerSockets ¶ added in v0.2.1
OriginLayerSockets are the unix sockets of the origin layer servers (with defaults applied).
func (Params) OriginLayerSocketsByName ¶ added in v1.0.0
OriginLayerSocketsByName maps the edge layer's upstream names of the origin layers (the values of $edgeweir_origin_layer) to their unix sockets (with defaults applied).
func (Params) SidecarFallthroughSocket ¶ added in v1.7.0
SidecarFallthroughSocket answers 599 for sidecars nginx cannot reach.
func (Params) Validate ¶
Validate checks the settings Render needs (after WithDefaults): paths, names, sizes and resolvers.
func (Params) WithDefaults ¶
WithDefaults fills zero values with production defaults.