Skip to content

Commit 436d599

Browse files
authored
Merge pull request #3804 from yildizozan/fix-oidc-callback-url
backend: config: Add oidc-callback-url flag
2 parents 6f6f203 + 192eb4a commit 436d599

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

backend/cmd/headlamp.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type HeadlampConfig struct {
7373
oidcValidatorClientID string
7474
oidcClientSecret string
7575
oidcIdpIssuerURL string
76+
oidcCallbackURL string
7677
oidcValidatorIdpIssuerURL string
7778
oidcUseAccessToken bool
7879
cache cache.Cache[interface{}]
@@ -230,6 +231,12 @@ func baseURLReplace(staticDir string, baseURL string) {
230231
}
231232

232233
func getOidcCallbackURL(r *http.Request, config *HeadlampConfig) string {
234+
// If callback URL is configured, use it
235+
if config.oidcCallbackURL != "" {
236+
return config.oidcCallbackURL
237+
}
238+
239+
// Otherwise, generate callback URL dynamically
233240
urlScheme := r.URL.Scheme
234241
if urlScheme == "" {
235242
// check proxy headers first

backend/cmd/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func main() {
6767
oidcValidatorClientID: conf.OidcValidatorClientID,
6868
oidcClientSecret: conf.OidcClientSecret,
6969
oidcIdpIssuerURL: conf.OidcIdpIssuerURL,
70+
oidcCallbackURL: conf.OidcCallbackURL,
7071
oidcValidatorIdpIssuerURL: conf.OidcValidatorIdpIssuerURL,
7172
oidcScopes: strings.Split(conf.OidcScopes, ","),
7273
oidcUseAccessToken: conf.OidcUseAccessToken,

backend/pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Config struct {
3838
OidcValidatorClientID string `koanf:"oidc-validator-client-id"`
3939
OidcClientSecret string `koanf:"oidc-client-secret"`
4040
OidcIdpIssuerURL string `koanf:"oidc-idp-issuer-url"`
41+
OidcCallbackURL string `koanf:"oidc-callback-url"`
4142
OidcValidatorIdpIssuerURL string `koanf:"oidc-validator-idp-issuer-url"`
4243
OidcScopes string `koanf:"oidc-scopes"`
4344
OidcUseAccessToken bool `koanf:"oidc-use-access-token"`
@@ -256,6 +257,7 @@ func flagset() *flag.FlagSet {
256257
f.String("oidc-client-secret", "", "ClientSecret for OIDC")
257258
f.String("oidc-validator-client-id", "", "Override ClientID for OIDC during validation")
258259
f.String("oidc-idp-issuer-url", "", "Identity provider issuer URL for OIDC")
260+
f.String("oidc-callback-url", "", "Callback URL for OIDC")
259261
f.String("oidc-validator-idp-issuer-url", "", "Override Identity provider issuer URL for OIDC during validation")
260262
f.String("oidc-scopes", "profile,email",
261263
"A comma separated list of scopes needed from the OIDC provider")

charts/headlamp/templates/deployment.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{- $clientSecret := "" }}
66
{{- $issuerURL := "" }}
77
{{- $scopes := "" }}
8+
{{- $callbackURL := "" }}
89
{{- $validatorClientID := "" }}
910
{{- $validatorIssuerURL := "" }}
1011
{{- $useAccessToken := "" }}
@@ -24,6 +25,9 @@
2425
{{- if eq .name "OIDC_SCOPES" }}
2526
{{- $scopes = .value }}
2627
{{- end }}
28+
{{- if eq .name "OIDC_CALLBACK_URL" }}
29+
{{- $callbackURL = .value }}
30+
{{- end }}
2731
{{- if eq .name "OIDC_VALIDATOR_CLIENT_ID" }}
2832
{{- $validatorClientID = .value }}
2933
{{- end }}
@@ -118,6 +122,13 @@ spec:
118122
name: {{ $oidc.secret.name }}
119123
key: scopes
120124
{{- end }}
125+
{{- if $oidc.callbackURL }}
126+
- name: OIDC_CALLBACK_URL
127+
valueFrom:
128+
secretKeyRef:
129+
name: {{ $oidc.secret.name }}
130+
key: callbackURL
131+
{{- end }}
121132
{{- if $oidc.validatorClientID }}
122133
- name: OIDC_VALIDATOR_CLIENT_ID
123134
valueFrom:
@@ -156,6 +167,10 @@ spec:
156167
- name: OIDC_SCOPES
157168
value: {{ $oidc.scopes }}
158169
{{- end }}
170+
{{- if $oidc.callbackURL }}
171+
- name: OIDC_CALLBACK_URL
172+
value: {{ $oidc.callbackURL }}
173+
{{- end }}
159174
{{- if $oidc.validatorClientID }}
160175
- name: OIDC_VALIDATOR_CLIENT_ID
161176
value: {{ $oidc.validatorClientID }}
@@ -202,6 +217,10 @@ spec:
202217
# Check if scopes are non empty either from env or oidc.config
203218
- "-oidc-scopes=$(OIDC_SCOPES)"
204219
{{- end }}
220+
{{- if or (ne $oidc.callbackURL "") (ne $callbackURL "") }}
221+
# Check if callbackURL is non empty either from env or oidc.config
222+
- "-oidc-callback-url=$(OIDC_CALLBACK_URL)"
223+
{{- end }}
205224
{{- if or (ne $oidc.validatorClientID "") (ne $validatorClientID "") }}
206225
# Check if validatorClientID is non empty either from env or oidc.config
207226
- "-oidc-validator-client-id=$(OIDC_VALIDATOR_CLIENT_ID)"
@@ -219,6 +238,10 @@ spec:
219238
- "-oidc-client-secret=$(OIDC_CLIENT_SECRET)"
220239
- "-oidc-idp-issuer-url=$(OIDC_ISSUER_URL)"
221240
- "-oidc-scopes=$(OIDC_SCOPES)"
241+
{{- if or (ne $oidc.callbackURL "") (ne $callbackURL "") }}
242+
# Check if callbackURL is non empty either from env or oidc.config
243+
- "-oidc-callback-url=$(OIDC_CALLBACK_URL)"
244+
{{- end }}
222245
{{- if or (ne $oidc.validatorClientID "") (ne $validatorClientID "") }}
223246
# Check if validatorClientID is non empty either from env or oidc.config
224247
- "-oidc-validator-client-id=$(OIDC_VALIDATOR_CLIENT_ID)"

charts/headlamp/templates/secret.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ data:
1818
{{- with .scopes }}
1919
scopes: {{ . | b64enc | quote }}
2020
{{- end }}
21+
{{- with .callbackURL }}
22+
callbackURL: {{ . | b64enc | quote }}
23+
{{- end }}
2124
{{- with .validatorClientID }}
2225
validatorClientID: {{ . | b64enc | quote }}
2326
{{- end }}

charts/headlamp/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ config:
6666
issuerURL: ""
6767
# -- OIDC scopes to be used
6868
scopes: ""
69+
# -- OIDC callback URL
70+
callbackURL: ""
6971

7072
# -- OIDC client to be used during token validation
7173
validatorClientID: ""

0 commit comments

Comments
 (0)