Skip to content

Commit 0942240

Browse files
committed
apply patches to template locally
Signed-off-by: Timofei Larkin <[email protected]>
1 parent 426ea31 commit 0942240

File tree

6 files changed

+51
-218
lines changed

6 files changed

+51
-218
lines changed

images/controller/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ ARG TAG=$TAG
55
RUN apk add --no-cache git make bash
66
RUN git clone --branch controller-${TAG} --depth 1 https://github.com/kubernetes/ingress-nginx /src
77
WORKDIR /src
8-
RUN wget -O- https://github.com/kubernetes/ingress-nginx/pull/11843.diff | git apply -
8+
COPY patches/* .
9+
RUN git apply *.diff
910
RUN make build DOCKER_IN_DOCKER_ENABLED=true ARCH=amd64
1011
RUN apk add --no-cache libcap
1112
RUN setcap cap_net_bind_service+ep /src/rootfs/bin/amd64/nginx-ingress-controller
@@ -17,9 +18,6 @@ USER root
1718
# required packages to build lua and run luarocks
1819
RUN apk add --no-cache make gcc musl-dev
1920

20-
COPY lua/* /etc/nginx/lua/
21-
COPY patches /patches
22-
2321
ARG LUA_ROCKS_VER="3.0.0"
2422
RUN cd /tmp \
2523
&& wget https://luarocks.org/releases/luarocks-${LUA_ROCKS_VER}.tar.gz \
@@ -32,9 +30,12 @@ RUN cd /tmp \
3230
&& rm -rf /tmp/* \
3331
&& mkdir -p /tmp/nginx && chown www-data: /tmp/nginx \
3432
&& luarocks install lua-protobuf 0.4.1-1 \
35-
&& luarocks install lua-iconv 7-3 \
36-
&& patch /etc/nginx/template/nginx.tmpl < /patches/nginx-tmpl.patch
33+
&& luarocks install lua-iconv 7-3
3734

3835
USER www-data
3936

4037
COPY --from=builder /src/rootfs/bin/amd64/nginx-ingress-controller /nginx-ingress-controller
38+
39+
COPY --chown=www-data:www-data ./etc/nginx /etc/nginx
40+
41+
LABEL org.opencontainers.image.source="https://github.com/cozystack/ingress-nginx-with-protobuf-exporter"

images/controller/PROVENANCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Description
2+
3+
This build of the NGINX Ingress controller is built with:
4+
5+
* [kubernetes/[email protected]](https://github.com/kubernetes/ingress-nginx/tree/controller-v1.11.2) ([permalink](https://github.com/kubernetes/ingress-nginx/tree/d3bb2b4f8757816f1d7c6268e02e433887373a3b)).
6+
* [Lua modules](./etc/nginx/lua) for exporting metrics and for geohashing ([source](https://github.com/deckhouse/deckhouse/tree/49744cd7e11f86aacf493be4dec391901348ddda/modules/402-ingress-nginx/images/controller-1-10/rootfs/etc/nginx/lua)).
7+
* A patched `nginx.conf` [template](./etc/nginx/template/nginx.tmpl). The patch is based on [deckhouse/deckhouse@91482468](https://raw.githubusercontent.com/deckhouse/deckhouse/91482468489526bc59623bd7fbd31228cd6a6b22/modules/402-ingress-nginx/images/controller-1-10/patches/nginx-tmpl.patch) sans the HTTP3 features.
8+
* [kubernetes/ingress-nginx#11843](./patches/11843.diff) ([source](https://github.com/kubernetes/ingress-nginx/pull/11843)).
9+
* A [backport](./patches/13068.diff) for [CVE-2025-1974](https://github.com/advisories/GHSA-mgvx-rpfc-9mpv) and friends ([source](https://github.com/kubernetes/ingress-nginx/pull/13068)). Parts of this patch are already included in [`etc/nginx/template/nginx.tmpl`](./etc/nginx/template/nginx.tmpl). Patches for test files are omitted.

images/controller/etc/nginx/template/nginx.tmpl

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# setup custom paths that do not require root access
1313
pid {{ .PID }};
1414

15+
# enables the use of “just-in-time compilation” for the regular expressions known by the time of configuration parsing
16+
pcre_jit on;
17+
1518
{{ if $cfg.UseGeoIP2 }}
1619
load_module /etc/nginx/modules/ngx_http_geoip2_module.so;
1720
{{ end }}
@@ -98,11 +101,11 @@ http {
98101
end
99102

100103
{{ if $all.EnableMetrics }}
101-
ok, res = pcall(require, "monitor")
104+
ok, res = pcall(require, "pbmetrics")
102105
if not ok then
103106
error("require failed: " .. tostring(res))
104107
else
105-
monitor = res
108+
pbmetrics = res
106109
end
107110
{{ end }}
108111

@@ -127,11 +130,9 @@ http {
127130
init_worker_by_lua_block {
128131
lua_ingress.init_worker()
129132
balancer.init_worker()
130-
{{ if $all.EnableMetrics }}
131-
monitor.init_worker({{ $all.MonitorMaxBatchSize }})
132-
{{ end }}
133133

134134
plugins.run()
135+
pbmetrics.init_worker()
135136
}
136137

137138
{{/* Enable the real_ip module only if we use either X-Forwarded headers or Proxy Protocol. */}}
@@ -415,6 +416,15 @@ http {
415416
{{ $reqUri }} 0;{{ end }}
416417
default 1;
417418
}
419+
map $server_name $total_upstream_response_time {
420+
default 0;
421+
}
422+
map $server_name $upstream_retries {
423+
default 0;
424+
}
425+
map $server_name $formatted_status {
426+
default $status;
427+
}
418428

419429
{{ if or $cfg.DisableAccessLog $cfg.DisableHTTPAccessLog }}
420430
access_log off;
@@ -955,14 +965,15 @@ stream {
955965
proxy_set_header Host $best_http_host;
956966

957967
set $proxy_upstream_name {{ $upstreamName | quote }};
968+
set $formatted_status $status;
969+
set $upstream_retries "0";
970+
set $total_upstream_response_time "0";
958971

959972
rewrite (.*) / break;
960973

961974
proxy_pass http://upstream_balancer;
962975
log_by_lua_block {
963-
{{ if $enableMetrics }}
964-
monitor.call()
965-
{{ end }}
976+
pbmetrics.call()
966977
}
967978
}
968979
{{ end }}
@@ -1010,10 +1021,13 @@ stream {
10101021
{{ buildHTTPSListener $all $server.Hostname }}
10111022

10121023
set $proxy_upstream_name "-";
1024+
set $formatted_status $status;
1025+
set $upstream_retries "0";
1026+
set $total_upstream_response_time "0";
10131027

10141028
{{ if not ( empty $server.CertificateAuth.MatchCN ) }}
10151029
{{ if gt (len $server.CertificateAuth.MatchCN) 0 }}
1016-
if ( $ssl_client_s_dn !~ {{ $server.CertificateAuth.MatchCN }} ) {
1030+
if ( $ssl_client_s_dn !~ {{ $server.CertificateAuth.MatchCN | quote }} ) {
10171031
return 403 "client certificate unauthorized";
10181032
}
10191033
{{ end }}
@@ -1172,6 +1186,10 @@ stream {
11721186
proxy_set_header X-Auth-Request-Redirect $request_uri;
11731187
{{ end }}
11741188

1189+
{{ if not (contains $externalAuth.AuthSnippet "proxy_connect_timeout") }}
1190+
proxy_connect_timeout 15s;
1191+
{{ end }}
1192+
11751193
{{ if $externalAuth.AuthCacheKey }}
11761194
proxy_buffering "on";
11771195
{{ else }}
@@ -1219,7 +1237,7 @@ stream {
12191237
set $target {{ changeHostPort $externalAuth.URL $authUpstreamName }};
12201238
{{ else }}
12211239
proxy_http_version {{ $location.Proxy.ProxyHTTPVersion }};
1222-
set $target {{ $externalAuth.URL }};
1240+
set $target {{ $externalAuth.URL | quote }};
12231241
{{ end }}
12241242
proxy_pass $target;
12251243
}
@@ -1255,10 +1273,12 @@ stream {
12551273
set $location_path {{ $ing.Path | escapeLiteralDollar | quote }};
12561274
set $global_rate_limit_exceeding n;
12571275

1276+
set $content_kind "";
1277+
12581278
{{ buildOpentelemetryForLocation $all.Cfg.EnableOpentelemetry $all.Cfg.OpentelemetryTrustIncomingSpan $location }}
12591279

12601280
{{ if $location.Mirror.Source }}
1261-
mirror {{ $location.Mirror.Source }};
1281+
mirror {{ $location.Mirror.Source | quote }};
12621282
mirror_request_body {{ $location.Mirror.RequestBody }};
12631283
{{ end }}
12641284

@@ -1285,11 +1305,9 @@ stream {
12851305

12861306
log_by_lua_block {
12871307
balancer.log()
1288-
{{ if $all.EnableMetrics }}
1289-
monitor.call()
1290-
{{ end }}
12911308

12921309
plugins.run()
1310+
pbmetrics.call()
12931311
}
12941312

12951313
{{ if not $location.Logs.Access }}
@@ -1577,14 +1595,15 @@ stream {
15771595

15781596
{{ if eq $server.Hostname "_" }}
15791597
# health checks in cloud providers require the use of port {{ $all.ListenPorts.HTTP }}
1580-
location {{ $all.HealthzURI }} {
1598+
location = {{ $all.HealthzURI }} {
15811599

15821600
{{ if $all.Cfg.EnableOpentelemetry }}
15831601
opentelemetry off;
15841602
{{ end }}
15851603

15861604
access_log off;
1587-
return 200;
1605+
proxy_set_header D8s-External-Check "True";
1606+
proxy_pass http://127.0.0.1:10254;
15881607
}
15891608

15901609
# this is required to avoid error if nginx is being monitored

images/controller/patches/13068-tmpl.diff

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

images/controller/patches/13068.diff

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,3 @@ index ed052e4ecf..0e03007433 100644
8989
}
9090

9191
return buffer.String()
92-
diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl
93-
index 6b8e750b06..0a87de5ee9 100644
94-
--- a/rootfs/etc/nginx/template/nginx.tmpl
95-
+++ b/rootfs/etc/nginx/template/nginx.tmpl
96-
@@ -879,7 +879,7 @@ stream {
97-
98-
{{ if not ( empty $server.CertificateAuth.MatchCN ) }}
99-
{{ if gt (len $server.CertificateAuth.MatchCN) 0 }}
100-
- if ( $ssl_client_s_dn !~ {{ $server.CertificateAuth.MatchCN }} ) {
101-
+ if ( $ssl_client_s_dn !~ {{ $server.CertificateAuth.MatchCN | quote }} ) {
102-
return 403 "client certificate unauthorized";
103-
}
104-
{{ end }}
105-
@@ -1082,7 +1082,7 @@ stream {
106-
set $target {{ changeHostPort $externalAuth.URL $authUpstreamName }};
107-
{{ else }}
108-
proxy_http_version {{ $location.Proxy.ProxyHTTPVersion }};
109-
- set $target {{ $externalAuth.URL }};
110-
+ set $target {{ $externalAuth.URL | quote }};
111-
{{ end }}
112-
proxy_pass $target;
113-
}
114-
@@ -1120,7 +1120,7 @@ stream {
115-
{{ buildOpentelemetryForLocation $all.Cfg.EnableOpentelemetry $all.Cfg.OpentelemetryTrustIncomingSpan $location }}
116-
117-
{{ if $location.Mirror.Source }}
118-
- mirror {{ $location.Mirror.Source }};
119-
+ mirror {{ $location.Mirror.Source | quote }};
120-
mirror_request_body {{ $location.Mirror.RequestBody }};
121-
{{ end }}
122-

images/controller/patches/nginx-tmpl.patch

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

0 commit comments

Comments
 (0)