Skip to content

Commit b480eaf

Browse files
committed
fix(auth): tolerate string booleans in oidc provider config (#2599)
The four boolean OIDC provider fields (emailfallback, usernamefallback, forceuserinfo, requireavailability) were parsed with a strict .(bool) type assertion. That works for YAML/JSON config where leaves are native bools, but fails for every other input path: env vars always arrive as strings, and GetConfigValueFromFile (used by the *.file Docker secret convention) also always returns strings. The assertion would silently zero the field for emailfallback and usernamefallback, and log an error and zero the field for forceuserinfo and requireavailability, which is what #2599 reports. Extract a small parseBoolField helper that accepts both native bools and strings (via strconv.ParseBool) and logs a parse error from each call site. This also fixes the previously-silent drop of stringified emailfallback / usernamefallback values — those now log an error if the input is garbage, matching the behaviour of the other two fields. Fixes #2599
1 parent 11e9d2e commit b480eaf

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

pkg/modules/auth/openid/providers.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,28 @@ func GetProvider(key string) (provider *Provider, err error) {
180180
return
181181
}
182182

183+
// parseBoolField reads a boolean-valued config field from a provider map,
184+
// tolerating both native bools (from YAML/JSON) and strings (from env vars or
185+
// the GetConfigValueFromFile path, which always return strings). Missing or
186+
// empty values default to false with no error.
187+
func parseBoolField(pi map[string]interface{}, key string) (val bool, err error) {
188+
raw, exists := pi[key]
189+
if !exists {
190+
return false, nil
191+
}
192+
switch v := raw.(type) {
193+
case bool:
194+
return v, nil
195+
case string:
196+
if v == "" {
197+
return false, nil
198+
}
199+
return strconv.ParseBool(v)
200+
default:
201+
return false, fmt.Errorf("expected bool, got %T", raw)
202+
}
203+
}
204+
183205
func getProviderFromMap(pi map[string]interface{}, key string) (provider *Provider, err error) {
184206

185207
requiredKeys := []string{
@@ -236,43 +258,21 @@ func getProviderFromMap(pi map[string]interface{}, key string) (provider *Provid
236258
scope = "openid profile email"
237259
}
238260

239-
var emailFallback = false
240-
emailFallbackValue, exists := pi["emailfallback"]
241-
if exists {
242-
emailFallbackTypedValue, ok := emailFallbackValue.(bool)
243-
if ok {
244-
emailFallback = emailFallbackTypedValue
245-
}
261+
emailFallback, err := parseBoolField(pi, "emailfallback")
262+
if err != nil {
263+
log.Errorf("emailfallback is not a boolean for provider %s: %s", key, err)
246264
}
247-
var usernameFallback = false
248-
usernameFallbackValue, exists := pi["usernamefallback"]
249-
if exists {
250-
usernameFallbackTypedValue, ok := usernameFallbackValue.(bool)
251-
if ok {
252-
usernameFallback = usernameFallbackTypedValue
253-
}
265+
usernameFallback, err := parseBoolField(pi, "usernamefallback")
266+
if err != nil {
267+
log.Errorf("usernamefallback is not a boolean for provider %s: %s", key, err)
254268
}
255-
256-
var forceUserInfo = false
257-
forceUserInfoValue, exists := pi["forceuserinfo"]
258-
if exists {
259-
forceUserInfoTypedValue, ok := forceUserInfoValue.(bool)
260-
if ok {
261-
forceUserInfo = forceUserInfoTypedValue
262-
} else {
263-
log.Errorf("forceuserinfo is not a boolean for provider %s, value: %v", key, forceUserInfoValue)
264-
}
269+
forceUserInfo, err := parseBoolField(pi, "forceuserinfo")
270+
if err != nil {
271+
log.Errorf("forceuserinfo is not a boolean for provider %s: %s", key, err)
265272
}
266-
267-
var requireAvailability = false
268-
requireAvailabilityValue, exists := pi["requireavailability"]
269-
if exists {
270-
requireAvailabilityTypedValue, ok := requireAvailabilityValue.(bool)
271-
if ok {
272-
requireAvailability = requireAvailabilityTypedValue
273-
} else {
274-
log.Errorf("requireavailability is not a boolean for provider %s, value: %v", key, requireAvailabilityValue)
275-
}
273+
requireAvailability, err := parseBoolField(pi, "requireavailability")
274+
if err != nil {
275+
log.Errorf("requireavailability is not a boolean for provider %s: %s", key, err)
276276
}
277277

278278
provider = &Provider{

0 commit comments

Comments
 (0)