-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Add ingress for grafana report #121
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,136 @@ | ||||||||||
| {{- $basehref := .Values.backend.config.basehref | default "" -}} | ||||||||||
| {{- $grafana_enabled := false -}} | ||||||||||
| {{- if .Values.global }} | ||||||||||
| {{- if .Values.global.grafana }} | ||||||||||
| {{- $grafana_enabled = .Values.global.grafana.enabled }} | ||||||||||
| {{- end }} | ||||||||||
| {{- end }} | ||||||||||
|
|
||||||||||
|
|
||||||||||
| {{- if $grafana_enabled }} | ||||||||||
|
|
||||||||||
| apiVersion: networking.k8s.io/v1 | ||||||||||
| kind: Ingress | ||||||||||
| metadata: | ||||||||||
| annotations: | ||||||||||
| nginx.ingress.kubernetes.io/affinity: cookie | ||||||||||
| nginx.ingress.kubernetes.io/configuration-snippet: | | ||||||||||
| if ($arg_user) { | ||||||||||
| set $user $arg_user; | ||||||||||
| } | ||||||||||
| if ($arg_hostgroup) { | ||||||||||
| set $hostgroup $arg_hostgroup; | ||||||||||
| } | ||||||||||
| if ($arg_orgId) { | ||||||||||
| set $orgId $arg_orgId; | ||||||||||
| } | ||||||||||
| if ($arg_report) { | ||||||||||
| set $report $arg_report; | ||||||||||
| } | ||||||||||
| if ($user = "") { | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| if ($hostgroup = "") { | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| if ($orgId = "") { | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| if ($report = "") { | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| if ($http_referer ~ "^https://(.*)/grafana/d/(.*)orgId=([0-9]+)(.*)") { | ||||||||||
| set $referer_orgId $3; | ||||||||||
| set $cookie_valid 1; | ||||||||||
| } | ||||||||||
| if ($referer_orgId != $orgId) { | ||||||||||
| set $cookie_valid 0; | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| if ($cookie_valid = 1) { | ||||||||||
| add_header Set-Cookie "ref_grafana_path=$http_referer; Path=/; HttpOnly; Secure; Samesite=Lax; Max-Age=86400"; | ||||||||||
| add_header Set-Cookie "ref_grafana_user=$user; Path=/; HttpOnly; Secure; Samesite=Lax; Max-Age=86400"; | ||||||||||
| add_header Set-Cookie "ref_grafana_hostgroup=$hostgroup; Path=/; HttpOnly; Secure; Samesite=Lax; Max-Age=86400"; | ||||||||||
| add_header Set-Cookie "ref_grafana_orgId=$orgId; Path=/; HttpOnly; Secure; Samesite=Lax; Max-Age=86400"; | ||||||||||
| add_header Set-Cookie "ref_grafana_report=$report; Path=/; HttpOnly; Secure; Samesite=Lax; Max-Age=86400"; | ||||||||||
| #ref_grafana_session already set from grafana ingress | ||||||||||
| set $redirect_url "$scheme://$host{{ $basehref }}/report/grafana/$report/"; | ||||||||||
|
|
||||||||||
| return 302 $redirect_url; | ||||||||||
| } | ||||||||||
| nginx.ingress.kubernetes.io/force-ssl-redirect: "true" | ||||||||||
| name: grafana-redirect-report-ingress | ||||||||||
| spec: | ||||||||||
| ingressClassName: {{ .Release.Name }} | ||||||||||
| rules: | ||||||||||
| - http: | ||||||||||
| paths: | ||||||||||
| - backend: | ||||||||||
| service: | ||||||||||
| name: {{ .Chart.Name }}-frontend | ||||||||||
| port: | ||||||||||
| number: {{ .Values.frontend.service.port }} | ||||||||||
| path: "{{ $basehref }}/grafana-redirect-report-nmaa(/|$)(.*)" | ||||||||||
| pathType: Prefix | ||||||||||
|
Comment on lines
+61
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing The path
Without these changes, NGINX won't interpret the regex and the path matching will fail. 🐛 Proposed fix nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
+ nginx.ingress.kubernetes.io/use-regex: "true"
name: grafana-redirect-report-ingress
spec:
ingressClassName: {{ .Release.Name }}
rules:
- http:
paths:
- backend:
service:
name: {{ .Chart.Name }}-frontend
port:
number: {{ .Values.frontend.service.port }}
path: "{{ $basehref }}/grafana-redirect-report-nmaa(/|$)(.*)"
- pathType: Prefix
+ pathType: ImplementationSpecific🧰 Tools🪛 YAMLlint (1.38.0)[error] 64-64: too many spaces inside braces (braces) [error] 64-64: too many spaces inside braces (braces) [error] 70-70: too many spaces inside braces (braces) [error] 70-70: too many spaces inside braces (braces) [error] 72-72: too many spaces inside braces (braces) [error] 72-72: too many spaces inside braces (braces) 🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| --- | ||||||||||
| apiVersion: networking.k8s.io/v1 | ||||||||||
| kind: Ingress | ||||||||||
| metadata: | ||||||||||
| annotations: | ||||||||||
| nginx.ingress.kubernetes.io/affinity: cookie | ||||||||||
| nginx.ingress.kubernetes.io/configuration-snippet: | | ||||||||||
| proxy_set_header X-GRAFANA-USER "$cookie_ref_grafana_user"; | ||||||||||
| proxy_set_header X-GRAFANA-HOSTGROUP "$cookie_ref_grafana_hostgroup"; | ||||||||||
| proxy_set_header X-GRAFANA-ORGID "$cookie_ref_grafana_orgId"; | ||||||||||
| if ($cookie_ref_grafana_session = "") { | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| nginx.ingress.kubernetes.io/force-ssl-redirect: "true" | ||||||||||
| nginx.ingress.kubernetes.io/rewrite-target: /$1$2 | ||||||||||
| nginx.ingress.kubernetes.io/use-regex: "true" | ||||||||||
| name: report-be-grafana-ingress | ||||||||||
| spec: | ||||||||||
| ingressClassName: {{ .Release.Name }} | ||||||||||
| rules: | ||||||||||
| - http: | ||||||||||
| paths: | ||||||||||
| - backend: | ||||||||||
| service: | ||||||||||
| name: {{ .Chart.Name }}-backend | ||||||||||
| port: | ||||||||||
| number: {{ .Values.backend.service.port }} | ||||||||||
| path: "{{ $basehref }}/(_event|ping|_upload)(/.*)?$" | ||||||||||
| pathType: ImplementationSpecific | ||||||||||
|
|
||||||||||
| --- | ||||||||||
| apiVersion: networking.k8s.io/v1 | ||||||||||
| kind: Ingress | ||||||||||
| metadata: | ||||||||||
| annotations: | ||||||||||
| nginx.ingress.kubernetes.io/affinity: cookie | ||||||||||
| nginx.ingress.kubernetes.io/configuration-snippet: | | ||||||||||
| proxy_set_header X-GRAFANA-USER "$cookie_ref_grafana_user"; | ||||||||||
| proxy_set_header X-GRAFANA-HOSTGROUP "$cookie_ref_grafana_hostgroup"; | ||||||||||
| proxy_set_header X-GRAFANA-ORGID "$cookie_ref_grafana_orgId"; | ||||||||||
| if ($cookie_ref_grafana_session = "") { | ||||||||||
| return 401; | ||||||||||
| } | ||||||||||
| nginx.ingress.kubernetes.io/force-ssl-redirect: "true" | ||||||||||
| nginx.ingress.kubernetes.io/session-cookie-path: "{{ $basehref }}/report/grafana/" | ||||||||||
| nginx.ingress.kubernetes.io/use-regex: "true" | ||||||||||
| name: report-fe-grafana-ingress | ||||||||||
| spec: | ||||||||||
| ingressClassName: {{ .Release.Name }} | ||||||||||
| rules: | ||||||||||
| - http: | ||||||||||
| paths: | ||||||||||
| - backend: | ||||||||||
| service: | ||||||||||
| name: {{ .Chart.Name }}-frontend | ||||||||||
| port: | ||||||||||
| number: {{ .Values.frontend.service.port }} | ||||||||||
| path: "{{ $basehref }}/report/grafana/(.*)" | ||||||||||
| pathType: Prefix | ||||||||||
|
Comment on lines
+133
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect The path contains a regex capture group 🔧 Proposed fix path: "{{ $basehref }}/report/grafana/(.*)"
- pathType: Prefix
+ pathType: ImplementationSpecific📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| {{- end }} | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filename typo:
refelxshould bereflex.The file is named
refelx-grafana-ingress.yamlbut based on the naming convention of other files in this directory (reflex-backend-svc.yaml,reflex-frontend-svc.yaml), it should bereflex-grafana-ingress.yaml.🧰 Tools
🪛 YAMLlint (1.38.0)
[error] 1-1: syntax error: expected the node content, but found '-'
(syntax)
🤖 Prompt for AI Agents