2022-03-08 20:28:09 +00:00
|
|
|
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
2020-10-14 13:47:34 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package supervisorconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-10-15 15:33:08 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
2020-10-14 13:47:34 +00:00
|
|
|
"crypto/rand"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-10-14 20:41:16 +00:00
|
|
|
"io"
|
2020-10-14 13:47:34 +00:00
|
|
|
|
|
|
|
"gopkg.in/square/go-jose.v2"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
corev1informers "k8s.io/client-go/informers/core/v1"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/client-go/util/retry"
|
|
|
|
"k8s.io/klog/v2"
|
|
|
|
|
2021-02-16 19:00:08 +00:00
|
|
|
configv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/config/v1alpha1"
|
|
|
|
pinnipedclientset "go.pinniped.dev/generated/latest/client/supervisor/clientset/versioned"
|
|
|
|
configinformers "go.pinniped.dev/generated/latest/client/supervisor/informers/externalversions/config/v1alpha1"
|
2020-10-14 13:47:34 +00:00
|
|
|
pinnipedcontroller "go.pinniped.dev/internal/controller"
|
2020-12-18 22:55:05 +00:00
|
|
|
"go.pinniped.dev/internal/controller/supervisorconfig/generator"
|
2020-10-14 13:47:34 +00:00
|
|
|
"go.pinniped.dev/internal/controllerlib"
|
2020-11-10 15:22:16 +00:00
|
|
|
"go.pinniped.dev/internal/plog"
|
2020-10-14 13:47:34 +00:00
|
|
|
)
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
// These constants are the keys in a FederationDomain's Secret's Data map.
|
2020-10-14 13:47:34 +00:00
|
|
|
const (
|
|
|
|
// activeJWKKey points to the current private key used for signing tokens.
|
|
|
|
//
|
|
|
|
// Note! The value for this key will contain private key material!
|
|
|
|
activeJWKKey = "activeJWK"
|
2020-10-14 20:41:16 +00:00
|
|
|
// jwksKey points to the current JWKS used to verify tokens.
|
2020-10-14 13:47:34 +00:00
|
|
|
//
|
|
|
|
// Note! The value for this key will contain only public key material!
|
2020-10-14 20:41:16 +00:00
|
|
|
jwksKey = "jwks"
|
2020-12-17 22:48:49 +00:00
|
|
|
|
2020-12-17 23:43:20 +00:00
|
|
|
jwksSecretTypeValue corev1.SecretType = "secrets.pinniped.dev/federation-domain-jwks"
|
2020-10-14 13:47:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-12-17 19:34:49 +00:00
|
|
|
federationDomainKind = "FederationDomain"
|
2020-10-14 13:47:34 +00:00
|
|
|
)
|
|
|
|
|
2020-10-15 15:33:08 +00:00
|
|
|
// generateKey is stubbed out for the purpose of testing. The default behavior is to generate an EC key.
|
2022-08-24 21:45:55 +00:00
|
|
|
var generateKey = generateECKey //nolint:gochecknoglobals
|
2020-10-14 20:41:16 +00:00
|
|
|
|
2020-10-15 15:33:08 +00:00
|
|
|
func generateECKey(r io.Reader) (interface{}, error) {
|
|
|
|
return ecdsa.GenerateKey(elliptic.P256(), r)
|
2020-10-14 20:41:16 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
// jwkController holds the fields necessary for the JWKS controller to communicate with FederationDomains and
|
2020-10-14 13:47:34 +00:00
|
|
|
// secrets, both via a cache and via the API.
|
2020-10-17 00:51:40 +00:00
|
|
|
type jwksWriterController struct {
|
2020-12-17 19:34:49 +00:00
|
|
|
jwksSecretLabels map[string]string
|
|
|
|
pinnipedClient pinnipedclientset.Interface
|
|
|
|
kubeClient kubernetes.Interface
|
|
|
|
federationDomainInformer configinformers.FederationDomainInformer
|
|
|
|
secretInformer corev1informers.SecretInformer
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
// NewJWKSWriterController returns a controllerlib.Controller that ensures a FederationDomain has a corresponding
|
2020-10-14 13:47:34 +00:00
|
|
|
// Secret that contains a valid active JWK and JWKS.
|
2020-10-17 00:51:40 +00:00
|
|
|
func NewJWKSWriterController(
|
2020-10-15 19:40:56 +00:00
|
|
|
jwksSecretLabels map[string]string,
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeClient kubernetes.Interface,
|
|
|
|
pinnipedClient pinnipedclientset.Interface,
|
|
|
|
secretInformer corev1informers.SecretInformer,
|
2020-12-17 19:34:49 +00:00
|
|
|
federationDomainInformer configinformers.FederationDomainInformer,
|
2020-10-14 13:47:34 +00:00
|
|
|
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
|
|
|
) controllerlib.Controller {
|
2020-12-18 22:55:05 +00:00
|
|
|
isSecretToSync := func(obj metav1.Object) bool {
|
|
|
|
return generator.IsFederationDomainSecretOfType(obj, jwksSecretTypeValue)
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:47:34 +00:00
|
|
|
return controllerlib.New(
|
|
|
|
controllerlib.Config{
|
|
|
|
Name: "JWKSController",
|
2020-10-17 00:51:40 +00:00
|
|
|
Syncer: &jwksWriterController{
|
2020-12-17 19:34:49 +00:00
|
|
|
jwksSecretLabels: jwksSecretLabels,
|
|
|
|
kubeClient: kubeClient,
|
|
|
|
pinnipedClient: pinnipedClient,
|
|
|
|
secretInformer: secretInformer,
|
|
|
|
federationDomainInformer: federationDomainInformer,
|
2020-10-14 13:47:34 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-17 19:34:49 +00:00
|
|
|
// We want to be notified when a FederationDomain's secret gets updated or deleted. When this happens, we
|
|
|
|
// should get notified via the corresponding FederationDomain key.
|
2020-10-14 13:47:34 +00:00
|
|
|
withInformer(
|
|
|
|
secretInformer,
|
2020-12-18 22:55:05 +00:00
|
|
|
pinnipedcontroller.SimpleFilter(isSecretToSync, pinnipedcontroller.SecretIsControlledByParentFunc(isSecretToSync)),
|
2020-10-14 13:47:34 +00:00
|
|
|
controllerlib.InformerOption{},
|
|
|
|
),
|
2020-12-17 19:34:49 +00:00
|
|
|
// We want to be notified when anything happens to an FederationDomain.
|
2020-10-14 13:47:34 +00:00
|
|
|
withInformer(
|
2020-12-17 19:34:49 +00:00
|
|
|
federationDomainInformer,
|
2020-10-02 17:22:18 +00:00
|
|
|
pinnipedcontroller.MatchAnythingFilter(nil), // nil parent func is fine because each event is distinct
|
2020-10-14 13:47:34 +00:00
|
|
|
controllerlib.InformerOption{},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync implements controllerlib.Syncer.
|
2020-10-17 00:51:40 +00:00
|
|
|
func (c *jwksWriterController) Sync(ctx controllerlib.Context) error {
|
2020-12-17 19:34:49 +00:00
|
|
|
federationDomain, err := c.federationDomainInformer.Lister().FederationDomains(ctx.Key.Namespace).Get(ctx.Key.Name)
|
2020-10-14 13:47:34 +00:00
|
|
|
notFound := k8serrors.IsNotFound(err)
|
|
|
|
if err != nil && !notFound {
|
|
|
|
return fmt.Errorf(
|
2020-12-16 22:27:09 +00:00
|
|
|
"failed to get %s/%s FederationDomain: %w",
|
2020-10-14 13:47:34 +00:00
|
|
|
ctx.Key.Namespace,
|
|
|
|
ctx.Key.Name,
|
|
|
|
err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if notFound {
|
2020-12-17 19:34:49 +00:00
|
|
|
// The corresponding secret to this FederationDomain should have been garbage collected since it should have
|
|
|
|
// had this FederationDomain as its owner.
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug(
|
2020-12-17 19:34:49 +00:00
|
|
|
"FederationDomain deleted",
|
2020-12-16 22:27:09 +00:00
|
|
|
"federationdomain",
|
2020-10-14 13:47:34 +00:00
|
|
|
klog.KRef(ctx.Key.Namespace, ctx.Key.Name),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
secretNeedsUpdate, err := c.secretNeedsUpdate(federationDomain)
|
2020-10-14 20:41:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot determine secret status: %w", err)
|
|
|
|
}
|
|
|
|
if !secretNeedsUpdate {
|
|
|
|
// Secret is up to date - we are good to go.
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug(
|
2020-10-15 13:09:49 +00:00
|
|
|
"secret is up to date",
|
2020-12-16 22:27:09 +00:00
|
|
|
"federationdomain",
|
2020-10-15 13:09:49 +00:00
|
|
|
klog.KRef(ctx.Key.Namespace, ctx.Key.Name),
|
|
|
|
)
|
2020-10-14 20:41:16 +00:00
|
|
|
return nil
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
// If the FederationDomain does not have a secret associated with it, that secret does not exist, or the secret
|
2020-10-14 20:41:16 +00:00
|
|
|
// is invalid, we will generate a new secret (i.e., a JWKS).
|
2020-12-17 19:34:49 +00:00
|
|
|
secret, err := c.generateSecret(federationDomain)
|
2020-10-14 20:41:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot generate secret: %w", err)
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.createOrUpdateSecret(ctx.Context, secret); err != nil {
|
|
|
|
return fmt.Errorf("cannot create or update secret: %w", err)
|
|
|
|
}
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("created/updated secret", "secret", klog.KObj(secret))
|
2020-10-14 13:47:34 +00:00
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
// Ensure that the FederationDomain points to the secret.
|
|
|
|
newFederationDomain := federationDomain.DeepCopy()
|
|
|
|
newFederationDomain.Status.Secrets.JWKS.Name = secret.Name
|
2021-02-11 02:46:03 +00:00
|
|
|
if err := c.updateFederationDomainStatus(ctx.Context, newFederationDomain); err != nil {
|
2020-12-17 19:34:49 +00:00
|
|
|
return fmt.Errorf("cannot update FederationDomain: %w", err)
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
2020-12-17 19:34:49 +00:00
|
|
|
plog.Debug("updated FederationDomain", "federationdomain", klog.KObj(newFederationDomain))
|
2020-10-14 13:47:34 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
func (c *jwksWriterController) secretNeedsUpdate(federationDomain *configv1alpha1.FederationDomain) (bool, error) {
|
|
|
|
if federationDomain.Status.Secrets.JWKS.Name == "" {
|
|
|
|
// If the FederationDomain says it doesn't have a secret associated with it, then let's create one.
|
2020-10-14 20:41:16 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
// This FederationDomain says it has a secret associated with it. Let's try to get it from the cache.
|
|
|
|
secret, err := c.secretInformer.Lister().Secrets(federationDomain.Namespace).Get(federationDomain.Status.Secrets.JWKS.Name)
|
2020-10-14 20:41:16 +00:00
|
|
|
notFound := k8serrors.IsNotFound(err)
|
|
|
|
if err != nil && !notFound {
|
|
|
|
return false, fmt.Errorf("cannot get secret: %w", err)
|
|
|
|
}
|
|
|
|
if notFound {
|
|
|
|
// If we can't find the secret, let's assume we need to create it.
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isValid(secret) {
|
|
|
|
// If this secret is invalid, we need to generate a new one.
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
func (c *jwksWriterController) generateSecret(federationDomain *configv1alpha1.FederationDomain) (*corev1.Secret, error) {
|
|
|
|
// Note! This is where we could potentially add more handling of FederationDomain spec fields which tell us how
|
|
|
|
// this FederationDomain should sign and verify ID tokens (e.g., hardcoded token secret, gRPC
|
2020-10-14 13:47:34 +00:00
|
|
|
// connection to KMS, etc).
|
|
|
|
//
|
|
|
|
// For now, we just generate an new RSA keypair and put that in the secret.
|
|
|
|
|
2020-10-15 15:33:08 +00:00
|
|
|
key, err := generateKey(rand.Reader)
|
2020-10-14 13:47:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot generate key: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
jwk := jose.JSONWebKey{
|
2020-10-14 20:41:16 +00:00
|
|
|
Key: key,
|
2020-10-15 15:33:08 +00:00
|
|
|
KeyID: "pinniped-supervisor-key",
|
|
|
|
Algorithm: "ES256",
|
2020-10-14 13:47:34 +00:00
|
|
|
Use: "sig",
|
|
|
|
}
|
|
|
|
jwkData, err := json.Marshal(jwk)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot marshal jwk: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
jwks := jose.JSONWebKeySet{
|
2020-10-14 20:41:16 +00:00
|
|
|
Keys: []jose.JSONWebKey{jwk.Public()},
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
jwksData, err := json.Marshal(jwks)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot marshal jwks: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s := corev1.Secret{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2020-12-17 19:34:49 +00:00
|
|
|
Name: federationDomain.Name + "-jwks",
|
|
|
|
Namespace: federationDomain.Namespace,
|
2020-10-15 19:40:56 +00:00
|
|
|
Labels: c.jwksSecretLabels,
|
2020-10-14 13:47:34 +00:00
|
|
|
OwnerReferences: []metav1.OwnerReference{
|
2020-12-17 19:34:49 +00:00
|
|
|
*metav1.NewControllerRef(federationDomain, schema.GroupVersionKind{
|
2020-10-14 13:47:34 +00:00
|
|
|
Group: configv1alpha1.SchemeGroupVersion.Group,
|
|
|
|
Version: configv1alpha1.SchemeGroupVersion.Version,
|
2020-12-17 19:34:49 +00:00
|
|
|
Kind: federationDomainKind,
|
2020-10-14 13:47:34 +00:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
activeJWKKey: jwkData,
|
2020-10-14 20:41:16 +00:00
|
|
|
jwksKey: jwksData,
|
2020-10-14 13:47:34 +00:00
|
|
|
},
|
2020-12-17 22:48:49 +00:00
|
|
|
Type: jwksSecretTypeValue,
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &s, nil
|
|
|
|
}
|
|
|
|
|
2020-10-17 00:51:40 +00:00
|
|
|
func (c *jwksWriterController) createOrUpdateSecret(
|
2020-10-14 13:47:34 +00:00
|
|
|
ctx context.Context,
|
|
|
|
newSecret *corev1.Secret,
|
|
|
|
) error {
|
|
|
|
secretClient := c.kubeClient.CoreV1().Secrets(newSecret.Namespace)
|
|
|
|
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
|
|
|
oldSecret, err := secretClient.Get(ctx, newSecret.Name, metav1.GetOptions{})
|
|
|
|
notFound := k8serrors.IsNotFound(err)
|
|
|
|
if err != nil && !notFound {
|
|
|
|
return fmt.Errorf("cannot get secret: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if notFound {
|
|
|
|
// New secret doesn't exist, so create it.
|
|
|
|
_, err := secretClient.Create(ctx, newSecret, metav1.CreateOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot create secret: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// New secret already exists, so ensure it is up to date.
|
|
|
|
|
|
|
|
if isValid(oldSecret) {
|
|
|
|
// If the secret already has valid JWK's, then we are good to go and we don't need an update.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
oldSecret.Data = newSecret.Data
|
2020-12-17 22:48:49 +00:00
|
|
|
oldSecret.Type = jwksSecretTypeValue
|
2020-10-14 13:47:34 +00:00
|
|
|
_, err = secretClient.Update(ctx, oldSecret, metav1.UpdateOptions{})
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-11 02:46:03 +00:00
|
|
|
func (c *jwksWriterController) updateFederationDomainStatus(
|
2020-10-14 13:47:34 +00:00
|
|
|
ctx context.Context,
|
2020-12-17 19:34:49 +00:00
|
|
|
newFederationDomain *configv1alpha1.FederationDomain,
|
2020-10-14 13:47:34 +00:00
|
|
|
) error {
|
2020-12-17 19:34:49 +00:00
|
|
|
federationDomainClient := c.pinnipedClient.ConfigV1alpha1().FederationDomains(newFederationDomain.Namespace)
|
2020-10-14 13:47:34 +00:00
|
|
|
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
2020-12-17 19:34:49 +00:00
|
|
|
oldFederationDomain, err := federationDomainClient.Get(ctx, newFederationDomain.Name, metav1.GetOptions{})
|
2020-10-14 20:41:16 +00:00
|
|
|
if err != nil {
|
2020-12-17 19:34:49 +00:00
|
|
|
return fmt.Errorf("cannot get FederationDomain: %w", err)
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
if newFederationDomain.Status.Secrets.JWKS.Name == oldFederationDomain.Status.Secrets.JWKS.Name {
|
|
|
|
// If the existing FederationDomain is up to date, we don't need to update it.
|
2020-10-14 13:47:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-17 19:34:49 +00:00
|
|
|
oldFederationDomain.Status.Secrets.JWKS.Name = newFederationDomain.Status.Secrets.JWKS.Name
|
2021-02-11 02:46:03 +00:00
|
|
|
_, err = federationDomainClient.UpdateStatus(ctx, oldFederationDomain, metav1.UpdateOptions{})
|
2020-10-14 13:47:34 +00:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// isValid returns whether the provided secret contains a valid active JWK and verification JWKS.
|
|
|
|
func isValid(secret *corev1.Secret) bool {
|
2020-12-17 22:48:49 +00:00
|
|
|
if secret.Type != jwksSecretTypeValue {
|
|
|
|
plog.Debug("secret does not have the expected type", "expectedType", jwksSecretTypeValue, "actualType", secret.Type)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:47:34 +00:00
|
|
|
jwkData, ok := secret.Data[activeJWKKey]
|
|
|
|
if !ok {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("secret does not contain active jwk")
|
2020-10-14 13:47:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var activeJWK jose.JSONWebKey
|
|
|
|
if err := json.Unmarshal(jwkData, &activeJWK); err != nil {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("cannot unmarshal active jwk", "err", err)
|
2020-10-14 13:47:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-14 20:41:16 +00:00
|
|
|
if activeJWK.IsPublic() {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("active jwk is public", "keyid", activeJWK.KeyID)
|
2020-10-14 20:41:16 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:47:34 +00:00
|
|
|
if !activeJWK.Valid() {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("active jwk is not valid", "keyid", activeJWK.KeyID)
|
2020-10-14 13:47:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-14 20:41:16 +00:00
|
|
|
jwksData, ok := secret.Data[jwksKey]
|
2020-10-14 13:47:34 +00:00
|
|
|
if !ok {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("secret does not contain valid jwks")
|
2020-10-14 13:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var validJWKS jose.JSONWebKeySet
|
|
|
|
if err := json.Unmarshal(jwksData, &validJWKS); err != nil {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("cannot unmarshal valid jwks", "err", err)
|
2020-10-14 13:47:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
foundActiveJWK := false
|
|
|
|
for _, validJWK := range validJWKS.Keys {
|
2020-10-14 20:41:16 +00:00
|
|
|
if !validJWK.IsPublic() {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("jwks key is not public", "keyid", validJWK.KeyID)
|
2020-10-14 20:41:16 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-10-14 13:47:34 +00:00
|
|
|
if !validJWK.Valid() {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("jwks key is not valid", "keyid", validJWK.KeyID)
|
2020-10-14 13:47:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if validJWK.KeyID == activeJWK.KeyID {
|
|
|
|
foundActiveJWK = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !foundActiveJWK {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("did not find active jwk in valid jwks", "keyid", activeJWK.KeyID)
|
2020-10-14 13:47:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|