Skip to content

Commit ee22e72

Browse files
feat: enhance error handling for app-proxy with CORS support in internal router configmap (#485)
* feat: enhance error handling for app-proxy with CORS support in internal router configmap * fix: index app-proxy Values * fix: index app-proxy Values * chore: app-proxy CORS headers for internal-router readme.md --------- Co-authored-by: Mikhail Klimko <[email protected]>
1 parent 24c217e commit ee22e72

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

charts/gitops-runtime/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ sealed-secrets:
187187
| app-proxy.config.argoWorkflowsInsecure | string | `"true"` | |
188188
| app-proxy.config.argoWorkflowsUrl | string | `nil` | Workflows server url. Determined by chart logic. Do not change unless you are certain you need to |
189189
| app-proxy.config.clusterChunkSize | int | `50` | define cluster list size per request to report the cluster state to platform, e.g. if you have 90 clusters and set clusterChunkSize: 40, it means cron job will report cluster state to platform in 3 iterations (40,40,10) - reduce this value if you have a lot of clusters and the cron job is failing with payload too large error - use 0 to sync all clusters at once |
190+
| app-proxy.config.cors | string | `"https://g.codefresh.io"` | Cors settings for app-proxy. This is the list of allowed domains for platform. |
190191
| app-proxy.config.env | string | `"production"` | |
191192
| app-proxy.config.logLevel | string | `"info"` | Log Level |
192193
| app-proxy.config.skipGitPermissionValidation | string | `"false"` | Skit git permissions validation |

charts/gitops-runtime/templates/_components/internal-router/_configmap.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,31 @@ data:
2727
proxy_set_header Connection "upgrade";
2828
chunked_transfer_encoding off;
2929
30+
error_page 502 = @app_proxy_init_error;
31+
3032
proxy_pass {{ index (get .Values.routing "app-proxy") "internalUrl" }};
3133
}
3234
35+
location @app_proxy_init_error {
36+
internal;
37+
38+
if ($request_method = OPTIONS) {
39+
add_header 'Access-Control-Allow-Origin' "{{ index .Values "app-proxy" "config" "cors" }}" always;
40+
add_header 'Access-Control-Allow-Methods' 'GET,HEAD,PUT,PATCH,POST,DELETE' always;
41+
add_header 'Access-Control-Allow-Headers' 'content-type,x-access-token' always;
42+
add_header 'Access-Control-Allow-Credentials' 'true' always;
43+
add_header 'Content-Length' 0;
44+
return 204;
45+
}
46+
47+
add_header 'Access-Control-Allow-Origin' "{{ index .Values "app-proxy" "config" "cors" }}" always;
48+
add_header 'Access-Control-Allow-Methods' 'GET,HEAD,PUT,PATCH,POST,DELETE' always;
49+
add_header 'Access-Control-Allow-Headers' 'content-type,x-access-token' always;
50+
add_header 'Access-Control-Allow-Credentials' 'true' always;
51+
return 502;
52+
53+
}
54+
3355
{{- if .Values.routing.workflows.enabled }}
3456
location /workflows/ {
3557
# sse

charts/gitops-runtime/templates/internal-router/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{- $internalRouterContext := deepCopy . }}
22
{{- $_ := set $internalRouterContext "Values" (deepCopy (get .Values "internal-router")) }}
3+
{{- $_ := set $internalRouterContext.Values "app-proxy" (deepCopy (get .Values "app-proxy")) }}
34
{{- $_ := set $internalRouterContext.Values "global" (deepCopy (get .Values "global")) }}
45
{{/*
56
Set workflows routing

charts/gitops-runtime/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ app-proxy:
591591
# - reduce this value if you have a lot of clusters and the cron job is failing with payload too large error
592592
# - use 0 to sync all clusters at once
593593
clusterChunkSize: 50
594+
# -- Cors settings for app-proxy. This is the list of allowed domains for platform.
595+
cors: "https://g.codefresh.io"
594596

595597
env: {}
596598

0 commit comments

Comments
 (0)