Provide possibility to block CIDRs, User-Agents and Referers globally
This commit is contained in:
parent
3f6314aa2f
commit
7212d0081b
6 changed files with 263 additions and 0 deletions
|
|
@ -533,12 +533,22 @@ type Configuration struct {
|
|||
|
||||
// Checksum contains a checksum of the configmap configuration
|
||||
Checksum string `json:"-"`
|
||||
|
||||
// Block all requests from given IPs
|
||||
BlockCIDRs []string `json:"block-cidrs"`
|
||||
|
||||
// Block all requests with given User-Agent headers
|
||||
BlockUserAgents []string `json:"block-user-agents"`
|
||||
|
||||
// Block all requests with given Referer headers
|
||||
BlockReferers []string `json:"block-referers"`
|
||||
}
|
||||
|
||||
// NewDefault returns the default nginx configuration
|
||||
func NewDefault() Configuration {
|
||||
defIPCIDR := make([]string, 0)
|
||||
defBindAddress := make([]string, 0)
|
||||
defBlockEntity := make([]string, 0)
|
||||
defNginxStatusIpv4Whitelist := make([]string, 0)
|
||||
defNginxStatusIpv6Whitelist := make([]string, 0)
|
||||
|
||||
|
|
@ -552,6 +562,9 @@ func NewDefault() Configuration {
|
|||
AccessLogPath: "/var/log/nginx/access.log",
|
||||
WorkerCpuAffinity: "",
|
||||
ErrorLogPath: "/var/log/nginx/error.log",
|
||||
BlockCIDRs: defBlockEntity,
|
||||
BlockUserAgents: defBlockEntity,
|
||||
BlockReferers: defBlockEntity,
|
||||
BrotliLevel: 4,
|
||||
BrotliTypes: brotliTypes,
|
||||
ClientHeaderBufferSize: "1k",
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ const (
|
|||
proxyRealIPCIDR = "proxy-real-ip-cidr"
|
||||
bindAddress = "bind-address"
|
||||
httpRedirectCode = "http-redirect-code"
|
||||
blockCIDRs = "block-cidrs"
|
||||
blockUserAgents = "block-user-agents"
|
||||
blockReferers = "block-referers"
|
||||
proxyStreamResponses = "proxy-stream-responses"
|
||||
hideHeaders = "hide-headers"
|
||||
nginxStatusIpv4Whitelist = "nginx-status-ipv4-whitelist"
|
||||
|
|
@ -71,6 +74,10 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
bindAddressIpv4List := make([]string, 0)
|
||||
bindAddressIpv6List := make([]string, 0)
|
||||
|
||||
blockCIDRList := make([]string, 0)
|
||||
blockUserAgentList := make([]string, 0)
|
||||
blockRefererList := make([]string, 0)
|
||||
|
||||
if val, ok := conf[customHTTPErrors]; ok {
|
||||
delete(conf, customHTTPErrors)
|
||||
for _, i := range strings.Split(val, ",") {
|
||||
|
|
@ -116,6 +123,19 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
if val, ok := conf[blockCIDRs]; ok {
|
||||
delete(conf, blockCIDRs)
|
||||
blockCIDRList = strings.Split(val, ",")
|
||||
}
|
||||
if val, ok := conf[blockUserAgents]; ok {
|
||||
delete(conf, blockUserAgents)
|
||||
blockUserAgentList = strings.Split(val, ",")
|
||||
}
|
||||
if val, ok := conf[blockReferers]; ok {
|
||||
delete(conf, blockReferers)
|
||||
blockRefererList = strings.Split(val, ",")
|
||||
}
|
||||
|
||||
if val, ok := conf[httpRedirectCode]; ok {
|
||||
delete(conf, httpRedirectCode)
|
||||
j, err := strconv.Atoi(val)
|
||||
|
|
@ -184,6 +204,9 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
to.ProxyRealIPCIDR = proxyList
|
||||
to.BindAddressIpv4 = bindAddressIpv4List
|
||||
to.BindAddressIpv6 = bindAddressIpv6List
|
||||
to.BlockCIDRs = blockCIDRList
|
||||
to.BlockUserAgents = blockUserAgentList
|
||||
to.BlockReferers = blockRefererList
|
||||
to.HideHeaders = hideHeadersList
|
||||
to.ProxyStreamResponses = streamResponses
|
||||
to.DisableIpv6DNS = !ing_net.IsIPv6Enabled()
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ var (
|
|||
"contains": strings.Contains,
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
"hasSuffix": strings.HasSuffix,
|
||||
"trimSpace": strings.TrimSpace,
|
||||
"toUpper": strings.ToUpper,
|
||||
"toLower": strings.ToLower,
|
||||
"formatIP": formatIP,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue