-
Notifications
You must be signed in to change notification settings - Fork 482
OCPBUGS-76530: Fix intermittent etcd peer communication failures #8479
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
Open
vsolanki12
wants to merge
1
commit into
openshift:main
Choose a base branch
from
vsolanki12:OCPBUGS-76530-etcd-peer-cert-san
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+83
−0
Open
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
Some comments aren't visible on the classic Files Changed page.
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
81 changes: 81 additions & 0 deletions
81
control-plane-operator/controllers/hostedcontrolplane/pki/etcd_test.go
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package pki | ||
|
|
||
| import ( | ||
| "crypto/x509" | ||
| "crypto/x509/pkix" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/openshift/hypershift/support/certs" | ||
| "github.com/openshift/hypershift/support/config" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestReconcileEtcdPeerSecret(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| caCfg := certs.CertCfg{ | ||
| IsCA: true, | ||
| Subject: pkix.Name{CommonName: "etcd-signer", OrganizationalUnit: []string{"openshift"}}, | ||
| } | ||
| caKey, caCert, err := certs.GenerateSelfSignedCertificate(&caCfg) | ||
| if err != nil { | ||
| t.Fatalf("failed to generate CA: %v", err) | ||
| } | ||
| caSecret := &corev1.Secret{ | ||
| Data: map[string][]byte{ | ||
| certs.CASignerCertMapKey: certs.CertToPem(caCert), | ||
| certs.CASignerKeyMapKey: certs.PrivateKeyToPem(caKey), | ||
| }, | ||
| } | ||
|
|
||
| t.Run("When reconciling etcd peer secret it should include both etcd-discovery and etcd-client SANs", func(t *testing.T) { | ||
| g := NewWithT(t) | ||
| secret := &corev1.Secret{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "clusters-test", | ||
| }, | ||
| } | ||
|
|
||
| err := ReconcileEtcdPeerSecret(secret, caSecret, config.OwnerRef{}) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| certData := secret.Data[EtcdPeerCrtKey] | ||
| g.Expect(certData).ToNot(BeEmpty()) | ||
|
|
||
| cert, err := certs.PemToCertificate(certData) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| g.Expect(cert.DNSNames).To(ContainElements( | ||
| "*.etcd-discovery.clusters-test.svc", | ||
| "*.etcd-discovery.clusters-test.svc.cluster.local", | ||
| "*.etcd-client.clusters-test.svc", | ||
| "*.etcd-client.clusters-test.svc.cluster.local", | ||
| "127.0.0.1", | ||
| "::1", | ||
| )) | ||
| }) | ||
|
|
||
| t.Run("When reconciling etcd peer secret it should have client and server auth usage", func(t *testing.T) { | ||
| g := NewWithT(t) | ||
| secret := &corev1.Secret{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "clusters-test", | ||
| }, | ||
| } | ||
|
|
||
| err := ReconcileEtcdPeerSecret(secret, caSecret, config.OwnerRef{}) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| cert, err := certs.PemToCertificate(secret.Data[EtcdPeerCrtKey]) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| g.Expect(cert.ExtKeyUsage).To(ContainElements( | ||
| x509.ExtKeyUsageClientAuth, | ||
| x509.ExtKeyUsageServerAuth, | ||
| )) | ||
| }) | ||
| } | ||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 2726
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 1123
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 1324
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 6056
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 2748
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 1305
Fix IP address handling in etcd peer certificate generation.
Lines 50–51 in
etcd.goincorrectly add IP addresses ("127.0.0.1","::1") to thednsNameslist. Per X.509 standards, IP addresses must be in theIPAddressesfield, notDNSNames. The function signature supports a separateipsparameter for this purpose.Fix the implementation by passing IPs via the dedicated parameter:
Then update the test assertion to check the correct certificate field:
🤖 Prompt for AI Agents