-
Notifications
You must be signed in to change notification settings - Fork 567
CNTRLPLANE-2910: feat(cpo): add Azure workload identity webhook as KAS sidecar #7867
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
Merged
openshift-merge-bot
merged 2 commits into
openshift:main
from
csrwng:azure-web-identity-webhook
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions
11
control-plane-operator/controllers/hostedcontrolplane/pki/azure_workload_identity_webhook.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,11 @@ | ||
| package pki | ||
|
|
||
| import ( | ||
| "github.com/openshift/hypershift/support/config" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| ) | ||
|
|
||
| func ReconcileAzureWorkloadIdentityWebhookServingCert(secret, ca *corev1.Secret, ownerRef config.OwnerRef) error { | ||
| return reconcileSignedCertWithAddresses(secret, ca, ownerRef, "127.0.0.1", nil, X509UsageClientServerAuth, nil, []string{"127.0.0.1"}) | ||
| } |
128 changes: 128 additions & 0 deletions
128
...plane-operator/controllers/hostedcontrolplane/pki/azure_workload_identity_webhook_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,128 @@ | ||
| package pki | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "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" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/utils/ptr" | ||
| ) | ||
|
|
||
| func TestReconcileAzureWorkloadIdentityWebhookServingCert(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| }{ | ||
| { | ||
| name: "When reconciling the serving cert it should generate a valid TLS certificate for 127.0.0.1", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| namespace := "test-namespace" | ||
|
|
||
| ownerRef := config.OwnerRef{ | ||
| Reference: &metav1.OwnerReference{ | ||
| APIVersion: "v1", | ||
| Kind: "HostedControlPlane", | ||
| Name: "test-hcp", | ||
| UID: types.UID("test-uid"), | ||
| Controller: ptr.To(true), | ||
| }, | ||
| } | ||
|
|
||
| ca := &corev1.Secret{} | ||
| ca.Name = "test-ca" | ||
| ca.Namespace = namespace | ||
| if err := reconcileSelfSignedCA(ca, ownerRef, "test-org", "test-ca"); err != nil { | ||
| t.Fatalf("failed to create CA: %v", err) | ||
| } | ||
|
|
||
| secret := &corev1.Secret{} | ||
| secret.Name = "azure-workload-identity-webhook-serving-cert" | ||
| secret.Namespace = namespace | ||
|
|
||
| if err := ReconcileAzureWorkloadIdentityWebhookServingCert(secret, ca, ownerRef); err != nil { | ||
| t.Fatalf("failed to reconcile cert: %v", err) | ||
| } | ||
|
|
||
| if secret.Data == nil { | ||
| t.Fatal("secret data is nil") | ||
| } | ||
|
|
||
| if _, ok := secret.Data[corev1.TLSCertKey]; !ok { | ||
| t.Fatal("secret missing tls.crt") | ||
| } | ||
|
|
||
| if _, ok := secret.Data[corev1.TLSPrivateKeyKey]; !ok { | ||
| t.Fatal("secret missing tls.key") | ||
| } | ||
|
|
||
| cert, err := certs.PemToCertificate(secret.Data[corev1.TLSCertKey]) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse certificate: %v", err) | ||
| } | ||
|
|
||
| // The cert should have 127.0.0.1 as an IP SAN | ||
| if len(cert.IPAddresses) != 1 || cert.IPAddresses[0].String() != "127.0.0.1" { | ||
| t.Errorf("expected IP SAN [127.0.0.1], got %v", cert.IPAddresses) | ||
| } | ||
|
|
||
| // The CN should be 127.0.0.1 | ||
| if cert.Subject.CommonName != "127.0.0.1" { | ||
| t.Errorf("expected CN 127.0.0.1, got %s", cert.Subject.CommonName) | ||
| } | ||
|
|
||
| // IP-only certs generated by reconcileSignedCertWithAddresses do not set an organization | ||
| if len(cert.Subject.Organization) != 0 { | ||
| t.Errorf("expected empty Organization for IP-based cert, got %v", cert.Subject.Organization) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestReconcileAzureWorkloadIdentityWebhookServingCertIdempotent(t *testing.T) { | ||
| t.Run("When reconciling the serving cert twice it should produce the same certificate", func(t *testing.T) { | ||
| namespace := "test-namespace" | ||
|
|
||
| ownerRef := config.OwnerRef{ | ||
| Reference: &metav1.OwnerReference{ | ||
| APIVersion: "v1", | ||
| Kind: "HostedControlPlane", | ||
| Name: "test-hcp", | ||
| UID: types.UID("test-uid"), | ||
| Controller: ptr.To(true), | ||
| }, | ||
| } | ||
|
|
||
| ca := &corev1.Secret{} | ||
| ca.Name = "test-ca" | ||
| ca.Namespace = namespace | ||
| if err := reconcileSelfSignedCA(ca, ownerRef, "test-org", "test-ca"); err != nil { | ||
| t.Fatalf("failed to create CA: %v", err) | ||
| } | ||
|
|
||
| secret := &corev1.Secret{} | ||
| secret.Name = "azure-workload-identity-webhook-serving-cert" | ||
| secret.Namespace = namespace | ||
|
|
||
| if err := ReconcileAzureWorkloadIdentityWebhookServingCert(secret, ca, ownerRef); err != nil { | ||
| t.Fatalf("first reconcile failed: %v", err) | ||
| } | ||
|
|
||
| firstCert := make([]byte, len(secret.Data[corev1.TLSCertKey])) | ||
| copy(firstCert, secret.Data[corev1.TLSCertKey]) | ||
|
|
||
| if err := ReconcileAzureWorkloadIdentityWebhookServingCert(secret, ca, ownerRef); err != nil { | ||
| t.Fatalf("second reconcile failed: %v", err) | ||
| } | ||
|
|
||
| if string(firstCert) != string(secret.Data[corev1.TLSCertKey]) { | ||
| t.Error("expected idempotent reconciliation to produce the same certificate") | ||
| } | ||
| }) | ||
| } |
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
23 changes: 23 additions & 0 deletions
23
...fixture_TestControlPlaneComponents_azure_workload_identity_webhook_kubeconfig_secret.yaml
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,23 @@ | ||
| apiVersion: v1 | ||
| data: | ||
| ca.crt: "" | ||
| kubeconfig: "" | ||
| tls.crt: "" | ||
| tls.key: "" | ||
| kind: Secret | ||
| metadata: | ||
| annotations: | ||
| hypershiftlite.openshift.io/ca-hash: "" | ||
| labels: | ||
| hypershift.openshift.io/kubeconfig: local | ||
| name: azure-workload-identity-webhook-kubeconfig | ||
| namespace: hcp-namespace | ||
| ownerReferences: | ||
| - apiVersion: hypershift.openshift.io/v1beta1 | ||
| blockOwnerDeletion: true | ||
| controller: true | ||
| kind: HostedControlPlane | ||
| name: hcp | ||
| uid: "" | ||
| resourceVersion: "1" | ||
| type: Opaque |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.