Skip to content
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

MIWI - Provide boundServiceAccountSigningKey secret to Hive Install #3877

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/hive/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (c *clusterManager) Install(ctx context.Context, sub *api.SubscriptionDocum
if err != nil {
return err
}
boundSASigningKeySecret, err := boundSASigningKeySecret(doc.OpenShiftCluster.Properties.HiveProfile.Namespace, doc.OpenShiftCluster)
if err != nil {
return err
}

resources := []kruntime.Object{
azureCredentialSecret,
Expand All @@ -89,6 +93,13 @@ func (c *clusterManager) Install(ctx context.Context, sub *api.SubscriptionDocum
cd,
}

if boundSASigningKeySecret != nil {
resources = append(resources, boundSASigningKeySecret)
cd.Spec.BoundServiceAccountSignkingKeySecretRef = &corev1.LocalObjectReference{
Name: boundSASigningKeySecret.ObjectMeta.Name,
}
}

err = dynamichelper.Prepare(resources)
if err != nil {
return err
Expand Down
30 changes: 26 additions & 4 deletions pkg/hive/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
// Changing values of these constants most likely would require
// some sort of migration on the Hive cluster for existing clusters.
const (
ClusterDeploymentName = "cluster"
aroServiceKubeconfigSecretName = "aro-service-kubeconfig-secret"
clusterServicePrincipalSecretName = "cluster-service-principal-secret"
clusterManifestsSecretName = "cluster-manifests-secret"
ClusterDeploymentName = "cluster"
aroServiceKubeconfigSecretName = "aro-service-kubeconfig-secret"
clusterServicePrincipalSecretName = "cluster-service-principal-secret"
clusterManifestsSecretName = "cluster-manifests-secret"
boundServiceAccountSigningKeySecretName = "bound-service-account-signing-key"
boundServiceAccountSigningKeySecretKey = "bound-service-account-signing-key.key"
)

var (
Expand Down Expand Up @@ -144,6 +146,26 @@ func clusterManifestsSecret(namespace string, customManifests map[string]kruntim
return secret, nil
}

func boundSASigningKeySecret(namespace string, oc *api.OpenShiftCluster) (*corev1.Secret, error) {
if !oc.UsesWorkloadIdentity() {
// no secret required - Hive ClusterDeployment should not reference this secret
return nil, nil
}
if oc.Properties.ClusterProfile.BoundServiceAccountSigningKey == nil {
return nil, fmt.Errorf("properties.clusterProfile.boundServiceAccountSigningKey not set")
}
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: boundServiceAccountSigningKeySecretName,
Namespace: namespace,
},
StringData: map[string]string{
boundServiceAccountSigningKeySecretKey: string(*oc.Properties.ClusterProfile.BoundServiceAccountSigningKey),
},
Type: corev1.SecretTypeOpaque,
}, nil
}

func envSecret(namespace string, isDevelopment bool) *corev1.Secret {
stringdata := map[string]string{}

Expand Down
59 changes: 59 additions & 0 deletions pkg/hive/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"testing"

"github.com/go-test/deep"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kruntime "k8s.io/apimachinery/pkg/runtime"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/pointerutils"
utilerror "github.com/Azure/ARO-RP/test/util/error"
)

func TestInstallConfigMap(t *testing.T) {
Expand Down Expand Up @@ -112,3 +115,59 @@ func TestClusterAzureSecret(t *testing.T) {
})
}
}

func TestBoundSASigningKeySecret(t *testing.T) {
testNamespace := "aro-UUID"
for _, tt := range []struct {
name string
oc *api.OpenShiftCluster
wantSecret *corev1.Secret
wantErr string
}{
{
name: "csp cluster - returns nil",
oc: &api.OpenShiftCluster{
Properties: api.OpenShiftClusterProperties{
ServicePrincipalProfile: &api.ServicePrincipalProfile{},
},
},
},
{
name: "miwi cluster - boundServiceAccountSigningKey not set - returns error",
oc: &api.OpenShiftCluster{
Properties: api.OpenShiftClusterProperties{
PlatformWorkloadIdentityProfile: &api.PlatformWorkloadIdentityProfile{},
ClusterProfile: api.ClusterProfile{},
},
},
wantErr: "properties.clusterProfile.boundServiceAccountSigningKey not set",
},
{
name: "miwi cluster - creates secret with bound-service-account-signing-key.key contents",
oc: &api.OpenShiftCluster{
Properties: api.OpenShiftClusterProperties{
PlatformWorkloadIdentityProfile: &api.PlatformWorkloadIdentityProfile{},
ClusterProfile: api.ClusterProfile{
BoundServiceAccountSigningKey: pointerutils.ToPtr(api.SecureString("fakeboundserviceaccountsigningkey")),
},
},
},
wantSecret: &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: boundServiceAccountSigningKeySecretName,
Namespace: testNamespace,
},
Type: corev1.SecretTypeOpaque,
StringData: map[string]string{
boundServiceAccountSigningKeySecretKey: "fakeboundserviceaccountsigningkey",
},
},
},
} {
t.Run(tt.name, func(t *testing.T) {
secret, err := boundSASigningKeySecret(testNamespace, tt.oc)
utilerror.AssertErrorMessage(t, err, tt.wantErr)
assert.Equal(t, tt.wantSecret, secret)
})
}
}
Loading