2021-04-10 01:49:43 +00:00
|
|
|
// Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-05-12 21:00:39 +00:00
|
|
|
// Package ldapupstreamwatcher implements a controller which watches LDAPIdentityProviders.
|
|
|
|
package ldapupstreamwatcher
|
2021-04-10 01:49:43 +00:00
|
|
|
|
|
|
|
import (
|
2021-04-12 20:53:21 +00:00
|
|
|
"context"
|
2021-04-14 00:16:57 +00:00
|
|
|
"crypto/x509"
|
|
|
|
"encoding/base64"
|
2021-04-10 01:49:43 +00:00
|
|
|
"fmt"
|
2021-04-15 21:44:43 +00:00
|
|
|
"time"
|
2021-04-10 01:49:43 +00:00
|
|
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
2021-04-12 20:53:21 +00:00
|
|
|
"k8s.io/apimachinery/pkg/api/equality"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2021-04-10 01:49:43 +00:00
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
|
|
corev1informers "k8s.io/client-go/informers/core/v1"
|
2021-04-12 20:53:21 +00:00
|
|
|
"k8s.io/klog/v2/klogr"
|
2021-04-10 01:49:43 +00:00
|
|
|
|
|
|
|
"go.pinniped.dev/generated/latest/apis/supervisor/idp/v1alpha1"
|
|
|
|
pinnipedclientset "go.pinniped.dev/generated/latest/client/supervisor/clientset/versioned"
|
|
|
|
idpinformers "go.pinniped.dev/generated/latest/client/supervisor/informers/externalversions/idp/v1alpha1"
|
|
|
|
pinnipedcontroller "go.pinniped.dev/internal/controller"
|
2021-05-12 21:00:39 +00:00
|
|
|
"go.pinniped.dev/internal/controller/conditionsutil"
|
|
|
|
"go.pinniped.dev/internal/controller/supervisorconfig/upstreamwatchers"
|
2021-04-10 01:49:43 +00:00
|
|
|
"go.pinniped.dev/internal/controllerlib"
|
|
|
|
"go.pinniped.dev/internal/oidc/provider"
|
|
|
|
"go.pinniped.dev/internal/upstreamldap"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ldapControllerName = "ldap-upstream-observer"
|
|
|
|
ldapBindAccountSecretType = corev1.SecretTypeBasicAuth
|
2021-04-16 00:45:15 +00:00
|
|
|
testLDAPConnectionTimeout = 90 * time.Second
|
2021-04-12 20:53:21 +00:00
|
|
|
|
|
|
|
// Constants related to conditions.
|
2021-04-28 21:26:57 +00:00
|
|
|
typeBindSecretValid = "BindSecretValid"
|
|
|
|
typeTLSConfigurationValid = "TLSConfigurationValid"
|
|
|
|
typeLDAPConnectionValid = "LDAPConnectionValid"
|
|
|
|
reasonLDAPConnectionError = "LDAPConnectionError"
|
|
|
|
noTLSConfigurationMessage = "no TLS configuration provided"
|
|
|
|
loadedTLSConfigurationMessage = "loaded TLS configuration"
|
2021-04-10 01:49:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// UpstreamLDAPIdentityProviderICache is a thread safe cache that holds a list of validated upstream LDAP IDP configurations.
|
|
|
|
type UpstreamLDAPIdentityProviderICache interface {
|
|
|
|
SetLDAPIdentityProviders([]provider.UpstreamLDAPIdentityProviderI)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ldapWatcherController struct {
|
|
|
|
cache UpstreamLDAPIdentityProviderICache
|
2021-05-13 22:22:36 +00:00
|
|
|
validatedSecretVersionsCache *secretVersionCache
|
2021-04-12 18:23:08 +00:00
|
|
|
ldapDialer upstreamldap.LDAPDialer
|
2021-04-10 01:49:43 +00:00
|
|
|
client pinnipedclientset.Interface
|
|
|
|
ldapIdentityProviderInformer idpinformers.LDAPIdentityProviderInformer
|
|
|
|
secretInformer corev1informers.SecretInformer
|
|
|
|
}
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
// An in-memory cache with an entry for each LDAPIdentityProvider, to keep track of which ResourceVersion
|
|
|
|
// of the bind Secret was used during the most recent successful validation.
|
|
|
|
type secretVersionCache struct {
|
|
|
|
ResourceVersionsByName map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSecretVersionCache() *secretVersionCache {
|
|
|
|
return &secretVersionCache{ResourceVersionsByName: map[string]string{}}
|
|
|
|
}
|
|
|
|
|
2021-05-12 21:00:39 +00:00
|
|
|
// New instantiates a new controllerlib.Controller which will populate the provided UpstreamLDAPIdentityProviderICache.
|
|
|
|
func New(
|
2021-04-27 19:43:09 +00:00
|
|
|
idpCache UpstreamLDAPIdentityProviderICache,
|
|
|
|
client pinnipedclientset.Interface,
|
|
|
|
ldapIdentityProviderInformer idpinformers.LDAPIdentityProviderInformer,
|
|
|
|
secretInformer corev1informers.SecretInformer,
|
|
|
|
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
|
|
|
) controllerlib.Controller {
|
2021-05-13 22:22:36 +00:00
|
|
|
return newInternal(
|
|
|
|
idpCache,
|
|
|
|
// start with an empty secretVersionCache
|
|
|
|
newSecretVersionCache(),
|
|
|
|
// nil means to use a real production dialer when creating objects to add to the cache
|
|
|
|
nil,
|
|
|
|
client,
|
|
|
|
ldapIdentityProviderInformer,
|
|
|
|
secretInformer,
|
|
|
|
withInformer,
|
|
|
|
)
|
2021-04-27 19:43:09 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
// For test dependency injection purposes.
|
2021-04-27 19:43:09 +00:00
|
|
|
func newInternal(
|
2021-04-10 01:49:43 +00:00
|
|
|
idpCache UpstreamLDAPIdentityProviderICache,
|
2021-05-13 22:22:36 +00:00
|
|
|
validatedSecretVersionsCache *secretVersionCache,
|
2021-04-12 18:23:08 +00:00
|
|
|
ldapDialer upstreamldap.LDAPDialer,
|
2021-04-10 01:49:43 +00:00
|
|
|
client pinnipedclientset.Interface,
|
|
|
|
ldapIdentityProviderInformer idpinformers.LDAPIdentityProviderInformer,
|
|
|
|
secretInformer corev1informers.SecretInformer,
|
|
|
|
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
|
|
|
) controllerlib.Controller {
|
|
|
|
c := ldapWatcherController{
|
|
|
|
cache: idpCache,
|
2021-05-13 22:22:36 +00:00
|
|
|
validatedSecretVersionsCache: validatedSecretVersionsCache,
|
2021-04-12 18:23:08 +00:00
|
|
|
ldapDialer: ldapDialer,
|
2021-04-10 01:49:43 +00:00
|
|
|
client: client,
|
|
|
|
ldapIdentityProviderInformer: ldapIdentityProviderInformer,
|
|
|
|
secretInformer: secretInformer,
|
|
|
|
}
|
|
|
|
return controllerlib.New(
|
|
|
|
controllerlib.Config{Name: ldapControllerName, Syncer: &c},
|
|
|
|
withInformer(
|
|
|
|
ldapIdentityProviderInformer,
|
|
|
|
pinnipedcontroller.MatchAnythingFilter(pinnipedcontroller.SingletonQueue()),
|
|
|
|
controllerlib.InformerOption{},
|
|
|
|
),
|
|
|
|
withInformer(
|
|
|
|
secretInformer,
|
|
|
|
pinnipedcontroller.MatchAnySecretOfTypeFilter(ldapBindAccountSecretType, pinnipedcontroller.SingletonQueue()),
|
|
|
|
controllerlib.InformerOption{},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync implements controllerlib.Syncer.
|
|
|
|
func (c *ldapWatcherController) Sync(ctx controllerlib.Context) error {
|
|
|
|
actualUpstreams, err := c.ldapIdentityProviderInformer.Lister().List(labels.Everything())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to list LDAPIdentityProviders: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
requeue := false
|
|
|
|
validatedUpstreams := make([]provider.UpstreamLDAPIdentityProviderI, 0, len(actualUpstreams))
|
|
|
|
for _, upstream := range actualUpstreams {
|
2021-05-13 22:22:36 +00:00
|
|
|
valid, requestedRequeue := c.validateUpstream(ctx.Context, upstream)
|
|
|
|
if valid != nil {
|
2021-04-10 01:49:43 +00:00
|
|
|
validatedUpstreams = append(validatedUpstreams, valid)
|
|
|
|
}
|
2021-05-13 22:22:36 +00:00
|
|
|
if requestedRequeue {
|
|
|
|
requeue = true
|
|
|
|
}
|
2021-04-10 01:49:43 +00:00
|
|
|
}
|
2021-05-13 22:22:36 +00:00
|
|
|
|
2021-04-10 01:49:43 +00:00
|
|
|
c.cache.SetLDAPIdentityProviders(validatedUpstreams)
|
2021-05-13 22:22:36 +00:00
|
|
|
|
2021-04-10 01:49:43 +00:00
|
|
|
if requeue {
|
|
|
|
return controllerlib.ErrSyntheticRequeue
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
func (c *ldapWatcherController) validateUpstream(ctx context.Context, upstream *v1alpha1.LDAPIdentityProvider) (p provider.UpstreamLDAPIdentityProviderI, requeue bool) {
|
2021-04-12 18:23:08 +00:00
|
|
|
spec := upstream.Spec
|
2021-04-14 00:16:57 +00:00
|
|
|
|
2021-04-15 17:25:35 +00:00
|
|
|
config := &upstreamldap.ProviderConfig{
|
2021-04-14 00:16:57 +00:00
|
|
|
Name: upstream.Name,
|
|
|
|
Host: spec.Host,
|
2021-04-15 17:25:35 +00:00
|
|
|
UserSearch: upstreamldap.UserSearchConfig{
|
2021-04-12 18:23:08 +00:00
|
|
|
Base: spec.UserSearch.Base,
|
|
|
|
Filter: spec.UserSearch.Filter,
|
|
|
|
UsernameAttribute: spec.UserSearch.Attributes.Username,
|
2021-04-27 19:43:09 +00:00
|
|
|
UIDAttribute: spec.UserSearch.Attributes.UID,
|
2021-04-12 18:23:08 +00:00
|
|
|
},
|
|
|
|
Dialer: c.ldapDialer,
|
|
|
|
}
|
2021-04-15 21:44:43 +00:00
|
|
|
|
|
|
|
conditions := []*v1alpha1.Condition{}
|
2021-04-16 00:45:15 +00:00
|
|
|
secretValidCondition, currentSecretVersion := c.validateSecret(upstream, config)
|
2021-04-15 21:44:43 +00:00
|
|
|
tlsValidCondition := c.validateTLSConfig(upstream, config)
|
|
|
|
conditions = append(conditions, secretValidCondition, tlsValidCondition)
|
|
|
|
|
|
|
|
// No point in trying to connect to the server if the config was already determined to be invalid.
|
2021-05-13 22:22:36 +00:00
|
|
|
var finishedConfigCondition *v1alpha1.Condition
|
2021-04-15 21:44:43 +00:00
|
|
|
if secretValidCondition.Status == v1alpha1.ConditionTrue && tlsValidCondition.Status == v1alpha1.ConditionTrue {
|
2021-05-13 22:22:36 +00:00
|
|
|
finishedConfigCondition = c.validateFinishedConfig(ctx, upstream, config, currentSecretVersion)
|
2021-04-15 23:46:27 +00:00
|
|
|
if finishedConfigCondition != nil {
|
|
|
|
conditions = append(conditions, finishedConfigCondition)
|
|
|
|
}
|
2021-04-12 20:53:21 +00:00
|
|
|
}
|
2021-04-15 21:44:43 +00:00
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
c.updateStatus(ctx, upstream, conditions)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case secretValidCondition.Status != v1alpha1.ConditionTrue || tlsValidCondition.Status != v1alpha1.ConditionTrue:
|
|
|
|
// Invalid provider, so do not load it into the cache.
|
|
|
|
p = nil
|
|
|
|
requeue = true
|
|
|
|
case finishedConfigCondition != nil && finishedConfigCondition.Status != v1alpha1.ConditionTrue:
|
|
|
|
// Error but load it into the cache anyway, treating this condition failure more like a warning.
|
|
|
|
p = upstreamldap.New(*config)
|
|
|
|
// Try again hoping that the condition will improve.
|
|
|
|
requeue = true
|
|
|
|
default:
|
|
|
|
// Fully validated provider, so load it into the cache.
|
|
|
|
p = upstreamldap.New(*config)
|
|
|
|
requeue = false
|
2021-04-12 20:53:21 +00:00
|
|
|
}
|
2021-04-15 21:44:43 +00:00
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
return p, requeue
|
2021-04-12 18:23:08 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 21:44:43 +00:00
|
|
|
func (c *ldapWatcherController) validateTLSConfig(upstream *v1alpha1.LDAPIdentityProvider, config *upstreamldap.ProviderConfig) *v1alpha1.Condition {
|
2021-04-14 00:16:57 +00:00
|
|
|
tlsSpec := upstream.Spec.TLS
|
|
|
|
if tlsSpec == nil {
|
|
|
|
return c.validTLSCondition(noTLSConfigurationMessage)
|
|
|
|
}
|
|
|
|
if len(tlsSpec.CertificateAuthorityData) == 0 {
|
|
|
|
return c.validTLSCondition(loadedTLSConfigurationMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle, err := base64.StdEncoding.DecodeString(tlsSpec.CertificateAuthorityData)
|
|
|
|
if err != nil {
|
|
|
|
return c.invalidTLSCondition(fmt.Sprintf("certificateAuthorityData is invalid: %s", err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
ca := x509.NewCertPool()
|
|
|
|
ok := ca.AppendCertsFromPEM(bundle)
|
|
|
|
if !ok {
|
2021-05-12 21:00:39 +00:00
|
|
|
return c.invalidTLSCondition(fmt.Sprintf("certificateAuthorityData is invalid: %s", upstreamwatchers.ErrNoCertificates))
|
2021-04-14 00:16:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 21:44:43 +00:00
|
|
|
config.CABundle = bundle
|
2021-04-14 00:16:57 +00:00
|
|
|
return c.validTLSCondition(loadedTLSConfigurationMessage)
|
|
|
|
}
|
|
|
|
|
2021-04-16 00:45:15 +00:00
|
|
|
func (c *ldapWatcherController) validateFinishedConfig(ctx context.Context, upstream *v1alpha1.LDAPIdentityProvider, config *upstreamldap.ProviderConfig, currentSecretVersion string) *v1alpha1.Condition {
|
2021-04-15 21:44:43 +00:00
|
|
|
ldapProvider := upstreamldap.New(*config)
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
if c.hasPreviousSuccessfulConditionForCurrentSpecGenerationAndSecretVersion(upstream, currentSecretVersion) {
|
2021-04-15 23:46:27 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-16 00:45:15 +00:00
|
|
|
testConnectionTimeout, cancelFunc := context.WithTimeout(ctx, testLDAPConnectionTimeout)
|
2021-04-15 21:44:43 +00:00
|
|
|
defer cancelFunc()
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
condition := c.testConnection(testConnectionTimeout, upstream, config, ldapProvider, currentSecretVersion)
|
|
|
|
|
|
|
|
if condition.Status == v1alpha1.ConditionTrue {
|
|
|
|
// Remember (in-memory for this pod) that the controller has successfully validated the LDAP provider
|
|
|
|
// using this version of the Secret. This is for performance reasons, to avoid attempting to connect to
|
|
|
|
// the LDAP server more than is needed. If the pod restarts, it will attempt this validation again.
|
|
|
|
c.validatedSecretVersionsCache.ResourceVersionsByName[upstream.GetName()] = currentSecretVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
return condition
|
2021-04-16 21:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ldapWatcherController) testConnection(
|
|
|
|
ctx context.Context,
|
|
|
|
upstream *v1alpha1.LDAPIdentityProvider,
|
|
|
|
config *upstreamldap.ProviderConfig,
|
|
|
|
ldapProvider *upstreamldap.Provider,
|
|
|
|
currentSecretVersion string,
|
|
|
|
) *v1alpha1.Condition {
|
|
|
|
err := ldapProvider.TestConnection(ctx)
|
2021-04-15 21:44:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return &v1alpha1.Condition{
|
2021-04-16 00:45:15 +00:00
|
|
|
Type: typeLDAPConnectionValid,
|
|
|
|
Status: v1alpha1.ConditionFalse,
|
|
|
|
Reason: reasonLDAPConnectionError,
|
|
|
|
Message: fmt.Sprintf(`could not successfully connect to "%s" and bind as user "%s": %s`,
|
|
|
|
config.Host, config.BindUsername, err.Error()),
|
2021-04-15 21:44:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &v1alpha1.Condition{
|
2021-04-16 00:45:15 +00:00
|
|
|
Type: typeLDAPConnectionValid,
|
|
|
|
Status: v1alpha1.ConditionTrue,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonSuccess,
|
2021-04-16 00:45:15 +00:00
|
|
|
Message: fmt.Sprintf(`successfully able to connect to "%s" and bind as user "%s" [validated with Secret "%s" at version "%s"]`,
|
|
|
|
config.Host, config.BindUsername, upstream.Spec.Bind.SecretName, currentSecretVersion),
|
2021-04-15 21:44:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
func (c *ldapWatcherController) hasPreviousSuccessfulConditionForCurrentSpecGenerationAndSecretVersion(upstream *v1alpha1.LDAPIdentityProvider, currentSecretVersion string) bool {
|
2021-04-15 23:46:27 +00:00
|
|
|
currentGeneration := upstream.Generation
|
2021-05-13 22:22:36 +00:00
|
|
|
for _, cond := range upstream.Status.Conditions {
|
|
|
|
if cond.Type == typeLDAPConnectionValid && cond.Status == v1alpha1.ConditionTrue && cond.ObservedGeneration == currentGeneration {
|
2021-04-16 00:45:15 +00:00
|
|
|
// Found a previously successful condition for the current spec generation.
|
2021-05-13 22:22:36 +00:00
|
|
|
// Now figure out which version of the bind Secret was used during that previous validation, if any.
|
|
|
|
validatedSecretVersion := c.validatedSecretVersionsCache.ResourceVersionsByName[upstream.GetName()]
|
2021-04-16 00:45:15 +00:00
|
|
|
if validatedSecretVersion == currentSecretVersion {
|
|
|
|
return true
|
|
|
|
}
|
2021-04-15 23:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-04-14 00:16:57 +00:00
|
|
|
func (c *ldapWatcherController) validTLSCondition(message string) *v1alpha1.Condition {
|
|
|
|
return &v1alpha1.Condition{
|
2021-04-15 21:44:43 +00:00
|
|
|
Type: typeTLSConfigurationValid,
|
2021-04-14 00:16:57 +00:00
|
|
|
Status: v1alpha1.ConditionTrue,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonSuccess,
|
2021-04-14 00:16:57 +00:00
|
|
|
Message: message,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ldapWatcherController) invalidTLSCondition(message string) *v1alpha1.Condition {
|
|
|
|
return &v1alpha1.Condition{
|
2021-04-15 21:44:43 +00:00
|
|
|
Type: typeTLSConfigurationValid,
|
2021-04-14 00:16:57 +00:00
|
|
|
Status: v1alpha1.ConditionFalse,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonInvalidTLSConfig,
|
2021-04-14 00:16:57 +00:00
|
|
|
Message: message,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 00:45:15 +00:00
|
|
|
func (c *ldapWatcherController) validateSecret(upstream *v1alpha1.LDAPIdentityProvider, config *upstreamldap.ProviderConfig) (*v1alpha1.Condition, string) {
|
2021-04-12 18:23:08 +00:00
|
|
|
secretName := upstream.Spec.Bind.SecretName
|
|
|
|
|
|
|
|
secret, err := c.secretInformer.Lister().Secrets(upstream.Namespace).Get(secretName)
|
|
|
|
if err != nil {
|
2021-04-12 20:53:21 +00:00
|
|
|
return &v1alpha1.Condition{
|
|
|
|
Type: typeBindSecretValid,
|
|
|
|
Status: v1alpha1.ConditionFalse,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonNotFound,
|
2021-04-12 20:53:21 +00:00
|
|
|
Message: err.Error(),
|
2021-04-16 00:45:15 +00:00
|
|
|
}, ""
|
2021-04-12 18:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if secret.Type != corev1.SecretTypeBasicAuth {
|
2021-04-12 20:53:21 +00:00
|
|
|
return &v1alpha1.Condition{
|
2021-04-16 00:45:15 +00:00
|
|
|
Type: typeBindSecretValid,
|
|
|
|
Status: v1alpha1.ConditionFalse,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonWrongType,
|
2021-04-16 00:45:15 +00:00
|
|
|
Message: fmt.Sprintf("referenced Secret %q has wrong type %q (should be %q)",
|
|
|
|
secretName, secret.Type, corev1.SecretTypeBasicAuth),
|
|
|
|
}, secret.ResourceVersion
|
2021-04-12 18:23:08 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 21:44:43 +00:00
|
|
|
config.BindUsername = string(secret.Data[corev1.BasicAuthUsernameKey])
|
|
|
|
config.BindPassword = string(secret.Data[corev1.BasicAuthPasswordKey])
|
|
|
|
if len(config.BindUsername) == 0 || len(config.BindPassword) == 0 {
|
2021-04-12 20:53:21 +00:00
|
|
|
return &v1alpha1.Condition{
|
2021-04-16 00:45:15 +00:00
|
|
|
Type: typeBindSecretValid,
|
|
|
|
Status: v1alpha1.ConditionFalse,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonMissingKeys,
|
2021-04-16 00:45:15 +00:00
|
|
|
Message: fmt.Sprintf("referenced Secret %q is missing required keys %q",
|
|
|
|
secretName, []string{corev1.BasicAuthUsernameKey, corev1.BasicAuthPasswordKey}),
|
|
|
|
}, secret.ResourceVersion
|
2021-04-12 20:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &v1alpha1.Condition{
|
|
|
|
Type: typeBindSecretValid,
|
|
|
|
Status: v1alpha1.ConditionTrue,
|
2021-05-12 21:00:39 +00:00
|
|
|
Reason: upstreamwatchers.ReasonSuccess,
|
2021-04-12 20:53:21 +00:00
|
|
|
Message: "loaded bind secret",
|
2021-04-16 00:45:15 +00:00
|
|
|
}, secret.ResourceVersion
|
2021-04-12 20:53:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 22:22:36 +00:00
|
|
|
func (c *ldapWatcherController) updateStatus(ctx context.Context, upstream *v1alpha1.LDAPIdentityProvider, conditions []*v1alpha1.Condition) {
|
2021-04-12 20:53:21 +00:00
|
|
|
log := klogr.New().WithValues("namespace", upstream.Namespace, "name", upstream.Name)
|
|
|
|
updated := upstream.DeepCopy()
|
|
|
|
|
2021-05-12 21:00:39 +00:00
|
|
|
hadErrorCondition := conditionsutil.Merge(conditions, upstream.Generation, &updated.Status.Conditions, log)
|
2021-04-12 20:53:21 +00:00
|
|
|
|
|
|
|
updated.Status.Phase = v1alpha1.LDAPPhaseReady
|
|
|
|
if hadErrorCondition {
|
|
|
|
updated.Status.Phase = v1alpha1.LDAPPhaseError
|
|
|
|
}
|
|
|
|
|
|
|
|
if equality.Semantic.DeepEqual(upstream, updated) {
|
2021-05-13 22:22:36 +00:00
|
|
|
return // nothing to update
|
2021-04-12 20:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err := c.client.
|
|
|
|
IDPV1alpha1().
|
|
|
|
LDAPIdentityProviders(upstream.Namespace).
|
|
|
|
UpdateStatus(ctx, updated, metav1.UpdateOptions{})
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "failed to update status")
|
2021-04-12 18:23:08 +00:00
|
|
|
}
|
2021-04-10 01:49:43 +00:00
|
|
|
}
|