|
@@ -87,14 +87,18 @@ func (auth *OidcAuthProvider) SetNewWorkConn(newWorkConnMsg *msg.NewWorkConn) (e
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+type TokenVerifier interface {
|
|
|
+ Verify(context.Context, string) (*oidc.IDToken, error)
|
|
|
+}
|
|
|
+
|
|
|
type OidcAuthConsumer struct {
|
|
|
additionalAuthScopes []v1.AuthScope
|
|
|
|
|
|
- verifier *oidc.IDTokenVerifier
|
|
|
- subjectFromLogin string
|
|
|
+ verifier TokenVerifier
|
|
|
+ subjectsFromLogin []string
|
|
|
}
|
|
|
|
|
|
-func NewOidcAuthVerifier(additionalAuthScopes []v1.AuthScope, cfg v1.AuthOIDCServerConfig) *OidcAuthConsumer {
|
|
|
+func NewTokenVerifier(cfg v1.AuthOIDCServerConfig) TokenVerifier {
|
|
|
provider, err := oidc.NewProvider(context.Background(), cfg.Issuer)
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
@@ -105,9 +109,14 @@ func NewOidcAuthVerifier(additionalAuthScopes []v1.AuthScope, cfg v1.AuthOIDCSer
|
|
|
SkipExpiryCheck: cfg.SkipExpiryCheck,
|
|
|
SkipIssuerCheck: cfg.SkipIssuerCheck,
|
|
|
}
|
|
|
+ return provider.Verifier(&verifierConf)
|
|
|
+}
|
|
|
+
|
|
|
+func NewOidcAuthVerifier(additionalAuthScopes []v1.AuthScope, verifier TokenVerifier) *OidcAuthConsumer {
|
|
|
return &OidcAuthConsumer{
|
|
|
additionalAuthScopes: additionalAuthScopes,
|
|
|
- verifier: provider.Verifier(&verifierConf),
|
|
|
+ verifier: verifier,
|
|
|
+ subjectsFromLogin: []string{},
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -116,7 +125,9 @@ func (auth *OidcAuthConsumer) VerifyLogin(loginMsg *msg.Login) (err error) {
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("invalid OIDC token in login: %v", err)
|
|
|
}
|
|
|
- auth.subjectFromLogin = token.Subject
|
|
|
+ if !slices.Contains(auth.subjectsFromLogin, token.Subject) {
|
|
|
+ auth.subjectsFromLogin = append(auth.subjectsFromLogin, token.Subject)
|
|
|
+ }
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -125,11 +136,11 @@ func (auth *OidcAuthConsumer) verifyPostLoginToken(privilegeKey string) (err err
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("invalid OIDC token in ping: %v", err)
|
|
|
}
|
|
|
- if token.Subject != auth.subjectFromLogin {
|
|
|
+ if !slices.Contains(auth.subjectsFromLogin, token.Subject) {
|
|
|
return fmt.Errorf("received different OIDC subject in login and ping. "+
|
|
|
- "original subject: %s, "+
|
|
|
+ "original subjects: %s, "+
|
|
|
"new subject: %s",
|
|
|
- auth.subjectFromLogin, token.Subject)
|
|
|
+ auth.subjectsFromLogin, token.Subject)
|
|
|
}
|
|
|
return nil
|
|
|
}
|