-
Notifications
You must be signed in to change notification settings - Fork 223
OCPBUGS-9037: If mTLS is required and the canary receives a "certificate required" TLS error, consider the canary probe successful #961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,15 +6,18 @@ package e2e | |
| import ( | ||
| "bufio" | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| routev1 "github.com/openshift/api/route/v1" | ||
|
|
||
| "github.com/openshift/cluster-ingress-operator/pkg/operator/controller" | ||
| canarycontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/canary" | ||
| ingresscontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/ingress" | ||
|
|
||
| "sigs.k8s.io/controller-runtime/pkg/client/config" | ||
|
|
||
|
|
@@ -160,3 +163,98 @@ func buildCanaryCurlPod(name, namespace, image, host string) *corev1.Pod { | |
| }, | ||
| } | ||
| } | ||
|
|
||
| func TestCanaryWithMTLS(t *testing.T) { | ||
| defaultIC := &operatorv1.IngressController{} | ||
| if err := waitForIngressControllerCondition(t, kclient, 5*time.Minute, defaultName, defaultAvailableConditions...); err != nil { | ||
| t.Fatalf("failed to observe expected conditions: %v", err) | ||
| } | ||
|
|
||
| caCert := MustCreateTLSKeyCert("root-ca", time.Now(), time.Now().Add(24*time.Hour), true, nil, nil) | ||
|
|
||
| clientCAConfigmap := &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "canary-with-mtls-client-ca", | ||
| Namespace: "openshift-config", | ||
| }, | ||
| Data: map[string]string{ | ||
| "ca-bundle.pem": caCert.CertPem, | ||
| }, | ||
| } | ||
|
|
||
| if err := kclient.Create(context.TODO(), clientCAConfigmap); err != nil { | ||
| t.Fatalf("Failed to create configmap %s: %v", clientCAConfigmap.Name, err) | ||
| } | ||
|
|
||
| defer assertDeleted(t, kclient, clientCAConfigmap) | ||
|
|
||
| if err := kclient.Get(context.TODO(), defaultName, defaultIC); err != nil { | ||
| t.Fatalf("failed to get default ingresscontroller: %v", err) | ||
| } | ||
|
|
||
| // Save the current clientTLS config so it can be restored at the end of the test. | ||
| originalClientTLS := defaultIC.Spec.ClientTLS | ||
|
|
||
| // Set client TLS (mTLS) to required, and use clientCAConfigmap as the CA bundle. | ||
| defaultIC.Spec.ClientTLS = operatorv1.ClientTLS{ | ||
| ClientCertificatePolicy: operatorv1.ClientCertificatePolicyRequired, | ||
| ClientCA: configv1.ConfigMapNameReference{ | ||
| Name: clientCAConfigmap.Name, | ||
| }, | ||
| } | ||
| if err := kclient.Update(context.TODO(), defaultIC); err != nil { | ||
| t.Fatalf("Failed to enable mTLS on default ingress controller: %v", err) | ||
| } | ||
|
|
||
| defer func() { | ||
| // Reset client TLS. | ||
| if err := kclient.Get(context.TODO(), defaultName, defaultIC); err != nil { | ||
| panic(fmt.Errorf("failed to get default ingresscontroller: %v", err)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to panic here. We can just call t.Fatal. |
||
| } | ||
| defaultIC.Spec.ClientTLS = originalClientTLS | ||
| if err := kclient.Update(context.TODO(), defaultIC); err != nil { | ||
| panic(fmt.Errorf("Failed to restore default ingress configuration: %w", err)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to panic here. We can just call t.Fatal. |
||
| } | ||
| }() | ||
|
|
||
| // Wait for IC update to completely roll out. | ||
| routerDeployment := &appsv1.Deployment{} | ||
| routerDeploymentName := controller.RouterDeploymentName(defaultIC) | ||
| if err := kclient.Get(context.TODO(), routerDeploymentName, routerDeployment); err != nil { | ||
| t.Fatalf("Failed to get router deployment for ingresscontroller %s: %v", defaultIC.Name, err) | ||
| } | ||
|
|
||
| if err := waitForDeploymentComplete(t, kclient, routerDeployment, 3*time.Minute); err != nil { | ||
| t.Fatalf("Timed out waiting for ingress update to complete: %v", err) | ||
| } | ||
|
|
||
| // Verify that canary does not fail. | ||
| err := wait.PollImmediate(10*time.Second, 6*time.Minute, func() (bool, error) { | ||
| ic := &operatorv1.IngressController{} | ||
| if err := kclient.Get(context.TODO(), defaultName, ic); err != nil { | ||
| return false, err | ||
| } | ||
| foundCondition := false | ||
| for _, condition := range ic.Status.Conditions { | ||
| if condition.Type == ingresscontroller.IngressControllerCanaryCheckSuccessConditionType { | ||
| foundCondition = true | ||
| if condition.Status == operatorv1.ConditionFalse { | ||
| t.Errorf("Canary failed: %s", condition.Reason) | ||
| return true, nil | ||
| } | ||
| break | ||
| } | ||
| } | ||
| if !foundCondition { | ||
| t.Errorf("Canary status condition not found") | ||
| return false, nil | ||
| } | ||
| return false, nil | ||
| }) | ||
|
|
||
| // Timeout means the canary succeeded for the entire polling interval, so only consider non-timeout errors a | ||
| // failure. | ||
| if err != nil && err != wait.ErrWaitTimeout { | ||
| t.Fatalf("Got unexpected error %v", err) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this message the same in a FIPS-enabled cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is the same on FIPS, although as we discussed out-of-band, I need to see if the message is the same in all TLS versions since it was added in TLS 1.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we summarise the testing you've already done with different TLS profiles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to summarize the testing with TLS profiles:
We only allow users to set the minimum TLS version, not the maximum. The canary checks are between the router and the ingress-operator pods, both of which support TLS 1.3, so regardless of what the minimum is set to, the connection gets negotiated to v1.3, so we get teh expected "certificate required" error.