Skip to content

Commit 2650e29

Browse files
committed
BUG/MEDIUM: haproxy rules should be mapped to ingress.Namespace+ingress.Name
We used to have haproxy rules mapped only to ingress.Name this results in conflicts when the same ingress name is reused in different namespaces.
1 parent a5ffff6 commit 2650e29

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

controller/configuration.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,41 @@ func (c *Configuration) HAProxyRulesInit() error {
6464
// ForwardedProto rule
6565
c.HAProxyRules.AddRule(rules.SetHdr{
6666
ForwardedProto: true,
67-
}, nil, FrontendHTTPS),
67+
}, "", FrontendHTTPS),
6868
// txn.base var used for logging
6969
c.HAProxyRules.AddRule(rules.ReqSetVar{
7070
Name: "base",
7171
Scope: "txn",
7272
Expression: "base",
73-
}, nil, FrontendHTTP, FrontendHTTPS),
73+
}, "", FrontendHTTP, FrontendHTTPS),
7474
// Backend switching rules.
7575
c.HAProxyRules.AddRule(rules.ReqSetVar{
7676
Name: "path",
7777
Scope: "txn",
7878
Expression: "path",
79-
}, nil, FrontendHTTP, FrontendHTTPS),
79+
}, "", FrontendHTTP, FrontendHTTPS),
8080
c.HAProxyRules.AddRule(rules.ReqSetVar{
8181
Name: "host",
8282
Scope: "txn",
8383
Expression: fmt.Sprintf("req.hdr(Host),field(1,:),lower,map(%s)", haproxy.GetMapPath(HOST)),
84-
}, nil, FrontendHTTP, FrontendHTTPS),
84+
}, "", FrontendHTTP, FrontendHTTPS),
8585
c.HAProxyRules.AddRule(rules.ReqSetVar{
8686
Name: "host",
8787
Scope: "txn",
8888
Expression: fmt.Sprintf("req.hdr(Host),field(1,:),regsub(^[^.]*,,),lower,map(%s,'')", haproxy.GetMapPath(HOST)),
8989
CondTest: "!{ var(txn.host) -m found }",
90-
}, nil, FrontendHTTP, FrontendHTTPS),
90+
}, "", FrontendHTTP, FrontendHTTPS),
9191
c.HAProxyRules.AddRule(rules.ReqSetVar{
9292
Name: "match",
9393
Scope: "txn",
9494
Expression: fmt.Sprintf("var(txn.host),concat(,txn.path,),map(%s)", haproxy.GetMapPath(PATH_EXACT)),
95-
}, nil, FrontendHTTP, FrontendHTTPS),
95+
}, "", FrontendHTTP, FrontendHTTPS),
9696
c.HAProxyRules.AddRule(rules.ReqSetVar{
9797
Name: "match",
9898
Scope: "txn",
9999
Expression: fmt.Sprintf("var(txn.host),concat(,txn.path,),map_beg(%s)", haproxy.GetMapPath(PATH_PREFIX)),
100100
CondTest: "!{ var(txn.match) -m found }",
101-
}, nil, FrontendHTTP, FrontendHTTPS),
101+
}, "", FrontendHTTP, FrontendHTTPS),
102102
)
103103

104104
return errors.Result()

controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (c *HAProxyController) updateHAProxy() {
246246
Ingress: ingress,
247247
Host: rule.Host,
248248
Path: path,
249-
HAProxyRules: c.cfg.HAProxyRules.GetIngressRuleIDs(ingress.Name),
249+
HAProxyRules: c.cfg.HAProxyRules.GetIngressRuleIDs(ingress.Namespace + "-" + ingress.Name),
250250
SSLPassthrough: c.sslPassthroughEnabled(namespace, ingress, path),
251251
}))
252252
}

controller/frontend-annotations.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c *HAProxyController) handleSourceIPHeader(ingress *store.Ingress) {
6060
reqSetSrc := rules.ReqSetSrc{
6161
HeaderName: srcIPHeader.Value,
6262
}
63-
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetSrc, &ingress.Name, FrontendHTTP, FrontendHTTPS))
63+
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetSrc, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
6464
}
6565

6666
func (c *HAProxyController) handleBlacklisting(ingress *store.Ingress) {
@@ -90,7 +90,7 @@ func (c *HAProxyController) handleBlacklisting(ingress *store.Ingress) {
9090
reqBlackList := rules.ReqDeny{
9191
SrcIPsMap: mapName,
9292
}
93-
logger.Error(c.cfg.HAProxyRules.AddRule(reqBlackList, &ingress.Name, FrontendHTTP, FrontendHTTPS))
93+
logger.Error(c.cfg.HAProxyRules.AddRule(reqBlackList, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
9494
}
9595

9696
func (c *HAProxyController) handleWhitelisting(ingress *store.Ingress) {
@@ -121,7 +121,7 @@ func (c *HAProxyController) handleWhitelisting(ingress *store.Ingress) {
121121
SrcIPsMap: mapName,
122122
Whitelist: true,
123123
}
124-
logger.Error(c.cfg.HAProxyRules.AddRule(reqWhitelist, &ingress.Name, FrontendHTTP, FrontendHTTPS))
124+
logger.Error(c.cfg.HAProxyRules.AddRule(reqWhitelist, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
125125
}
126126

127127
func (c *HAProxyController) handleRequestRateLimiting(ingress *store.Ingress) {
@@ -171,8 +171,8 @@ func (c *HAProxyController) handleRequestRateLimiting(ingress *store.Ingress) {
171171
ReqsLimit: reqsLimit,
172172
DenyStatusCode: rateLimitCode,
173173
}
174-
logger.Error(c.cfg.HAProxyRules.AddRule(reqTrack, &ingress.Name, FrontendHTTP, FrontendHTTPS))
175-
logger.Error(c.cfg.HAProxyRules.AddRule(reqRateLimit, &ingress.Name, FrontendHTTP, FrontendHTTPS))
174+
logger.Error(c.cfg.HAProxyRules.AddRule(reqTrack, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
175+
logger.Error(c.cfg.HAProxyRules.AddRule(reqRateLimit, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
176176
}
177177

178178
func (c *HAProxyController) handleRequestBasicAuth(ingress *store.Ingress) {
@@ -232,7 +232,7 @@ func (c *HAProxyController) handleRequestBasicAuth(ingress *store.Ingress) {
232232
AuthRealm: realm,
233233
AuthGroup: userListName,
234234
}
235-
logger.Error(c.cfg.HAProxyRules.AddRule(reqBasicAuth, &ingress.Name, FrontendHTTP, FrontendHTTPS))
235+
logger.Error(c.cfg.HAProxyRules.AddRule(reqBasicAuth, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
236236
}
237237

238238
func (c *HAProxyController) handleRequestHostRedirect(ingress *store.Ingress) {
@@ -252,9 +252,9 @@ func (c *HAProxyController) handleRequestHostRedirect(ingress *store.Ingress) {
252252
RedirectCode: domainRedirectCode,
253253
Host: annDomainRedirect.Value,
254254
}
255-
logger.Error(c.cfg.HAProxyRules.AddRule(reqDomainRedirect, &ingress.Name, FrontendHTTP))
255+
logger.Error(c.cfg.HAProxyRules.AddRule(reqDomainRedirect, ingress.Namespace+"-"+ingress.Name, FrontendHTTP))
256256
reqDomainRedirect.SSLRequest = true
257-
logger.Error(c.cfg.HAProxyRules.AddRule(reqDomainRedirect, &ingress.Name, FrontendHTTPS))
257+
logger.Error(c.cfg.HAProxyRules.AddRule(reqDomainRedirect, ingress.Namespace+"-"+ingress.Name, FrontendHTTPS))
258258
}
259259

260260
func (c *HAProxyController) handleRequestHTTPSRedirect(ingress *store.Ingress) {
@@ -290,7 +290,7 @@ func (c *HAProxyController) handleRequestHTTPSRedirect(ingress *store.Ingress) {
290290
RedirectPort: sslRedirectPort,
291291
SSLRedirect: true,
292292
}
293-
logger.Error(c.cfg.HAProxyRules.AddRule(reqSSLRedirect, &ingress.Name, FrontendHTTP))
293+
logger.Error(c.cfg.HAProxyRules.AddRule(reqSSLRedirect, ingress.Namespace+"-"+ingress.Name, FrontendHTTP))
294294
}
295295

296296
func (c *HAProxyController) handleRequestCapture(ingress *store.Ingress) {
@@ -321,7 +321,7 @@ func (c *HAProxyController) handleRequestCapture(ingress *store.Ingress) {
321321
Expression: sample,
322322
CaptureLen: captureLen,
323323
}
324-
logger.Error(c.cfg.HAProxyRules.AddRule(reqCapture, &ingress.Name, FrontendHTTP, FrontendHTTPS))
324+
logger.Error(c.cfg.HAProxyRules.AddRule(reqCapture, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
325325
}
326326
}
327327

@@ -341,7 +341,7 @@ func (c *HAProxyController) handleRequestSetHost(ingress *store.Ingress) {
341341
HdrName: "Host",
342342
HdrFormat: annSetHost.Value,
343343
}
344-
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetHost, &ingress.Name, FrontendHTTP, FrontendHTTPS))
344+
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetHost, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
345345
}
346346

347347
func (c *HAProxyController) handleRequestPathRewrite(ingress *store.Ingress) {
@@ -374,7 +374,7 @@ func (c *HAProxyController) handleRequestPathRewrite(ingress *store.Ingress) {
374374
logger.Errorf("incorrect value '%s', path-rewrite takes 1 or 2 params ", annPathRewrite.Value)
375375
return
376376
}
377-
logger.Error(c.cfg.HAProxyRules.AddRule(reqPathReWrite, &ingress.Name, FrontendHTTP, FrontendHTTPS))
377+
logger.Error(c.cfg.HAProxyRules.AddRule(reqPathReWrite, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
378378
}
379379

380380
func (c *HAProxyController) handleRequestSetHdr(ingress *store.Ingress) {
@@ -399,7 +399,7 @@ func (c *HAProxyController) handleRequestSetHdr(ingress *store.Ingress) {
399399
HdrName: parts[0],
400400
HdrFormat: parts[1],
401401
}
402-
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS))
402+
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
403403
}
404404
}
405405

@@ -429,7 +429,7 @@ func (c *HAProxyController) handleResponseSetHdr(ingress *store.Ingress) {
429429
HdrFormat: param[indexSpace+1:],
430430
Response: true,
431431
}
432-
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS))
432+
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
433433
}
434434
}
435435

@@ -481,7 +481,7 @@ func (c *HAProxyController) handleResponseCorsOrigin(ingress *store.Ingress) (ac
481481
Name: originVar,
482482
Scope: "txn",
483483
Expression: "req.hdr(origin)",
484-
}, &ingress.Name, FrontendHTTP, FrontendHTTPS)
484+
}, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS)
485485
if err != nil {
486486
return acl, err
487487
}
@@ -500,7 +500,7 @@ func (c *HAProxyController) handleResponseCorsOrigin(ingress *store.Ingress) (ac
500500
resSetHdr.HdrFormat = "%[var(txn." + originVar + ")]"
501501
resSetHdr.CondTest = acl
502502
}
503-
err = c.cfg.HAProxyRules.AddRule(resSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS)
503+
err = c.cfg.HAProxyRules.AddRule(resSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS)
504504
if err != nil {
505505
return acl, err
506506
}
@@ -537,7 +537,7 @@ func (c *HAProxyController) handleResponseCorsMethod(ingress *store.Ingress, acl
537537
Response: true,
538538
CondTest: acl,
539539
}
540-
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS))
540+
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
541541
}
542542

543543
func (c *HAProxyController) handleResponseCorsCredential(ingress *store.Ingress, acl string) {
@@ -561,7 +561,7 @@ func (c *HAProxyController) handleResponseCorsCredential(ingress *store.Ingress,
561561
Response: true,
562562
CondTest: acl,
563563
}
564-
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS))
564+
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
565565
}
566566

567567
func (c *HAProxyController) handleResponseCorsHeaders(ingress *store.Ingress, acl string) {
@@ -581,7 +581,7 @@ func (c *HAProxyController) handleResponseCorsHeaders(ingress *store.Ingress, ac
581581
Response: true,
582582
CondTest: acl,
583583
}
584-
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS))
584+
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
585585
}
586586

587587
func (c *HAProxyController) handleResponseCorsMaxAge(ingress *store.Ingress, acl string) {
@@ -611,7 +611,7 @@ func (c *HAProxyController) handleResponseCorsMaxAge(ingress *store.Ingress, acl
611611
Response: true,
612612
CondTest: acl,
613613
}
614-
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, &ingress.Name, FrontendHTTP, FrontendHTTPS))
614+
logger.Error(c.cfg.HAProxyRules.AddRule(resSetHdr, ingress.Namespace+"-"+ingress.Name, FrontendHTTP, FrontendHTTPS))
615615
}
616616

617617
func tlsEnabled(ingress *store.Ingress) bool {

controller/handler-https.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ func (h HTTPS) sslPassthroughRules(k store.K8s, cfg *Configuration) error {
191191
cfg.HAProxyRules.EnableSSLPassThrough(FrontendSSL, FrontendHTTPS)
192192
errors := utils.Errors{}
193193
errors.Add(
194-
cfg.HAProxyRules.AddRule(rules.ReqAcceptContent{}, nil, FrontendSSL),
194+
cfg.HAProxyRules.AddRule(rules.ReqAcceptContent{}, "", FrontendSSL),
195195
cfg.HAProxyRules.AddRule(rules.ReqSetVar{
196196
Name: "sni",
197197
Scope: "sess",
198198
Expression: "req_ssl_sni",
199-
}, nil, FrontendSSL),
199+
}, "", FrontendSSL),
200200
cfg.HAProxyRules.AddRule(rules.ReqInspectDelay{
201201
Timeout: inspectTimeout,
202-
}, nil, FrontendSSL),
202+
}, "", FrontendSSL),
203203
)
204204
return errors.Result()
205205
}

controller/handler-proxy-protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ func (p ProxyProtocol) Update(k store.K8s, cfg *Configuration, api api.HAProxyCl
5151
}
5252
// Configure Annotation
5353
logger.Debugf("Configuring ProxyProtcol annotation")
54-
err = cfg.HAProxyRules.AddRule(rules.ReqProxyProtocol{SrcIPsMap: mapName}, nil, FrontendHTTP, FrontendHTTPS)
54+
err = cfg.HAProxyRules.AddRule(rules.ReqProxyProtocol{SrcIPsMap: mapName}, "", FrontendHTTP, FrontendHTTPS)
5555
return false, err
5656
}

controller/haproxy/rules.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func NewRules() *Rules {
8585
}
8686
}
8787

88-
func (r Rules) AddRule(rule Rule, ingressName *string, frontends ...string) error {
88+
func (r Rules) AddRule(rule Rule, ingressName string, frontends ...string) error {
8989
if rule == nil || len(frontends) == 0 {
9090
return fmt.Errorf("invalid params")
9191
}
@@ -111,11 +111,11 @@ func (r Rules) AddRule(rule Rule, ingressName *string, frontends ...string) erro
111111
ftRules.status[id] = TO_CREATE
112112
}
113113
}
114-
if ingressName != nil {
114+
if ingressName != "" {
115115
for _, frontend := range frontends {
116116
r.frontendRules[frontend].status[id] |= INGRESS
117117
}
118-
r.ingressRuleIDs[*ingressName] = append(r.ingressRuleIDs[*ingressName], id)
118+
r.ingressRuleIDs[ingressName] = append(r.ingressRuleIDs[ingressName], id)
119119
}
120120
return nil
121121
}

0 commit comments

Comments
 (0)