Skip to content

Commit

Permalink
feat: add rw lock for provider access
Browse files Browse the repository at this point in the history
Signed-off-by: Cali0707 <[email protected]>
  • Loading branch information
Cali0707 committed Oct 5, 2024
1 parent 4bd5aef commit 057c69d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/auth/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"net/http"
"strings"
"sync"
"time"

"go.opencensus.io/plugin/ochttp"
Expand Down Expand Up @@ -52,9 +53,10 @@ import (
type Verifier struct {
logger *zap.SugaredLogger
restConfig *rest.Config
provider *oidc.Provider
eventPolicyLister v1alpha1.EventPolicyLister
trustBundleConfigMapLister corev1listers.ConfigMapNamespaceLister
m *sync.RWMutex
provider *oidc.Provider
}

type IDToken struct {
Expand Down Expand Up @@ -211,6 +213,9 @@ func (v *Verifier) verifyAuthZ(ctx context.Context, features feature.Flags, idTo

// verifyJWT verifies the given JWT for the expected audience and returns the parsed ID token.
func (v *Verifier) verifyJWT(ctx context.Context, jwt, audience string) (*IDToken, error) {
v.m.RLock()
defer v.m.RUnlock()

if v.provider == nil {
return nil, fmt.Errorf("provider is nil. Is the OIDC provider config correct?")
}
Expand Down Expand Up @@ -259,6 +264,8 @@ func (v *Verifier) initOIDCProvider(ctx context.Context, features feature.Flags)
}

// provider is valid, update it
v.m.Lock()
defer v.m.Unlock()
v.provider = provider

v.logger.Debug("updated OIDC provider config", zap.Any("discovery-config", discovery))
Expand Down

0 comments on commit 057c69d

Please sign in to comment.