Bound OIDC discovery with a client timeout and failure backoff
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-14 22:27:20 +11:00
parent 638931d7ed
commit 51a77e3446
3 changed files with 167 additions and 27 deletions
+13 -8
View File
@@ -45,6 +45,18 @@ func NewOIDCIssuer() *OIDCIssuer {
// Token signs a token for aud and sub. Pass a nil key to use the issuer's own;
// expiry is relative to now.
func (o *OIDCIssuer) Token(key *rsa.PrivateKey, aud, sub string, expiry time.Duration) string {
now := time.Now()
return o.Sign(key, jwt.Claims{
Issuer: o.URL,
Subject: sub,
Audience: jwt.Audience{aud},
IssuedAt: jwt.NewNumericDate(now.Add(-time.Minute)),
Expiry: jwt.NewNumericDate(now.Add(expiry)),
})
}
// Sign signs arbitrary claims with RS256. Pass a nil key to use the issuer's own.
func (o *OIDCIssuer) Sign(key *rsa.PrivateKey, claims jwt.Claims) string {
if key == nil {
key = o.key
}
@@ -53,14 +65,7 @@ func (o *OIDCIssuer) Token(key *rsa.PrivateKey, aud, sub string, expiry time.Dur
if err != nil {
panic(err)
}
now := time.Now()
tok, err := jwt.Signed(sig).Claims(jwt.Claims{
Issuer: o.URL,
Subject: sub,
Audience: jwt.Audience{aud},
IssuedAt: jwt.NewNumericDate(now.Add(-time.Minute)),
Expiry: jwt.NewNumericDate(now.Add(expiry)),
}).Serialize()
tok, err := jwt.Signed(sig).Claims(claims).Serialize()
if err != nil {
panic(err)
}