|
|
|
@@ -23,6 +23,9 @@ import (
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
applycorev1 "k8s.io/client-go/applyconfigurations/core/v1"
|
|
|
|
|
applymetav1 "k8s.io/client-go/applyconfigurations/meta/v1"
|
|
|
|
|
|
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
|
"k8s.io/client-go/util/retry"
|
|
|
|
|
"k8s.io/utils/ptr"
|
|
|
|
@@ -47,16 +50,14 @@ func TestSupervisorOIDCDiscovery_Disruptive(t *testing.T) {
|
|
|
|
|
client := testlib.NewSupervisorClientset(t)
|
|
|
|
|
kubeClient := testlib.NewKubernetesClientset(t)
|
|
|
|
|
|
|
|
|
|
ns := env.SupervisorNamespace
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, ns, env.DefaultTLSCertSecretName(), client, testlib.NewKubernetesClientset(t))
|
|
|
|
|
defaultCA := createTLSCertificateSecret(
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, env.SupervisorNamespace, env.DefaultTLSCertSecretName(), client, testlib.NewKubernetesClientset(t))
|
|
|
|
|
defaultCA := createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx,
|
|
|
|
|
t,
|
|
|
|
|
ns,
|
|
|
|
|
env,
|
|
|
|
|
testlib.NewSupervisorIssuer(t, env.SupervisorHTTPSAddress),
|
|
|
|
|
env.DefaultTLSCertSecretName(),
|
|
|
|
|
kubeClient,
|
|
|
|
@@ -105,9 +106,9 @@ func TestSupervisorOIDCDiscovery_Disruptive(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// When FederationDomains are created in sequence they each cause a discovery endpoint to appear only for as long as the FederationDomain exists.
|
|
|
|
|
config1, jwks1 := requireCreatingFederationDomainCausesDiscoveryEndpointsToAppear(ctx, t, scheme, addr, caBundle, issuer1, client)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config1, client, ns, scheme, addr, caBundle, issuer1)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config1, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer1)
|
|
|
|
|
config2, jwks2 := requireCreatingFederationDomainCausesDiscoveryEndpointsToAppear(ctx, t, scheme, addr, caBundle, issuer2, client)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config2, client, ns, scheme, addr, caBundle, issuer2)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config2, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer2)
|
|
|
|
|
// The auto-created JWK's were different from each other.
|
|
|
|
|
require.NotEqual(t, jwks1.Keys[0]["x"], jwks2.Keys[0]["x"])
|
|
|
|
|
require.NotEqual(t, jwks1.Keys[0]["y"], jwks2.Keys[0]["y"])
|
|
|
|
@@ -121,47 +122,47 @@ func TestSupervisorOIDCDiscovery_Disruptive(t *testing.T) {
|
|
|
|
|
require.NotEqual(t, jwks3.Keys[0]["y"], jwks4.Keys[0]["y"])
|
|
|
|
|
|
|
|
|
|
// Editing a FederationDomain to change the issuer URL updates the endpoints that are being served.
|
|
|
|
|
updatedConfig4 := editFederationDomainIssuerName(t, config4, client, ns, issuer5)
|
|
|
|
|
updatedConfig4 := editFederationDomainIssuerName(t, config4, client, env.SupervisorNamespace, issuer5)
|
|
|
|
|
requireDiscoveryEndpointsAreNotFound(t, scheme, addr, caBundle, issuer4)
|
|
|
|
|
jwks5 := requireStandardDiscoveryEndpointsAreWorking(t, scheme, addr, caBundle, issuer5, nil)
|
|
|
|
|
// The JWK did not change when the issuer name was updated.
|
|
|
|
|
require.Equal(t, jwks4.Keys[0], jwks5.Keys[0])
|
|
|
|
|
|
|
|
|
|
// When they are deleted they stop serving discovery endpoints.
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config3, client, ns, scheme, addr, caBundle, issuer3)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, updatedConfig4, client, ns, scheme, addr, caBundle, issuer5)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config3, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer3)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, updatedConfig4, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer5)
|
|
|
|
|
|
|
|
|
|
// When the same issuer URL is added to two FederationDomains, both FederationDomains are marked as duplicates, and neither is serving.
|
|
|
|
|
config6Duplicate1, _ := requireCreatingFederationDomainCausesDiscoveryEndpointsToAppear(ctx, t, scheme, addr, caBundle, issuer6, client)
|
|
|
|
|
config6Duplicate2 := testlib.CreateTestFederationDomain(ctx, t, supervisorconfigv1alpha1.FederationDomainSpec{Issuer: issuer6}, supervisorconfigv1alpha1.FederationDomainPhaseError)
|
|
|
|
|
requireStatus(t, client, ns, config6Duplicate1.Name, supervisorconfigv1alpha1.FederationDomainPhaseError, withFalseConditions([]string{"Ready", "IssuerIsUnique"}))
|
|
|
|
|
requireStatus(t, client, ns, config6Duplicate2.Name, supervisorconfigv1alpha1.FederationDomainPhaseError, withFalseConditions([]string{"Ready", "IssuerIsUnique"}))
|
|
|
|
|
requireStatus(t, client, env.SupervisorNamespace, config6Duplicate1.Name, supervisorconfigv1alpha1.FederationDomainPhaseError, withFalseConditions([]string{"Ready", "IssuerIsUnique"}))
|
|
|
|
|
requireStatus(t, client, env.SupervisorNamespace, config6Duplicate2.Name, supervisorconfigv1alpha1.FederationDomainPhaseError, withFalseConditions([]string{"Ready", "IssuerIsUnique"}))
|
|
|
|
|
requireDiscoveryEndpointsAreNotFound(t, scheme, addr, caBundle, issuer6)
|
|
|
|
|
|
|
|
|
|
// If we delete the first duplicate FederationDomain, the second duplicate FederationDomain starts serving.
|
|
|
|
|
requireDelete(t, client, ns, config6Duplicate1.Name)
|
|
|
|
|
requireDelete(t, client, env.SupervisorNamespace, config6Duplicate1.Name)
|
|
|
|
|
requireWellKnownEndpointIsWorking(t, scheme, addr, caBundle, issuer6, nil)
|
|
|
|
|
requireStatus(t, client, ns, config6Duplicate2.Name, supervisorconfigv1alpha1.FederationDomainPhaseReady, withAllSuccessfulConditions())
|
|
|
|
|
requireStatus(t, client, env.SupervisorNamespace, config6Duplicate2.Name, supervisorconfigv1alpha1.FederationDomainPhaseReady, withAllSuccessfulConditions())
|
|
|
|
|
|
|
|
|
|
// When we finally delete all FederationDomains, the discovery endpoints should be down.
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config6Duplicate2, client, ns, scheme, addr, caBundle, issuer6)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config6Duplicate2, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer6)
|
|
|
|
|
|
|
|
|
|
// "Host" headers can be used to send requests to discovery endpoints when the public address is different from the issuer URL.
|
|
|
|
|
issuer7 := "https://some-issuer-host-and-port-that-doesnt-match-public-supervisor-address.com:2684/issuer7"
|
|
|
|
|
config7, _ := requireCreatingFederationDomainCausesDiscoveryEndpointsToAppear(ctx, t, scheme, addr, caBundle, issuer7, client)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config7, client, ns, scheme, addr, caBundle, issuer7)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config7, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer7)
|
|
|
|
|
|
|
|
|
|
// When we create a FederationDomain with an invalid issuer url, the status is set to invalid.
|
|
|
|
|
badConfig := testlib.CreateTestFederationDomain(ctx, t, supervisorconfigv1alpha1.FederationDomainSpec{Issuer: badIssuer}, supervisorconfigv1alpha1.FederationDomainPhaseError)
|
|
|
|
|
requireStatus(t, client, ns, badConfig.Name, supervisorconfigv1alpha1.FederationDomainPhaseError, withFalseConditions([]string{"Ready", "IssuerURLValid"}))
|
|
|
|
|
requireStatus(t, client, env.SupervisorNamespace, badConfig.Name, supervisorconfigv1alpha1.FederationDomainPhaseError, withFalseConditions([]string{"Ready", "IssuerURLValid"}))
|
|
|
|
|
requireDiscoveryEndpointsAreNotFound(t, scheme, addr, caBundle, badIssuer)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, badConfig, client, ns, scheme, addr, caBundle, badIssuer)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, badConfig, client, env.SupervisorNamespace, scheme, addr, caBundle, badIssuer)
|
|
|
|
|
|
|
|
|
|
issuer8 := fmt.Sprintf("https://%s/issuer8multipleIDP", addr)
|
|
|
|
|
config8 := requireIDPsListedByIDPDiscoveryEndpoint(t, env, ctx, kubeClient, ns, scheme, addr, caBundle, issuer8)
|
|
|
|
|
config8 := requireIDPsListedByIDPDiscoveryEndpoint(t, env, ctx, kubeClient, env.SupervisorNamespace, scheme, addr, caBundle, issuer8)
|
|
|
|
|
|
|
|
|
|
// requireJWKSEndpointIsWorking() will give us a bit of an idea what to do...
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config8, client, ns, scheme, addr, caBundle, issuer8)
|
|
|
|
|
requireDeletingFederationDomainCausesDiscoveryEndpointsToDisappear(t, config8, client, env.SupervisorNamespace, scheme, addr, caBundle, issuer8)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -172,7 +173,6 @@ func TestSupervisorTLSTerminationWithSNI_Disruptive(t *testing.T) {
|
|
|
|
|
pinnipedClient := testlib.NewSupervisorClientset(t)
|
|
|
|
|
kubeClient := testlib.NewKubernetesClientset(t)
|
|
|
|
|
|
|
|
|
|
ns := env.SupervisorNamespace
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
@@ -182,7 +182,7 @@ func TestSupervisorTLSTerminationWithSNI_Disruptive(t *testing.T) {
|
|
|
|
|
Client: idpv1alpha1.OIDCClient{SecretName: "this-will-not-exist-but-does-not-matter"},
|
|
|
|
|
}, idpv1alpha1.PhaseError)
|
|
|
|
|
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, ns, env.DefaultTLSCertSecretName(), pinnipedClient, kubeClient)
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, env.SupervisorNamespace, env.DefaultTLSCertSecretName(), pinnipedClient, kubeClient)
|
|
|
|
|
|
|
|
|
|
scheme := "https"
|
|
|
|
|
supervisorIssuer := testlib.NewSupervisorIssuer(t, env.SupervisorHTTPSAddress)
|
|
|
|
@@ -203,20 +203,31 @@ func TestSupervisorTLSTerminationWithSNI_Disruptive(t *testing.T) {
|
|
|
|
|
requireEndpointHasBootstrapTLSErrorBecauseCertificatesAreNotReady(t, issuer1)
|
|
|
|
|
|
|
|
|
|
// Create the Secret.
|
|
|
|
|
ca1 := createTLSCertificateSecret(ctx, t, ns, supervisorIssuer, certSecretName1, kubeClient)
|
|
|
|
|
ca1 := createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx,
|
|
|
|
|
t,
|
|
|
|
|
env,
|
|
|
|
|
supervisorIssuer,
|
|
|
|
|
certSecretName1,
|
|
|
|
|
kubeClient,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Now that the Secret exists, we should be able to access the endpoints by hostname using the CA.
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, address, string(ca1.Bundle()), issuer1, nil)
|
|
|
|
|
|
|
|
|
|
// Delete the default TLS secret as well
|
|
|
|
|
err := kubeClient.CoreV1().Secrets(env.SupervisorNamespace).Delete(ctx, env.DefaultTLSCertSecretName(), metav1.DeleteOptions{})
|
|
|
|
|
require.True(t, err == nil || apierrors.IsNotFound(err), "unexpected error when deleting the default secret: %s", err)
|
|
|
|
|
|
|
|
|
|
// Update the config to with a new .spec.tls.secretName.
|
|
|
|
|
certSecretName1update := "integration-test-cert-1-update"
|
|
|
|
|
require.NoError(t, retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
|
|
|
|
federationDomain1LatestVersion, err := pinnipedClient.ConfigV1alpha1().FederationDomains(ns).Get(ctx, federationDomain1.Name, metav1.GetOptions{})
|
|
|
|
|
federationDomain1LatestVersion, err := pinnipedClient.ConfigV1alpha1().FederationDomains(env.SupervisorNamespace).Get(ctx, federationDomain1.Name, metav1.GetOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
federationDomain1LatestVersion.Spec.TLS = &supervisorconfigv1alpha1.FederationDomainTLSSpec{SecretName: certSecretName1update}
|
|
|
|
|
_, err = pinnipedClient.ConfigV1alpha1().FederationDomains(ns).Update(ctx, federationDomain1LatestVersion, metav1.UpdateOptions{})
|
|
|
|
|
_, err = pinnipedClient.ConfigV1alpha1().FederationDomains(env.SupervisorNamespace).Update(ctx, federationDomain1LatestVersion, metav1.UpdateOptions{})
|
|
|
|
|
return err
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
@@ -224,7 +235,14 @@ func TestSupervisorTLSTerminationWithSNI_Disruptive(t *testing.T) {
|
|
|
|
|
requireEndpointHasBootstrapTLSErrorBecauseCertificatesAreNotReady(t, issuer1)
|
|
|
|
|
|
|
|
|
|
// Create a Secret at the updated name.
|
|
|
|
|
ca1update := createTLSCertificateSecret(ctx, t, ns, supervisorIssuer, certSecretName1update, kubeClient)
|
|
|
|
|
ca1update := createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx,
|
|
|
|
|
t,
|
|
|
|
|
env,
|
|
|
|
|
supervisorIssuer,
|
|
|
|
|
certSecretName1update,
|
|
|
|
|
kubeClient,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Now that the Secret exists at the new name, we should be able to access the endpoints by hostname using the CA.
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, address, string(ca1update.Bundle()), issuer1, nil)
|
|
|
|
@@ -244,7 +262,14 @@ func TestSupervisorTLSTerminationWithSNI_Disruptive(t *testing.T) {
|
|
|
|
|
requireStatus(t, pinnipedClient, federationDomain2.Namespace, federationDomain2.Name, supervisorconfigv1alpha1.FederationDomainPhaseReady, withAllSuccessfulConditions())
|
|
|
|
|
|
|
|
|
|
// Create the Secret.
|
|
|
|
|
ca2 := createTLSCertificateSecret(ctx, t, ns, testlib.NewSupervisorIssuer(t, issuer2), certSecretName2, kubeClient)
|
|
|
|
|
ca2 := createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx,
|
|
|
|
|
t,
|
|
|
|
|
env,
|
|
|
|
|
testlib.NewSupervisorIssuer(t, issuer2),
|
|
|
|
|
certSecretName2,
|
|
|
|
|
kubeClient,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Now that the Secret exists, we should be able to access the endpoints by hostname using the CA.
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, hostname2+":"+hostnamePort2, string(ca2.Bundle()), issuer2, map[string]string{
|
|
|
|
@@ -258,7 +283,6 @@ func TestSupervisorTLSTerminationWithDefaultCerts_Disruptive(t *testing.T) {
|
|
|
|
|
pinnipedClient := testlib.NewSupervisorClientset(t)
|
|
|
|
|
kubeClient := testlib.NewKubernetesClientset(t)
|
|
|
|
|
|
|
|
|
|
ns := env.SupervisorNamespace
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
@@ -268,7 +292,7 @@ func TestSupervisorTLSTerminationWithDefaultCerts_Disruptive(t *testing.T) {
|
|
|
|
|
Client: idpv1alpha1.OIDCClient{SecretName: "this-will-not-exist-but-does-not-matter"},
|
|
|
|
|
}, idpv1alpha1.PhaseError)
|
|
|
|
|
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, ns, env.DefaultTLSCertSecretName(), pinnipedClient, kubeClient)
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, env.SupervisorNamespace, env.DefaultTLSCertSecretName(), pinnipedClient, kubeClient)
|
|
|
|
|
|
|
|
|
|
scheme := "https"
|
|
|
|
|
supervisorIssuer := testlib.NewSupervisorIssuer(t, env.SupervisorHTTPSAddress)
|
|
|
|
@@ -296,7 +320,14 @@ func TestSupervisorTLSTerminationWithDefaultCerts_Disruptive(t *testing.T) {
|
|
|
|
|
requireEndpointHasBootstrapTLSErrorBecauseCertificatesAreNotReady(t, issuerUsingIPAddress)
|
|
|
|
|
|
|
|
|
|
// Create a Secret at the special name which represents the default TLS cert.
|
|
|
|
|
defaultCA := createTLSCertificateSecret(ctx, t, ns, testlib.NewSupervisorIssuer(t, issuerUsingIPAddress), env.DefaultTLSCertSecretName(), kubeClient)
|
|
|
|
|
defaultCA := createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx,
|
|
|
|
|
t,
|
|
|
|
|
env,
|
|
|
|
|
testlib.NewSupervisorIssuer(t, issuerUsingIPAddress),
|
|
|
|
|
env.DefaultTLSCertSecretName(),
|
|
|
|
|
kubeClient,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Now that the Secret exists, we should be able to access the endpoints by IP address using the CA.
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, ipWithPort, string(defaultCA.Bundle()), issuerUsingIPAddress, nil)
|
|
|
|
@@ -311,57 +342,84 @@ func TestSupervisorTLSTerminationWithDefaultCerts_Disruptive(t *testing.T) {
|
|
|
|
|
requireStatus(t, pinnipedClient, federationDomain2.Namespace, federationDomain2.Name, supervisorconfigv1alpha1.FederationDomainPhaseReady, withAllSuccessfulConditions())
|
|
|
|
|
|
|
|
|
|
// Create the Secret.
|
|
|
|
|
certCA := createTLSCertificateSecret(ctx, t, ns, supervisorIssuer, certSecretName, kubeClient)
|
|
|
|
|
certCA := createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx,
|
|
|
|
|
t,
|
|
|
|
|
env,
|
|
|
|
|
supervisorIssuer,
|
|
|
|
|
certSecretName,
|
|
|
|
|
kubeClient,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Now that the Secret exists, we should be able to access the endpoints by hostname using the CA from the SNI cert.
|
|
|
|
|
// Hostnames are case-insensitive, so the request should still work even if the case of the hostname is different
|
|
|
|
|
// from the case of the issuer URL's hostname.
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, strings.ToUpper(hostname)+":"+port, string(certCA.Bundle()), issuerUsingHostname, nil)
|
|
|
|
|
|
|
|
|
|
// And we can still access the other issuer using the default cert.
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, ipWithPort, string(defaultCA.Bundle()), issuerUsingIPAddress, nil)
|
|
|
|
|
if !supervisorIssuer.IsIPAddress() {
|
|
|
|
|
// And we can still access the other issuer using the default cert,
|
|
|
|
|
// except when we have an IP address, because in that case we just overwrote the default cert
|
|
|
|
|
_ = requireStandardDiscoveryEndpointsAreWorking(t, scheme, ipWithPort, string(defaultCA.Bundle()), issuerUsingIPAddress, nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createTLSCertificateSecret(
|
|
|
|
|
func createTLSServingCertSecretForSupervisor(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
t *testing.T,
|
|
|
|
|
namespace string,
|
|
|
|
|
env *testlib.TestEnv,
|
|
|
|
|
supervisorIssuer testlib.SupervisorIssuer,
|
|
|
|
|
secretName string,
|
|
|
|
|
kubeClient kubernetes.Interface,
|
|
|
|
|
) *certauthority.CA {
|
|
|
|
|
// If the issuer is an IP address, then we have to create/update the DEFAULT cert, not the given secret
|
|
|
|
|
if supervisorIssuer.IsIPAddress() {
|
|
|
|
|
secretName = env.DefaultTLSCertSecretName()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a CA.
|
|
|
|
|
ca, err := certauthority.New("Acme Corp", 1000*time.Hour)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Using the CA, create a TLS server cert.
|
|
|
|
|
// Using the CA, create a TLS serving cert.
|
|
|
|
|
certPEM, keyPEM := supervisorIssuer.IssuerServerCert(t, ca)
|
|
|
|
|
|
|
|
|
|
// Write the serving cert to the SNI secret.
|
|
|
|
|
secret := corev1.Secret{
|
|
|
|
|
Type: corev1.SecretTypeTLS,
|
|
|
|
|
TypeMeta: metav1.TypeMeta{},
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
Name: secretName,
|
|
|
|
|
Namespace: namespace,
|
|
|
|
|
secret := &applycorev1.SecretApplyConfiguration{
|
|
|
|
|
TypeMetaApplyConfiguration: applymetav1.TypeMetaApplyConfiguration{
|
|
|
|
|
Kind: ptr.To("Secret"),
|
|
|
|
|
APIVersion: ptr.To("v1"),
|
|
|
|
|
},
|
|
|
|
|
Type: ptr.To(corev1.SecretTypeTLS),
|
|
|
|
|
ObjectMetaApplyConfiguration: &applymetav1.ObjectMetaApplyConfiguration{
|
|
|
|
|
Name: ptr.To(secretName),
|
|
|
|
|
Namespace: ptr.To(env.SupervisorNamespace),
|
|
|
|
|
},
|
|
|
|
|
StringData: map[string]string{
|
|
|
|
|
"tls.crt": string(certPEM),
|
|
|
|
|
"tls.key": string(keyPEM),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
_, err = kubeClient.CoreV1().Secrets(namespace).Create(ctx, &secret, metav1.CreateOptions{})
|
|
|
|
|
|
|
|
|
|
_, err = kubeClient.CoreV1().Secrets(env.SupervisorNamespace).Apply(ctx, secret, metav1.ApplyOptions{FieldManager: "pinniped-integration-tests"})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
t.Logf("wrote TLS cert secret to: %s/%s", namespace, secretName)
|
|
|
|
|
t.Logf("wrote TLS cert secret to: %s/%s", env.SupervisorNamespace, secretName)
|
|
|
|
|
|
|
|
|
|
// Delete the Secret when the test ends.
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
t.Helper()
|
|
|
|
|
deleteCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
|
|
|
defer cancel()
|
|
|
|
|
err := kubeClient.CoreV1().Secrets(namespace).Delete(deleteCtx, secretName, metav1.DeleteOptions{})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
// check to see if it exists (so that the default TLS secret doesn't get deleted multiple times)
|
|
|
|
|
secret, err := kubeClient.CoreV1().Secrets(env.SupervisorNamespace).Get(deleteCtx, secretName, metav1.GetOptions{})
|
|
|
|
|
require.True(t, err == nil || apierrors.IsNotFound(err), "unexpected error when getting secret %s/%s: %s",
|
|
|
|
|
env.SupervisorNamespace,
|
|
|
|
|
secretName,
|
|
|
|
|
err)
|
|
|
|
|
|
|
|
|
|
if err == nil && secret != nil {
|
|
|
|
|
err = kubeClient.CoreV1().Secrets(env.SupervisorNamespace).Delete(deleteCtx, secretName, metav1.DeleteOptions{})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ca
|
|
|
|
@@ -602,7 +660,7 @@ func printServerCert(t *testing.T, address string, dnsOverrides map[string]strin
|
|
|
|
|
|
|
|
|
|
host := addressURL.Host
|
|
|
|
|
if _, ok := dnsOverrides[host]; ok {
|
|
|
|
|
host = dnsOverrides[address]
|
|
|
|
|
host = dnsOverrides[host]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conn, err := tls.Dial("tcp", host, conf)
|
|
|
|
|