-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4888 from bryan-cox/aro-hcp-image-reg-cert-deploy…
…ment HOSTEDCP-2022: Reconcile SecretProviderClass for Image Registry on ARO HCP
- Loading branch information
Showing
11 changed files
with
211 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 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 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
39 changes: 2 additions & 37 deletions
39
control-plane-operator/controllers/hostedcontrolplane/manifests/secretproviderclass.go
This file contains 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 |
---|---|---|
@@ -1,50 +1,15 @@ | ||
package manifests | ||
|
||
import ( | ||
"fmt" | ||
"github.com/openshift/hypershift/support/azureutil" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
secretsstorev1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1" | ||
) | ||
|
||
const ( | ||
objectFormat = ` | ||
array: | ||
- | | ||
objectName: %s | ||
objectType: secret | ||
` | ||
) | ||
|
||
// ManagedAzureKeyVaultSecretProviderClass returns an instance of a SecretProviderClass completed with its name, Azure Key Vault set | ||
// up, and the certificate name it needs to pull from the Key Vault. | ||
// | ||
// https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access?tabs=azure-portal&pivots=access-with-a-user-assigned-managed-identity | ||
func ManagedAzureKeyVaultSecretProviderClass(secretProviderClassName, namespace, keyVaultName, KeyVaultTenantID, certificateName string) *secretsstorev1.SecretProviderClass { | ||
func ManagedAzureSecretProviderClass(name, namespace string) *secretsstorev1.SecretProviderClass { | ||
return &secretsstorev1.SecretProviderClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretProviderClassName, | ||
Name: name, | ||
Namespace: namespace, | ||
}, | ||
Spec: secretsstorev1.SecretProviderClassSpec{ | ||
Provider: "azure", | ||
Parameters: map[string]string{ | ||
"usePodIdentity": "false", | ||
"useVMManagedIdentity": "true", | ||
"userAssignedIdentityID": azureutil.GetKeyVaultAuthorizedUser(), | ||
"keyvaultName": keyVaultName, | ||
"tenantId": KeyVaultTenantID, | ||
"objects": formatSecretProviderClassObject(certificateName), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// formatSecretProviderClassObject places the certificate name in the appropriate string structure the | ||
// SecretProviderClass expects for an object. More details here: | ||
// - https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access?tabs=azure-portal&pivots=access-with-a-user-assigned-managed-identity#configure-managed-identity | ||
// - https://secrets-store-csi-driver.sigs.k8s.io/concepts.html?highlight=object#custom-resource-definitions-crds | ||
func formatSecretProviderClassObject(certName string) string { | ||
return fmt.Sprintf(objectFormat, certName) | ||
} |
This file contains 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
44 changes: 44 additions & 0 deletions
44
...-plane-operator/controllers/hostedcontrolplane/secretproviderclass/secretproviderclass.go
This file contains 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,44 @@ | ||
package secretproviderclass | ||
|
||
import ( | ||
"fmt" | ||
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" | ||
"github.com/openshift/hypershift/support/azureutil" | ||
|
||
secretsstorev1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1" | ||
) | ||
|
||
const ( | ||
objectFormat = ` | ||
array: | ||
- | | ||
objectName: %s | ||
objectType: secret | ||
` | ||
) | ||
|
||
// ReconcileManagedAzureSecretProviderClass reconciles the Spec of a SecretProviderClass completed with its name, Azure | ||
// Key Vault setup, and the certificate name it needs to pull from the Key Vault. | ||
// | ||
// https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access?tabs=azure-portal&pivots=access-with-a-user-assigned-managed-identity | ||
func ReconcileManagedAzureSecretProviderClass(secretProviderClass *secretsstorev1.SecretProviderClass, hcp *hyperv1.HostedControlPlane, certName string) { | ||
secretProviderClass.Spec = secretsstorev1.SecretProviderClassSpec{ | ||
Provider: "azure", | ||
Parameters: map[string]string{ | ||
"usePodIdentity": "false", | ||
"useVMManagedIdentity": "true", | ||
"userAssignedIdentityID": azureutil.GetKeyVaultAuthorizedUser(), | ||
"keyvaultName": hcp.Spec.Platform.Azure.ManagedIdentities.ControlPlane.ManagedIdentitiesKeyVault.Name, | ||
"tenantId": hcp.Spec.Platform.Azure.ManagedIdentities.ControlPlane.ManagedIdentitiesKeyVault.TenantID, | ||
"objects": formatSecretProviderClassObject(certName), | ||
}, | ||
} | ||
} | ||
|
||
// formatSecretProviderClassObject places the certificate name in the appropriate string structure the | ||
// SecretProviderClass expects for an object. More details here: | ||
// - https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access?tabs=azure-portal&pivots=access-with-a-user-assigned-managed-identity#configure-managed-identity | ||
// - https://secrets-store-csi-driver.sigs.k8s.io/concepts.html?highlight=object#custom-resource-definitions-crds | ||
func formatSecretProviderClassObject(certName string) string { | ||
return fmt.Sprintf(objectFormat, certName) | ||
} |
This file contains 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 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 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.