update default block list,docs, tests (#7942)
* update default block list,docs, tests * fix config for admin test * gofmt * remove the err return
This commit is contained in:
parent
e57d2f63fa
commit
d4a6ade65f
7 changed files with 69 additions and 63 deletions
|
|
@ -18,7 +18,6 @@ package config
|
|||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
|
@ -767,21 +766,6 @@ func NewDefault() Configuration {
|
|||
defNginxStatusIpv4Whitelist := make([]string, 0)
|
||||
defNginxStatusIpv6Whitelist := make([]string, 0)
|
||||
defResponseHeaders := make([]string, 0)
|
||||
|
||||
defAnnotationValueWordBlocklist := []string{
|
||||
"load_module",
|
||||
"lua_package",
|
||||
"_by_lua",
|
||||
"location",
|
||||
"root",
|
||||
"proxy_pass",
|
||||
"serviceaccount",
|
||||
"{",
|
||||
"}",
|
||||
"'",
|
||||
"\\",
|
||||
}
|
||||
|
||||
defIPCIDR = append(defIPCIDR, "0.0.0.0/0")
|
||||
defNginxStatusIpv4Whitelist = append(defNginxStatusIpv4Whitelist, "127.0.0.1")
|
||||
defNginxStatusIpv6Whitelist = append(defNginxStatusIpv6Whitelist, "::1")
|
||||
|
|
@ -792,7 +776,7 @@ func NewDefault() Configuration {
|
|||
|
||||
AllowSnippetAnnotations: true,
|
||||
AllowBackendServerHeader: false,
|
||||
AnnotationValueWordBlocklist: strings.Join(defAnnotationValueWordBlocklist, ","),
|
||||
AnnotationValueWordBlocklist: "",
|
||||
AccessLogPath: "/var/log/nginx/access.log",
|
||||
AccessLogParams: "",
|
||||
EnableAccessLogForDefaultBackend: false,
|
||||
|
|
|
|||
|
|
@ -242,7 +242,12 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
|
|||
cfg := n.store.GetBackendConfiguration()
|
||||
cfg.Resolver = n.resolver
|
||||
|
||||
arraybadWords := strings.Split(strings.TrimSpace(cfg.AnnotationValueWordBlocklist), ",")
|
||||
var arrayBadWords []string
|
||||
|
||||
if cfg.AnnotationValueWordBlocklist != "" {
|
||||
arrayBadWords = strings.Split(strings.TrimSpace(cfg.AnnotationValueWordBlocklist), ",")
|
||||
klog.Warningf("Blocklist is %s", cfg.AnnotationValueWordBlocklist)
|
||||
}
|
||||
|
||||
for key, value := range ing.ObjectMeta.GetAnnotations() {
|
||||
|
||||
|
|
@ -251,9 +256,11 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
|
|||
return fmt.Errorf("This deployment has a custom annotation prefix defined. Use '%s' instead of '%s'", parser.AnnotationsPrefix, parser.DefaultAnnotationsPrefix)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(key, fmt.Sprintf("%s/", parser.AnnotationsPrefix)) {
|
||||
for _, forbiddenvalue := range arraybadWords {
|
||||
|
||||
if strings.HasPrefix(key, fmt.Sprintf("%s/", parser.AnnotationsPrefix)) && len(arrayBadWords) != 0 {
|
||||
for _, forbiddenvalue := range arrayBadWords {
|
||||
if strings.Contains(value, strings.TrimSpace(forbiddenvalue)) {
|
||||
klog.Errorf("%s annotation contains invalid word %s", key, forbiddenvalue)
|
||||
return fmt.Errorf("%s annotation contains invalid word %s", key, forbiddenvalue)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -823,10 +823,11 @@ func (s *k8sStore) syncIngress(ing *networkingv1.Ingress) {
|
|||
copyIng := &networkingv1.Ingress{}
|
||||
ing.ObjectMeta.DeepCopyInto(©Ing.ObjectMeta)
|
||||
|
||||
klog.Errorf("Blocklist: %v", s.backendConfig.AnnotationValueWordBlocklist)
|
||||
if err := checkBadAnnotationValue(copyIng.Annotations, s.backendConfig.AnnotationValueWordBlocklist); err != nil {
|
||||
klog.Errorf("skipping ingress %s: %s", key, err)
|
||||
return
|
||||
if s.backendConfig.AnnotationValueWordBlocklist != "" {
|
||||
if err := checkBadAnnotationValue(copyIng.Annotations, s.backendConfig.AnnotationValueWordBlocklist); err != nil {
|
||||
klog.Errorf("skipping ingress %s: %s", key, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ing.Spec.DeepCopyInto(©Ing.Spec)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue