Skip to content

Commit a4fac5c

Browse files
author
Ali Asghar
authored
config: guard against nil oauth2 credential in RoundTrip (#897)
* config: guard against nil oauth2 credential in RoundTrip toSecret returns (nil, nil) when no source is configured. Most callers guarded the returned SecretReader with an `!= nil` check before invoking Fetch, but oauth2RoundTripper.RoundTrip reached directly into rt.oauthCredential.Immutable() and would nil-deref panic when someone supplied an oauth2 block with no client-secret source (likely the proximate cause of prometheus/prometheus#16622). Return a clear error instead of panicking, and document toSecret's nil-return contract so future callers explicitly acknowledge it. Fixes #790 Signed-off-by: Ali <alliasgher123@gmail.com> * config: simplify comments per review feedback - toSecret: restore original one-line comment (no need to document nil-return semantics in the function comment) - oauth2RoundTripper.RoundTrip nil guard: replace verbose explanation with a single-line note matching reviewer's suggestion Signed-off-by: Ali <alliasgher123@gmail.com> --------- Signed-off-by: Ali <alliasgher123@gmail.com>
1 parent 9e28363 commit a4fac5c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

config/http_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,12 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
10631063
needsInit bool
10641064
)
10651065

1066+
// This should not happen when config goes through the normal Prometheus
1067+
// validation path, but guard against a nil credential to avoid a panic.
1068+
if rt.oauthCredential == nil {
1069+
return nil, errors.New("oauth2 client secret is required")
1070+
}
1071+
10661072
rt.mtx.RLock()
10671073
secret = rt.lastSecret
10681074
needsInit = rt.lastRT.Source == nil

0 commit comments

Comments
 (0)