From 453d27af4362a56f23caaad0300f7e5962507ce4 Mon Sep 17 00:00:00 2001 From: Serhii Ponomarenko <116438358+tiptophelmet@users.noreply.github.com> Date: Mon, 24 Mar 2025 23:23:41 +0200 Subject: [PATCH] :hammer: Create `tap.routing.front.basePath` flag (#1726) * :hammer: Add `tap.routing.front.basePath` helm value * :hammer: Use `tap.routing.front.basePath` to adjust nginx blocks * :hammer: Set `front` base path to empty string * :memo: Update `front` base path docs * :memo: Add `front` base path example * :memo: Add base-path to Kubeshark URL in instructions --------- Co-authored-by: Alon Girmonsky <1990761+alongir@users.noreply.github.com> --- config/configStructs/tapConfig.go | 9 ++++++++ helm-chart/README.md | 1 + helm-chart/templates/11-nginx-config-map.yaml | 23 +++++++++++++++---- helm-chart/templates/NOTES.txt | 4 ++-- helm-chart/values.yaml | 4 ++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/config/configStructs/tapConfig.go b/config/configStructs/tapConfig.go index 174a242d4..1be086b04 100644 --- a/config/configStructs/tapConfig.go +++ b/config/configStructs/tapConfig.go @@ -191,6 +191,14 @@ type IngressConfig struct { Annotations map[string]string `yaml:"annotations" json:"annotations" default:"{}"` } +type RoutingConfig struct { + Front FrontRoutingConfig `yaml:"front" json:"front"` +} + +type FrontRoutingConfig struct { + BasePath string `yaml:"basePath" json:"basePath" default:""` +} + type ReleaseConfig struct { Repo string `yaml:"repo" json:"repo" default:"https://helm.kubeshark.co"` Name string `yaml:"name" json:"name" default:"kubeshark"` @@ -309,6 +317,7 @@ type TapConfig struct { Tolerations TolerationsConfig `yaml:"tolerations" json:"tolerations" default:"{}"` Auth AuthConfig `yaml:"auth" json:"auth"` Ingress IngressConfig `yaml:"ingress" json:"ingress"` + Routing RoutingConfig `yaml:"routing" json:"routing"` IPv6 bool `yaml:"ipv6" json:"ipv6" default:"true"` Debug bool `yaml:"debug" json:"debug" default:"false"` Telemetry TelemetryConfig `yaml:"telemetry" json:"telemetry"` diff --git a/helm-chart/README.md b/helm-chart/README.md index f9a077419..c18b30137 100644 --- a/helm-chart/README.md +++ b/helm-chart/README.md @@ -196,6 +196,7 @@ Example for overriding image names: | `tap.ingress.host` | Host of the `Ingress` | `ks.svc.cluster.local` | | `tap.ingress.tls` | `Ingress` TLS configuration | `[]` | | `tap.ingress.annotations` | `Ingress` annotations | `{}` | +| `tap.routing.front.basePath` | Set this value to serve `front` under specific base path. Example: `/custompath` (forward slash must be present) | `""` | | `tap.ipv6` | Enable IPv6 support for the front-end | `true` | | `tap.debug` | Enable debug mode | `false` | | `tap.telemetry.enabled` | Enable anonymous usage statistics collection | `true` | diff --git a/helm-chart/templates/11-nginx-config-map.yaml b/helm-chart/templates/11-nginx-config-map.yaml index 70a5cecd5..86323c710 100644 --- a/helm-chart/templates/11-nginx-config-map.yaml +++ b/helm-chart/templates/11-nginx-config-map.yaml @@ -20,8 +20,8 @@ data: client_header_buffer_size 32k; large_client_header_buffers 8 64k; - location /api { - rewrite ^/api(.*)$ $1 break; + location {{ default "" (((.Values.tap).routing).front).basePath }}/api { + rewrite ^{{ default "" (((.Values.tap).routing).front).basePath }}/api(.*)$ $1 break; proxy_pass http://kubeshark-hub; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; @@ -35,8 +35,8 @@ data: proxy_pass_request_headers on; } - location /saml { - rewrite ^/saml(.*)$ /saml$1 break; + location {{ default "" (((.Values.tap).routing).front).basePath }}/saml { + rewrite ^{{ default "" (((.Values.tap).routing).front).basePath }}/saml(.*)$ /saml$1 break; proxy_pass http://kubeshark-hub; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; @@ -45,9 +45,10 @@ data: proxy_send_timeout 12s; proxy_pass_request_headers on; } + {{- if .Values.tap.auth.dexConfig }} location /dex { - rewrite ^/dex(.*)$ /dex$1 break; + rewrite ^{{ default "" (((.Values.tap).routing).front).basePath }}/dex(.*)$ /dex$1 break; proxy_pass http://kubeshark-dex; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; @@ -61,6 +62,18 @@ data: proxy_pass_request_headers on; } {{- end }} + +{{- if (((.Values.tap).routing).front).basePath }} + location {{ .Values.tap.routing.front.basePath }} { + rewrite ^{{ .Values.tap.routing.front.basePath }}(.*)$ $1 break; + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + expires -1; + add_header Cache-Control no-cache; + } +{{- end }} + location / { root /usr/share/nginx/html; index index.html index.htm; diff --git a/helm-chart/templates/NOTES.txt b/helm-chart/templates/NOTES.txt index 8b91df42d..b1a6a1d72 100644 --- a/helm-chart/templates/NOTES.txt +++ b/helm-chart/templates/NOTES.txt @@ -34,7 +34,7 @@ Notices: {{ if .Values.tap.ingress.enabled }} You can now access the application through the following URL: -http{{ if .Values.tap.ingress.tls }}s{{ end }}://{{ .Values.tap.ingress.host }} +http{{ if .Values.tap.ingress.tls }}s{{ end }}://{{ .Values.tap.ingress.host }}{{ default "" (((.Values.tap).routing).front).basePath }}/ {{- else }} To access the application, follow these steps: @@ -44,6 +44,6 @@ To access the application, follow these steps: kubectl port-forward -n {{ .Release.Namespace }} service/kubeshark-front 8899:80 2. Once port forwarding is done, you can access the application by visiting the following URL in your web browser: - http://0.0.0.0:8899 + http://0.0.0.0:8899{{ default "" (((.Values.tap).routing).front).basePath }}/ {{- end }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index b36b610b9..08d4024ed 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -137,6 +137,10 @@ tap: host: ks.svc.cluster.local tls: [] annotations: {} + routing: + front: + # Example: /custompath + basePath: "" ipv6: true debug: false telemetry: