2021-01-07 22:58:09 +00:00
|
|
|
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
2020-10-06 00:28:19 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-12-14 15:36:45 +00:00
|
|
|
"crypto/rand"
|
2020-10-27 00:03:26 +00:00
|
|
|
"crypto/tls"
|
2020-10-06 00:28:19 +00:00
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2020-10-27 00:03:26 +00:00
|
|
|
"strings"
|
2020-10-06 00:28:19 +00:00
|
|
|
"time"
|
|
|
|
|
2020-12-11 16:11:49 +00:00
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
2020-12-17 12:41:53 +00:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
2020-10-08 17:27:45 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/clock"
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeinformers "k8s.io/client-go/informers"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
2020-10-06 00:28:19 +00:00
|
|
|
"k8s.io/client-go/pkg/version"
|
|
|
|
"k8s.io/client-go/rest"
|
|
|
|
"k8s.io/component-base/logs"
|
|
|
|
"k8s.io/klog/v2"
|
2020-11-11 23:10:06 +00:00
|
|
|
"k8s.io/klog/v2/klogr"
|
2020-10-06 00:28:19 +00:00
|
|
|
|
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"
|
|
|
|
pinnipedinformers "go.pinniped.dev/generated/latest/client/supervisor/informers/externalversions"
|
2020-10-15 19:40:56 +00:00
|
|
|
"go.pinniped.dev/internal/config/supervisor"
|
2020-10-06 00:28:19 +00:00
|
|
|
"go.pinniped.dev/internal/controller/supervisorconfig"
|
2020-12-12 00:05:08 +00:00
|
|
|
"go.pinniped.dev/internal/controller/supervisorconfig/generator"
|
2020-11-11 23:10:06 +00:00
|
|
|
"go.pinniped.dev/internal/controller/supervisorconfig/upstreamwatcher"
|
2020-12-11 23:21:34 +00:00
|
|
|
"go.pinniped.dev/internal/controller/supervisorstorage"
|
2020-10-06 00:28:19 +00:00
|
|
|
"go.pinniped.dev/internal/controllerlib"
|
2021-01-05 22:07:33 +00:00
|
|
|
"go.pinniped.dev/internal/deploymentref"
|
2020-10-06 00:28:19 +00:00
|
|
|
"go.pinniped.dev/internal/downward"
|
2021-01-13 01:27:41 +00:00
|
|
|
"go.pinniped.dev/internal/groupsuffix"
|
2021-01-05 22:07:33 +00:00
|
|
|
"go.pinniped.dev/internal/kubeclient"
|
2020-10-17 00:51:40 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/jwks"
|
2020-10-27 00:03:26 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/provider"
|
2020-10-08 18:28:21 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/provider/manager"
|
2020-11-10 13:48:42 +00:00
|
|
|
"go.pinniped.dev/internal/plog"
|
2020-12-17 12:41:53 +00:00
|
|
|
"go.pinniped.dev/internal/secret"
|
2020-10-06 00:28:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
singletonWorker = 1
|
|
|
|
defaultResyncInterval = 3 * time.Minute
|
|
|
|
)
|
|
|
|
|
2020-10-08 02:18:34 +00:00
|
|
|
func start(ctx context.Context, l net.Listener, handler http.Handler) {
|
|
|
|
server := http.Server{Handler: handler}
|
2020-10-06 00:28:19 +00:00
|
|
|
|
|
|
|
errCh := make(chan error)
|
|
|
|
go func() {
|
|
|
|
errCh <- server.Serve(l)
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case err := <-errCh:
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("server exited", "err", err)
|
2020-10-06 00:28:19 +00:00
|
|
|
case <-ctx.Done():
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("server context cancelled", "err", ctx.Err())
|
2020-10-06 00:28:19 +00:00
|
|
|
if err := server.Shutdown(context.Background()); err != nil {
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("server shutdown failed", "err", err)
|
2020-10-06 00:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitForSignal() os.Signal {
|
|
|
|
signalCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(signalCh, os.Interrupt)
|
|
|
|
return <-signalCh
|
|
|
|
}
|
|
|
|
|
2020-12-14 16:44:01 +00:00
|
|
|
//nolint:funlen
|
2020-10-06 00:28:19 +00:00
|
|
|
func startControllers(
|
|
|
|
ctx context.Context,
|
2020-10-15 19:40:56 +00:00
|
|
|
cfg *supervisor.Config,
|
2020-10-17 00:51:40 +00:00
|
|
|
issuerManager *manager.Manager,
|
|
|
|
dynamicJWKSProvider jwks.DynamicJWKSProvider,
|
2020-10-27 00:03:26 +00:00
|
|
|
dynamicTLSCertProvider provider.DynamicTLSCertProvider,
|
2020-11-11 23:10:06 +00:00
|
|
|
dynamicUpstreamIDPProvider provider.DynamicUpstreamIDPProvider,
|
2020-12-11 16:11:49 +00:00
|
|
|
secretCache *secret.Cache,
|
|
|
|
supervisorDeployment *appsv1.Deployment,
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeClient kubernetes.Interface,
|
2020-10-08 17:27:45 +00:00
|
|
|
pinnipedClient pinnipedclientset.Interface,
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeInformers kubeinformers.SharedInformerFactory,
|
2020-10-07 14:53:05 +00:00
|
|
|
pinnipedInformers pinnipedinformers.SharedInformerFactory,
|
2020-10-06 00:28:19 +00:00
|
|
|
) {
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer := pinnipedInformers.Config().V1alpha1().FederationDomains()
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer := kubeInformers.Core().V1().Secrets()
|
|
|
|
|
2020-10-06 00:28:19 +00:00
|
|
|
// Create controller manager.
|
|
|
|
controllerManager := controllerlib.
|
|
|
|
NewManager().
|
2020-12-11 23:21:34 +00:00
|
|
|
WithController(
|
|
|
|
supervisorstorage.GarbageCollectorController(
|
|
|
|
clock.RealClock{},
|
|
|
|
kubeClient,
|
2020-12-17 19:34:49 +00:00
|
|
|
secretInformer,
|
2020-12-11 23:21:34 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
2020-10-06 00:28:19 +00:00
|
|
|
WithController(
|
2020-12-16 22:27:09 +00:00
|
|
|
supervisorconfig.NewFederationDomainWatcherController(
|
2020-10-17 00:51:40 +00:00
|
|
|
issuerManager,
|
2020-10-08 17:27:45 +00:00
|
|
|
clock.RealClock{},
|
|
|
|
pinnipedClient,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-10-06 00:28:19 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-10-14 13:47:34 +00:00
|
|
|
).
|
|
|
|
WithController(
|
2020-10-17 00:51:40 +00:00
|
|
|
supervisorconfig.NewJWKSWriterController(
|
2020-10-15 19:40:56 +00:00
|
|
|
cfg.Labels,
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeClient,
|
|
|
|
pinnipedClient,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-10-14 13:47:34 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-10-17 00:51:40 +00:00
|
|
|
).
|
|
|
|
WithController(
|
|
|
|
supervisorconfig.NewJWKSObserverController(
|
|
|
|
dynamicJWKSProvider,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-10-17 00:51:40 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-10-27 00:03:26 +00:00
|
|
|
).
|
|
|
|
WithController(
|
|
|
|
supervisorconfig.NewTLSCertObserverController(
|
|
|
|
dynamicTLSCertProvider,
|
2020-10-28 18:56:50 +00:00
|
|
|
cfg.NamesConfig.DefaultTLSCertificateSecret,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-10-27 00:03:26 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-11-11 23:10:06 +00:00
|
|
|
).
|
2020-12-11 16:11:49 +00:00
|
|
|
WithController(
|
2020-12-12 00:05:08 +00:00
|
|
|
generator.NewSupervisorSecretsController(
|
2020-12-11 16:11:49 +00:00
|
|
|
supervisorDeployment,
|
2020-12-14 20:53:12 +00:00
|
|
|
cfg.Labels,
|
2020-12-11 16:11:49 +00:00
|
|
|
kubeClient,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-11 16:11:49 +00:00
|
|
|
func(secret []byte) {
|
|
|
|
plog.Debug("setting csrf cookie secret")
|
|
|
|
secretCache.SetCSRFCookieEncoderHashKey(secret)
|
|
|
|
},
|
2020-12-15 00:08:48 +00:00
|
|
|
controllerlib.WithInformer,
|
2020-12-15 12:58:33 +00:00
|
|
|
controllerlib.WithInitialEvent,
|
2020-12-11 16:11:49 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
2020-11-11 23:10:06 +00:00
|
|
|
WithController(
|
2020-12-16 22:27:09 +00:00
|
|
|
generator.NewFederationDomainSecretsController(
|
2020-12-15 01:38:01 +00:00
|
|
|
generator.NewSymmetricSecretHelper(
|
2020-12-14 15:36:45 +00:00
|
|
|
"pinniped-oidc-provider-hmac-key-",
|
|
|
|
cfg.Labels,
|
|
|
|
rand.Reader,
|
2020-12-15 14:13:01 +00:00
|
|
|
generator.SecretUsageTokenSigningKey,
|
2020-12-16 22:27:09 +00:00
|
|
|
func(federationDomainIssuer string, symmetricKey []byte) {
|
|
|
|
plog.Debug("setting hmac secret", "issuer", federationDomainIssuer)
|
|
|
|
secretCache.SetTokenHMACKey(federationDomainIssuer, symmetricKey)
|
2020-12-14 15:36:45 +00:00
|
|
|
},
|
|
|
|
),
|
2021-02-11 02:46:03 +00:00
|
|
|
func(fd *configv1alpha1.FederationDomainStatus) *corev1.LocalObjectReference {
|
|
|
|
return &fd.Secrets.TokenSigningKey
|
2020-12-17 12:41:53 +00:00
|
|
|
},
|
2020-12-14 15:36:45 +00:00
|
|
|
kubeClient,
|
2020-12-15 14:13:01 +00:00
|
|
|
pinnipedClient,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-12-14 15:36:45 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
|
|
|
WithController(
|
2020-12-16 22:27:09 +00:00
|
|
|
generator.NewFederationDomainSecretsController(
|
2020-12-15 01:38:01 +00:00
|
|
|
generator.NewSymmetricSecretHelper(
|
2020-12-14 15:36:45 +00:00
|
|
|
"pinniped-oidc-provider-upstream-state-signature-key-",
|
|
|
|
cfg.Labels,
|
|
|
|
rand.Reader,
|
2020-12-15 14:13:01 +00:00
|
|
|
generator.SecretUsageStateSigningKey,
|
2020-12-16 22:27:09 +00:00
|
|
|
func(federationDomainIssuer string, symmetricKey []byte) {
|
|
|
|
plog.Debug("setting state signature key", "issuer", federationDomainIssuer)
|
|
|
|
secretCache.SetStateEncoderHashKey(federationDomainIssuer, symmetricKey)
|
2020-12-14 15:36:45 +00:00
|
|
|
},
|
|
|
|
),
|
2021-02-11 02:46:03 +00:00
|
|
|
func(fd *configv1alpha1.FederationDomainStatus) *corev1.LocalObjectReference {
|
|
|
|
return &fd.Secrets.StateSigningKey
|
2020-12-17 12:41:53 +00:00
|
|
|
},
|
2020-12-14 15:36:45 +00:00
|
|
|
kubeClient,
|
2020-12-15 14:13:01 +00:00
|
|
|
pinnipedClient,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-12-14 15:36:45 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
|
|
|
WithController(
|
2020-12-16 22:27:09 +00:00
|
|
|
generator.NewFederationDomainSecretsController(
|
2020-12-15 01:38:01 +00:00
|
|
|
generator.NewSymmetricSecretHelper(
|
2020-12-14 15:36:45 +00:00
|
|
|
"pinniped-oidc-provider-upstream-state-encryption-key-",
|
|
|
|
cfg.Labels,
|
|
|
|
rand.Reader,
|
2020-12-15 14:13:01 +00:00
|
|
|
generator.SecretUsageStateEncryptionKey,
|
2020-12-16 22:27:09 +00:00
|
|
|
func(federationDomainIssuer string, symmetricKey []byte) {
|
|
|
|
plog.Debug("setting state encryption key", "issuer", federationDomainIssuer)
|
|
|
|
secretCache.SetStateEncoderBlockKey(federationDomainIssuer, symmetricKey)
|
2020-12-14 15:36:45 +00:00
|
|
|
},
|
|
|
|
),
|
2021-02-11 02:46:03 +00:00
|
|
|
func(fd *configv1alpha1.FederationDomainStatus) *corev1.LocalObjectReference {
|
|
|
|
return &fd.Secrets.StateEncryptionKey
|
2020-12-17 12:41:53 +00:00
|
|
|
},
|
2020-12-14 15:36:45 +00:00
|
|
|
kubeClient,
|
2020-12-15 14:13:01 +00:00
|
|
|
pinnipedClient,
|
2020-12-14 15:36:45 +00:00
|
|
|
secretInformer,
|
2020-12-17 21:49:53 +00:00
|
|
|
federationDomainInformer,
|
2020-12-14 15:36:45 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
|
|
|
WithController(
|
2021-04-09 15:43:09 +00:00
|
|
|
upstreamwatcher.NewOIDCUpstreamWatcherController(
|
2020-11-11 23:10:06 +00:00
|
|
|
dynamicUpstreamIDPProvider,
|
|
|
|
pinnipedClient,
|
2020-12-16 22:27:09 +00:00
|
|
|
pinnipedInformers.IDP().V1alpha1().OIDCIdentityProviders(),
|
2020-12-17 21:49:53 +00:00
|
|
|
secretInformer,
|
2020-12-18 23:41:07 +00:00
|
|
|
klogr.New(),
|
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
2021-04-10 01:49:43 +00:00
|
|
|
singletonWorker).
|
|
|
|
WithController(
|
|
|
|
upstreamwatcher.NewLDAPUpstreamWatcherController(
|
|
|
|
dynamicUpstreamIDPProvider,
|
|
|
|
// nil means to use a real production dialer when creating objects to add to the dynamicUpstreamIDPProvider cache.
|
|
|
|
nil,
|
|
|
|
pinnipedClient,
|
|
|
|
pinnipedInformers.IDP().V1alpha1().LDAPIdentityProviders(),
|
|
|
|
secretInformer,
|
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
2020-11-11 23:10:06 +00:00
|
|
|
singletonWorker)
|
2020-10-06 00:28:19 +00:00
|
|
|
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeInformers.Start(ctx.Done())
|
2020-10-07 14:53:05 +00:00
|
|
|
pinnipedInformers.Start(ctx.Done())
|
2020-10-06 00:28:19 +00:00
|
|
|
|
2020-10-21 18:51:31 +00:00
|
|
|
// Wait until the caches are synced before returning.
|
|
|
|
kubeInformers.WaitForCacheSync(ctx.Done())
|
|
|
|
pinnipedInformers.WaitForCacheSync(ctx.Done())
|
|
|
|
|
2020-10-06 00:28:19 +00:00
|
|
|
go controllerManager.Start(ctx)
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:11:49 +00:00
|
|
|
func run(podInfo *downward.PodInfo, cfg *supervisor.Config) error {
|
|
|
|
serverInstallationNamespace := podInfo.Namespace
|
|
|
|
|
2020-10-06 00:28:19 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-01-05 22:07:33 +00:00
|
|
|
dref, supervisorDeployment, err := deploymentref.New(podInfo)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot create deployment ref: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-01-13 01:27:41 +00:00
|
|
|
client, err := kubeclient.New(
|
|
|
|
dref,
|
|
|
|
kubeclient.WithMiddleware(groupsuffix.New(*cfg.APIGroupSuffix)),
|
|
|
|
)
|
2020-10-06 00:28:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot create k8s client: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:47:34 +00:00
|
|
|
kubeInformers := kubeinformers.NewSharedInformerFactoryWithOptions(
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
2020-10-14 13:47:34 +00:00
|
|
|
defaultResyncInterval,
|
|
|
|
kubeinformers.WithNamespace(serverInstallationNamespace),
|
|
|
|
)
|
|
|
|
|
2020-10-07 14:53:05 +00:00
|
|
|
pinnipedInformers := pinnipedinformers.NewSharedInformerFactoryWithOptions(
|
2021-01-05 22:07:33 +00:00
|
|
|
client.PinnipedSupervisor,
|
2020-10-06 00:28:19 +00:00
|
|
|
defaultResyncInterval,
|
2020-10-07 14:53:05 +00:00
|
|
|
pinnipedinformers.WithNamespace(serverInstallationNamespace),
|
2020-10-06 00:28:19 +00:00
|
|
|
)
|
|
|
|
|
2020-10-21 22:24:48 +00:00
|
|
|
// Serve the /healthz endpoint and make all other paths result in 404.
|
|
|
|
healthMux := http.NewServeMux()
|
|
|
|
healthMux.Handle("/healthz", http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
_, _ = writer.Write([]byte("ok"))
|
|
|
|
}))
|
|
|
|
|
2020-10-17 00:51:40 +00:00
|
|
|
dynamicJWKSProvider := jwks.NewDynamicJWKSProvider()
|
2020-10-27 00:03:26 +00:00
|
|
|
dynamicTLSCertProvider := provider.NewDynamicTLSCertProvider()
|
2020-11-05 01:06:47 +00:00
|
|
|
dynamicUpstreamIDPProvider := provider.NewDynamicUpstreamIDPProvider()
|
2020-12-11 16:11:49 +00:00
|
|
|
secretCache := secret.Cache{}
|
2020-10-27 00:03:26 +00:00
|
|
|
|
2020-10-21 22:24:48 +00:00
|
|
|
// OIDC endpoints will be served by the oidProvidersManager, and any non-OIDC paths will fallback to the healthMux.
|
2020-12-03 01:39:45 +00:00
|
|
|
oidProvidersManager := manager.NewManager(
|
|
|
|
healthMux,
|
|
|
|
dynamicJWKSProvider,
|
|
|
|
dynamicUpstreamIDPProvider,
|
2020-12-11 16:11:49 +00:00
|
|
|
&secretCache,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes.CoreV1().Secrets(serverInstallationNamespace),
|
2020-12-03 01:39:45 +00:00
|
|
|
)
|
2020-10-27 00:03:26 +00:00
|
|
|
|
|
|
|
startControllers(
|
|
|
|
ctx,
|
|
|
|
cfg,
|
|
|
|
oidProvidersManager,
|
|
|
|
dynamicJWKSProvider,
|
|
|
|
dynamicTLSCertProvider,
|
2020-11-11 23:10:06 +00:00
|
|
|
dynamicUpstreamIDPProvider,
|
2020-12-11 16:11:49 +00:00
|
|
|
&secretCache,
|
|
|
|
supervisorDeployment,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
|
|
|
client.PinnipedSupervisor,
|
2020-10-27 00:03:26 +00:00
|
|
|
kubeInformers,
|
|
|
|
pinnipedInformers,
|
|
|
|
)
|
2020-10-06 00:28:19 +00:00
|
|
|
|
|
|
|
//nolint: gosec // Intentionally binding to all network interfaces.
|
2020-11-02 16:57:05 +00:00
|
|
|
httpListener, err := net.Listen("tcp", ":8080")
|
2020-10-06 00:28:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot create listener: %w", err)
|
|
|
|
}
|
2020-10-27 23:33:08 +00:00
|
|
|
defer func() { _ = httpListener.Close() }()
|
2020-10-27 00:03:26 +00:00
|
|
|
start(ctx, httpListener, oidProvidersManager)
|
2020-10-21 18:51:31 +00:00
|
|
|
|
2020-10-27 00:03:26 +00:00
|
|
|
//nolint: gosec // Intentionally binding to all network interfaces.
|
2020-11-02 16:57:05 +00:00
|
|
|
httpsListener, err := tls.Listen("tcp", ":8443", &tls.Config{
|
2020-10-27 21:57:25 +00:00
|
|
|
MinVersion: tls.VersionTLS12, // Allow v1.2 because clients like the default `curl` on MacOS don't support 1.3 yet.
|
2020-10-27 00:03:26 +00:00
|
|
|
GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
2020-10-27 21:57:25 +00:00
|
|
|
cert := dynamicTLSCertProvider.GetTLSCert(strings.ToLower(info.ServerName))
|
2020-10-27 23:33:08 +00:00
|
|
|
defaultCert := dynamicTLSCertProvider.GetDefaultTLSCert()
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("GetCertificate called for port 8443",
|
2020-10-27 23:33:08 +00:00
|
|
|
"info.ServerName", info.ServerName,
|
|
|
|
"foundSNICert", cert != nil,
|
|
|
|
"foundDefaultCert", defaultCert != nil,
|
|
|
|
)
|
|
|
|
if cert == nil {
|
|
|
|
cert = defaultCert
|
|
|
|
}
|
2020-10-27 21:57:25 +00:00
|
|
|
return cert, nil
|
2020-10-27 00:03:26 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot create listener: %w", err)
|
|
|
|
}
|
2020-10-27 23:33:08 +00:00
|
|
|
defer func() { _ = httpsListener.Close() }()
|
2020-10-27 00:03:26 +00:00
|
|
|
start(ctx, httpsListener, oidProvidersManager)
|
|
|
|
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("supervisor is ready",
|
2020-10-27 00:03:26 +00:00
|
|
|
"httpAddress", httpListener.Addr().String(),
|
|
|
|
"httpsAddress", httpsListener.Addr().String(),
|
|
|
|
)
|
2020-10-06 00:28:19 +00:00
|
|
|
|
|
|
|
gotSignal := waitForSignal()
|
2020-11-10 15:22:16 +00:00
|
|
|
plog.Debug("supervisor exiting", "signal", gotSignal)
|
2020-10-06 00:28:19 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
logs.InitLogs()
|
|
|
|
defer logs.FlushLogs()
|
2020-11-10 13:48:42 +00:00
|
|
|
plog.RemoveKlogGlobalFlags() // move this whenever the below code gets refactored to use cobra
|
2020-10-06 00:28:19 +00:00
|
|
|
|
|
|
|
klog.Infof("Running %s at %#v", rest.DefaultKubernetesUserAgent(), version.Get())
|
|
|
|
klog.Infof("Command-line arguments were: %s %s %s", os.Args[0], os.Args[1], os.Args[2])
|
|
|
|
|
|
|
|
// Discover in which namespace we are installed.
|
|
|
|
podInfo, err := downward.Load(os.Args[1])
|
|
|
|
if err != nil {
|
|
|
|
klog.Fatal(fmt.Errorf("could not read pod metadata: %w", err))
|
|
|
|
}
|
|
|
|
|
2020-10-15 19:40:56 +00:00
|
|
|
// Read the server config file.
|
|
|
|
cfg, err := supervisor.FromPath(os.Args[2])
|
|
|
|
if err != nil {
|
|
|
|
klog.Fatal(fmt.Errorf("could not load config: %w", err))
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:11:49 +00:00
|
|
|
if err := run(podInfo, cfg); err != nil {
|
2020-10-06 00:28:19 +00:00
|
|
|
klog.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|