-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add option to force enabling snippet directives #7665
Changes from all 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 |
---|---|---|
|
@@ -46,6 +46,7 @@ The following table shows a configuration option's name, type, and the default v | |
|[disable-access-log](#disable-access-log)|bool|false| | ||
|[disable-ipv6](#disable-ipv6)|bool|false| | ||
|[disable-ipv6-dns](#disable-ipv6-dns)|bool|false| | ||
|[enable-snippet-directives](#enable-snippet-directives)|bool|true| | ||
|[enable-underscores-in-headers](#enable-underscores-in-headers)|bool|false| | ||
|[enable-ocsp](#enable-ocsp)|bool|false| | ||
|[ignore-invalid-headers](#ignore-invalid-headers)|bool|true| | ||
|
@@ -316,6 +317,12 @@ Disable listening on IPV6. _**default:**_ `false`; IPv6 listening is enabled | |
|
||
Disable IPV6 for nginx DNS resolver. _**default:**_ `false`; IPv6 resolving enabled. | ||
|
||
## enable-snippet-directives | ||
|
||
Enables Ingress to parse and add *-snippet annotations/directives created by the user. _**default:**_ `true`; | ||
Obs.: We recommend enabling this option only if you TRUST users with permission to create Ingress objects, as this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, agreed. I will change this one here. Obs is a shorten for "Observação" in portuguese and my head though this made all sense in english...hahaha I will change here for WARNING @strongjz @cpanato I'm tempted now in changing to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍🏼 i learned some portuguese |
||
may allow a user to add restricted configurations to the final nginx.conf file | ||
|
||
## enable-underscores-in-headers | ||
|
||
Enables underscores in header names. _**default:**_ is disabled | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,27 +234,28 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error { | |
return fmt.Errorf("This deployment is trying to create a catch-all ingress while DisableCatchAll flag is set to true. Remove '.spec.backend' or set DisableCatchAll flag to false.") | ||
} | ||
|
||
if parser.AnnotationsPrefix != parser.DefaultAnnotationsPrefix { | ||
for key := range ing.ObjectMeta.GetAnnotations() { | ||
cfg := n.store.GetBackendConfiguration() | ||
cfg.Resolver = n.resolver | ||
|
||
for key := range ing.ObjectMeta.GetAnnotations() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For those wondering about this change, as we have a bunch of "fors" in admission webhook for annotations I though it would be better to move all of them to a single iteraction (performance yeeey) |
||
if parser.AnnotationsPrefix != parser.DefaultAnnotationsPrefix { | ||
if strings.HasPrefix(key, fmt.Sprintf("%s/", parser.DefaultAnnotationsPrefix)) { | ||
return fmt.Errorf("This deployment has a custom annotation prefix defined. Use '%s' instead of '%s'", parser.AnnotationsPrefix, parser.DefaultAnnotationsPrefix) | ||
} | ||
} | ||
} | ||
|
||
k8s.SetDefaultNGINXPathType(ing) | ||
|
||
cfg := n.store.GetBackendConfiguration() | ||
cfg.Resolver = n.resolver | ||
if !cfg.EnableSnippetDirectives && strings.HasSuffix(key, "-snippet") { | ||
return fmt.Errorf("%s annotation cannot be used. Snippet directives are disabled by the Ingress administrator", key) | ||
} | ||
|
||
if len(cfg.GlobalRateLimitMemcachedHost) == 0 { | ||
for key := range ing.ObjectMeta.GetAnnotations() { | ||
if strings.HasPrefix(key, fmt.Sprintf("%s/%s", parser.AnnotationsPrefix, "global-rate-limit")) { | ||
return fmt.Errorf("'global-rate-limit*' annotations require 'global-rate-limit-memcached-host' settings configured in the global configmap") | ||
} | ||
if len(cfg.GlobalRateLimitMemcachedHost) == 0 && strings.HasPrefix(key, fmt.Sprintf("%s/%s", parser.AnnotationsPrefix, "global-rate-limit")) { | ||
return fmt.Errorf("'global-rate-limit*' annotations require 'global-rate-limit-memcached-host' settings configured in the global configmap") | ||
} | ||
|
||
} | ||
|
||
k8s.SetDefaultNGINXPathType(ing) | ||
|
||
allIngresses := n.store.ListIngresses() | ||
|
||
filter := func(toCheck *ingress.Ingress) bool { | ||
|
@@ -511,6 +512,30 @@ func (n *NGINXController) getConfiguration(ingresses []*ingress.Ingress) (sets.S | |
} | ||
} | ||
|
||
func dropSnippetDirectives(anns *annotations.Ingress, ingKey string) { | ||
if anns != nil { | ||
if anns.ConfigurationSnippet != "" { | ||
klog.V(3).Infof("Ingress %q tried to use configuration-snippet and the annotation is disabled by the admin. Removing the annotation", ingKey) | ||
anns.ConfigurationSnippet = "" | ||
} | ||
if anns.ServerSnippet != "" { | ||
klog.V(3).Infof("Ingress %q tried to use server-snippet and the annotation is disabled by the admin. Removing the annotation", ingKey) | ||
anns.ServerSnippet = "" | ||
} | ||
|
||
if anns.ModSecurity.Snippet != "" { | ||
klog.V(3).Infof("Ingress %q tried to use modsecurity-snippet and the annotation is disabled by the admin. Removing the annotation", ingKey) | ||
anns.ModSecurity.Snippet = "" | ||
} | ||
|
||
if anns.ExternalAuth.AuthSnippet != "" { | ||
klog.V(3).Infof("Ingress %q tried to use auth-snippet and the annotation is disabled by the admin. Removing the annotation", ingKey) | ||
anns.ExternalAuth.AuthSnippet = "" | ||
} | ||
|
||
} | ||
} | ||
|
||
// getBackendServers returns a list of Upstream and Server to be used by the | ||
// backend. An upstream can be used in multiple servers if the namespace, | ||
// service name and port are the same. | ||
|
@@ -525,6 +550,10 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in | |
ingKey := k8s.MetaNamespaceKey(ing) | ||
anns := ing.ParsedAnnotations | ||
|
||
if !n.store.GetBackendConfiguration().EnableSnippetDirectives { | ||
dropSnippetDirectives(anns, ingKey) | ||
} | ||
|
||
for _, rule := range ing.Spec.Rules { | ||
host := rule.Host | ||
if host == "" { | ||
|
@@ -801,6 +830,10 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B | |
ingKey := k8s.MetaNamespaceKey(ing) | ||
anns := ing.ParsedAnnotations | ||
|
||
if !n.store.GetBackendConfiguration().EnableSnippetDirectives { | ||
dropSnippetDirectives(anns, ingKey) | ||
} | ||
|
||
var defBackend string | ||
if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil { | ||
defBackend = upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service) | ||
|
@@ -1091,6 +1124,10 @@ func (n *NGINXController) createServers(data []*ingress.Ingress, | |
ingKey := k8s.MetaNamespaceKey(ing) | ||
anns := ing.ParsedAnnotations | ||
|
||
if !n.store.GetBackendConfiguration().EnableSnippetDirectives { | ||
dropSnippetDirectives(anns, ingKey) | ||
} | ||
|
||
// default upstream name | ||
un := du.Name | ||
|
||
|
@@ -1167,6 +1204,10 @@ func (n *NGINXController) createServers(data []*ingress.Ingress, | |
ingKey := k8s.MetaNamespaceKey(ing) | ||
anns := ing.ParsedAnnotations | ||
|
||
if !n.store.GetBackendConfiguration().EnableSnippetDirectives { | ||
dropSnippetDirectives(anns, ingKey) | ||
} | ||
|
||
if anns.Canary.Enabled { | ||
klog.V(2).Infof("Ingress %v is marked as Canary, ignoring", ingKey) | ||
continue | ||
|
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.
what about
allow-snippet-annotations
?