Skip to content

Commit 42e53c9

Browse files
committed
Enforce annotations inheritance in minions
- minions are only allowed to inherent certain annotations from their master Additional changes: - nginx.org/grpc-services is not allowed in the master anymore - nginx.org/server-snippets is not allowed in the minion anymore
1 parent 478789a commit 42e53c9

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

examples/mergeable-ingress-types/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ingress resource.
1313
Masters cannot contain the following annotations:
1414
* nginx.org/rewrites
1515
* nginx.org/ssl-services
16+
* nginx.org/grpc-services
1617
* nginx.org/websocket-services
1718
* nginx.com/sticky-cookie-services
1819
* nginx.com/health-checks
@@ -39,6 +40,21 @@ Minions cannot contain the following annotations:
3940
* nginx.com/jwt-realm
4041
* nginx.com/jwt-token
4142
* nginx.com/jwt-login-url
43+
* nginx.org/server-snippets
44+
45+
Minions inherent the following annotations from the master, unless they override them:
46+
* nginx.org/proxy-connect-timeout
47+
* nginx.org/proxy-read-timeout
48+
* nginx.org/client-max-body-size
49+
* nginx.org/proxy-buffering
50+
* nginx.org/proxy-buffers
51+
* nginx.org/proxy-buffer-size
52+
* nginx.org/proxy-max-temp-file-size
53+
* nginx.org/location-snippets
54+
* nginx.org/lb-method
55+
* nginx.org/keepalive
56+
* nginx.org/max-fails
57+
* nginx.org/fail-timeout
4258

4359
Note: Ingress Resources with more than one host cannot be used.
4460

nginx-controller/nginx/configurator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ func filterMasterAnnotations(annotations map[string]string) []string {
993993
var removedAnnotations []string
994994

995995
for key, _ := range annotations {
996-
if _, ok := masterBlacklist[key]; ok {
996+
if _, notAllowed := masterBlacklist[key]; notAllowed {
997997
removedAnnotations = append(removedAnnotations, key)
998998
delete(annotations, key)
999999
}
@@ -1006,7 +1006,7 @@ func filterMinionAnnotations(annotations map[string]string) []string {
10061006
var removedAnnotations []string
10071007

10081008
for key, _ := range annotations {
1009-
if _, ok := minionBlacklist[key]; ok {
1009+
if _, notAllowed := minionBlacklist[key]; notAllowed {
10101010
removedAnnotations = append(removedAnnotations, key)
10111011
delete(annotations, key)
10121012
}
@@ -1017,8 +1017,8 @@ func filterMinionAnnotations(annotations map[string]string) []string {
10171017

10181018
func mergeMasterAnnotationsIntoMinion(minionAnnotations map[string]string, masterAnnotations map[string]string) {
10191019
for key, val := range masterAnnotations {
1020-
if _, ok := minionAnnotations[key]; !ok {
1021-
if _, ok := minionBlacklist[key]; !ok {
1020+
if _, exists := minionAnnotations[key]; !exists {
1021+
if _, allowed := minionInheritanceList[key]; allowed {
10221022
minionAnnotations[key] = val
10231023
}
10241024
}

nginx-controller/nginx/configurator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func TestMergeMasterAnnotationsIntoMinion(t *testing.T) {
134134
"nginx.org/hsts": "True",
135135
"nginx.org/hsts-max-age": "2700000",
136136
"nginx.org/proxy-connect-timeout": "50s",
137+
"nginx.com/jwt-token": "$cookie_auth_token",
137138
}
138139
minionAnnotations := map[string]string{
139140
"nginx.org/client-max-body-size": "2m",

nginx-controller/nginx/ingress.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type MergeableIngresses struct {
2323
var masterBlacklist = map[string]bool{
2424
"nginx.org/rewrites": true,
2525
"nginx.org/ssl-services": true,
26+
"nginx.org/grpc-services": true,
2627
"nginx.org/websocket-services": true,
2728
"nginx.com/sticky-cookie-services": true,
2829
"nginx.com/health-checks": true,
@@ -45,4 +46,20 @@ var minionBlacklist = map[string]bool{
4546
"nginx.com/jwt-realm": true,
4647
"nginx.com/jwt-token": true,
4748
"nginx.com/jwt-login-url": true,
49+
"nginx.org/server-snippets": true,
50+
}
51+
52+
var minionInheritanceList = map[string]bool{
53+
"nginx.org/proxy-connect-timeout": true,
54+
"nginx.org/proxy-read-timeout": true,
55+
"nginx.org/client-max-body-size": true,
56+
"nginx.org/proxy-buffering": true,
57+
"nginx.org/proxy-buffers": true,
58+
"nginx.org/proxy-buffer-size": true,
59+
"nginx.org/proxy-max-temp-file-size": true,
60+
"nginx.org/location-snippets": true,
61+
"nginx.org/lb-method": true,
62+
"nginx.org/keepalive": true,
63+
"nginx.org/max-fails": true,
64+
"nginx.org/fail-timeout": true,
4865
}

0 commit comments

Comments
 (0)