Skip to content

Refactor nginx config in prod #7417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/konflux-ui/production/base/proxy/auth.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Auth configuration with impersonation enabled
auth_request_set $user $upstream_http_x_auth_request_email;
proxy_set_header Impersonate-User $user;
proxy_set_header Impersonate-Group system:authenticated;
proxy_set_header Authorization "Bearer __BEARER_TOKEN__";
7 changes: 7 additions & 0 deletions components/konflux-ui/production/base/proxy/kubearchive.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
location /api/k8s/plugins/kubearchive/ {
auth_request /oauth2/auth;
rewrite /api/k8s/plugins/kubearchive/(.+) /$1 break;
proxy_read_timeout 30m;
proxy_pass https://kubearchive-api-server.product-kubearchive.svc.cluster.local:8081;
include /mnt/nginx-generated-config/auth.conf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ configMapGenerator:
- name: proxy
files:
- nginx.conf
- name: proxy-nginx-templates
files:
- auth.conf
- name: proxy-nginx-static
files:
- tekton-results.conf
- tekton-results-workspaces.conf
- kubearchive.conf
18 changes: 0 additions & 18 deletions components/konflux-ui/production/base/proxy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,7 @@ http {
include /mnt/nginx-generated-config/auth.conf;
}

# Deprecated
location /api/k8s/plugins/tekton-results/workspaces/ {
auth_request /oauth2/auth;

rewrite /api/k8s/plugins/tekton-results/workspaces/.+?/(.+) /$1 break;
proxy_read_timeout 30m;
include /mnt/nginx-generated-config/tekton-results.conf;
include /mnt/nginx-generated-config/auth.conf;
}

location /api/k8s/plugins/tekton-results/ {
auth_request /oauth2/auth;

rewrite /api/k8s/plugins/tekton-results/(.+) /$1 break;
proxy_read_timeout 30m;
include /mnt/nginx-generated-config/tekton-results.conf;
include /mnt/nginx-generated-config/auth.conf;
}

# GET requests to /api/k8s/api/v1/namespaces and /api/k8s/api/v1/namespaces/
# are handled from the namespace-lister.
Expand Down Expand Up @@ -200,6 +183,5 @@ http {
}

include /mnt/nginx-additional-location-configs/*.conf;
include /mnt/nginx-generated-config/kubearchive.conf;
}
}
47 changes: 16 additions & 31 deletions components/konflux-ui/production/base/proxy/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,23 @@ spec:
memory: 64Mi
- name: generate-nginx-configs
image: registry.access.redhat.com/ubi9/ubi@sha256:66233eebd72bb5baa25190d4f55e1dc3fff3a9b77186c1f91a0abdb274452072
envFrom:
- configMapRef:
name: proxy-init-config
command:
- sh
- -c
- |
set -e

auth_conf=/mnt/nginx-generated-config/auth.conf

if [[ "$IMPERSONATE" == "true" ]]; then
token=$(cat /mnt/api-token/token)
echo 'auth_request_set $user $upstream_http_x_auth_request_email;' > "$auth_conf"
echo 'proxy_set_header Impersonate-User $user;' >> "$auth_conf"
echo 'proxy_set_header Impersonate-Group system:authenticated;' >> "$auth_conf"
echo "proxy_set_header Authorization \"Bearer $token\";" >> "$auth_conf"
else
echo "# impersonation was disabled by config" > "$auth_conf"
fi
# Generate auth.conf with bearer token replacement
token=$(cat /mnt/api-token/token)
sed "s/__BEARER_TOKEN__/$token/g" /mnt/nginx-templates/auth.conf > /mnt/nginx-generated-config/auth.conf

chmod 640 "$auth_conf"

echo \
"proxy_pass ${TEKTON_RESULTS_URL:?tekton results url must be provided};" \
> /mnt/nginx-generated-config/tekton-results.conf

if [[ "$KUBEARCHIVE_URL" != "" ]]; then
echo "location /api/k8s/plugins/kubearchive/ {" > /mnt/nginx-generated-config/kubearchive.conf
echo "auth_request /oauth2/auth;" >> /mnt/nginx-generated-config/kubearchive.conf
echo "rewrite /api/k8s/plugins/kubearchive/(.+) /\$1 break;" >> /mnt/nginx-generated-config/kubearchive.conf
echo "proxy_read_timeout 30m;" >> /mnt/nginx-generated-config/kubearchive.conf
echo "proxy_pass ${KUBEARCHIVE_URL};" >> /mnt/nginx-generated-config/kubearchive.conf
echo "include /mnt/nginx-generated-config/auth.conf;" >> /mnt/nginx-generated-config/kubearchive.conf
echo "}" >> /mnt/nginx-generated-config/kubearchive.conf
else
echo "# KubeArchive disabled by config" > /mnt/nginx-generated-config/kubearchive.conf
fi
chmod 640 /mnt/nginx-generated-config/auth.conf

volumeMounts:
- name: nginx-generated-config
mountPath: /mnt/nginx-generated-config
- name: nginx-templates
mountPath: /mnt/nginx-templates
- name: api-token
mountPath: /mnt/api-token
securityContext:
Expand Down Expand Up @@ -167,6 +142,8 @@ spec:
mountPath: /mnt
- name: nginx-generated-config
mountPath: /mnt/nginx-generated-config
- name: nginx-static
mountPath: /mnt/nginx-additional-location-configs
- name: static-content
mountPath: /opt/app-root/src/static-content
securityContext:
Expand Down Expand Up @@ -228,6 +205,14 @@ spec:
- key: nginx.conf
path: nginx.conf
name: proxy
- configMap:
defaultMode: 420
name: proxy-nginx-templates
name: nginx-templates
- configMap:
defaultMode: 420
name: proxy-nginx-static
name: nginx-static
- name: logs
emptyDir: {}
- name: nginx-tmp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Deprecated
location /api/k8s/plugins/tekton-results/workspaces/ {
auth_request /oauth2/auth;

rewrite /api/k8s/plugins/tekton-results/workspaces/.+?/(.+) /$1 break;
proxy_read_timeout 30m;
include /mnt/nginx-generated-config/tekton-results.conf;
include /mnt/nginx-generated-config/auth.conf;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
location /api/k8s/plugins/tekton-results/ {
auth_request /oauth2/auth;

rewrite /api/k8s/plugins/tekton-results/(.+) /$1 break;
proxy_read_timeout 30m;
proxy_pass https://tekton-results-api-service.tekton-results.svc.cluster.local:8080;
include /mnt/nginx-generated-config/auth.conf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- KUBEARCHIVE_URL=https://kubearchive-api-server.product-kubearchive.svc.cluster.local:8081

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- name: proxy-nginx-static
files:
- kubearchive.conf
behavior: merge

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# KubeArchive disabled by config
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- name: proxy-nginx-static
files:
- kubearchive.conf
behavior: merge

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- KUBEARCHIVE_URL=https://kubearchive-api-server.product-kubearchive.svc.cluster.local:8081

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- KUBEARCHIVE_URL=https://kubearchive-api-server.product-kubearchive.svc.cluster.local:8081

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# KubeArchive disabled by config
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- name: proxy-nginx-static
files:
- kubearchive.conf
behavior: merge

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-init-config
literals:
- IMPERSONATE=true
- TEKTON_RESULTS_URL=https://tekton-results-api-service.tekton-results.svc.cluster.local:8080
- KUBEARCHIVE_URL=https://kubearchive-api-server.product-kubearchive.svc.cluster.local:8081

patches:
- path: add-service-certs-patch.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ configMapGenerator:
- name: dex
files:
- dex-config.yaml
- name: proxy-nginx-static
files:
- kubearchive.conf
behavior: merge

patches:
- path: add-service-certs-patch.yaml
Expand Down