Skip to content

Commit a5ffff6

Browse files
committed
MINOR: Make src-ip-header annotation available by Ingress
We used to have src-ip-header annotation only available at ConfigMap level. This is now available at the Ingress level too.
1 parent 0ed6443 commit a5ffff6

File tree

6 files changed

+22
-42
lines changed

6 files changed

+22
-42
lines changed

controller/frontend-annotations.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
var rateLimitTables []string
3232

3333
func (c *HAProxyController) handleIngressAnnotations(ingress *store.Ingress) {
34+
c.handleSourceIPHeader(ingress)
3435
c.handleBlacklisting(ingress)
3536
c.handleWhitelisting(ingress)
3637
c.handleRequestRateLimiting(ingress)
@@ -45,6 +46,23 @@ func (c *HAProxyController) handleIngressAnnotations(ingress *store.Ingress) {
4546
c.handleResponseCors(ingress)
4647
}
4748

49+
func (c *HAProxyController) handleSourceIPHeader(ingress *store.Ingress) {
50+
srcIPHeader, _ := c.Store.GetValueFromAnnotations("src-ip-header", ingress.Annotations, c.Store.ConfigMaps[Main].Annotations)
51+
52+
if srcIPHeader == nil {
53+
return
54+
}
55+
if srcIPHeader.Status == DELETED || len(srcIPHeader.Value) == 0 {
56+
logger.Debugf("Ingress %s/%s: Deleting Source IP configuration", ingress.Namespace, ingress.Name)
57+
return
58+
}
59+
logger.Debugf("Ingress %s/%s: Configuring Source IP annotation", ingress.Namespace, ingress.Name)
60+
reqSetSrc := rules.ReqSetSrc{
61+
HeaderName: srcIPHeader.Value,
62+
}
63+
logger.Error(c.cfg.HAProxyRules.AddRule(reqSetSrc, &ingress.Name, FrontendHTTP, FrontendHTTPS))
64+
}
65+
4866
func (c *HAProxyController) handleBlacklisting(ingress *store.Ingress) {
4967
// Get annotation status
5068
annBlacklist, _ := c.Store.GetValueFromAnnotations("blacklist", ingress.Annotations, c.Store.ConfigMaps[Main].Annotations)

controller/handler-src-ip.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

controller/handler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type UpdateHandler interface {
2525

2626
func (c *HAProxyController) initHandlers() {
2727
c.UpdateHandlers = []UpdateHandler{
28-
SourceIPHeader{},
2928
ProxyProtocol{},
3029
ErrorFile{},
3130
HTTPS{

controller/haproxy/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const (
2828
REQ_ACCEPT_CONTENT RuleType = iota
2929
REQ_INSPECT_DELAY
3030
REQ_PROXY_PROTOCOL
31-
REQ_SET_SRC
3231
REQ_SET_VAR
32+
REQ_SET_SRC
3333
REQ_DENY
3434
REQ_TRACK
3535
REQ_AUTH

documentation/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This is autogenerated from [doc.yaml](doc.yaml). Description can be found in [ge
3232
| [backend-config-snippet](#config-snippet) | string | | |:large_blue_circle:|:large_blue_circle:|:large_blue_circle:|
3333
| [cookie-persistence](#cookie-persistence) | string | | |:large_blue_circle:|:large_blue_circle:|:large_blue_circle:|
3434
| [dontlognull](#logging) | [bool](#bool) | "true" | |:large_blue_circle:|:white_circle:|:white_circle:|
35-
| [src-ip-header](#src-ip-header) | string | "null" | |:large_blue_circle:|:white_circle:|:white_circle:|
35+
| [src-ip-header](#src-ip-header) | string | "null" | |:large_blue_circle:|:large_blue_circle:|:white_circle:|
3636
| [forwarded-for](#x-forwarded-for) | [bool](#bool) | "true" | |:large_blue_circle:|:large_blue_circle:|:large_blue_circle:|
3737
| [hard-stop-after](#hard-stop-after) | [time](#time) | "1h" | |:large_blue_circle:|:white_circle:|:white_circle:|
3838
| [http-keep-alive](#http-options) | [bool](#bool) | "true" | |:large_blue_circle:|:white_circle:|:white_circle:|
@@ -1331,7 +1331,7 @@ set-host: "example.local"
13311331

13321332
Set the source IP from a header rather than the L3 connection.
13331333

1334-
Available on: `configmap`
1334+
Available on: `configmap` `ingress`
13351335

13361336
Possible values:
13371337

documentation/doc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ annotations:
675675
- "any header name"
676676
applies_to:
677677
- configmap
678+
- ingress
678679
version_min: "1.5"
679680
example: ['src-ip-header: "True-Client-IP"']
680681
- title: forwarded-for

0 commit comments

Comments
 (0)