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

[release-0.19] Encode username and password in Kubernetes secrets #7833

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
12 changes: 9 additions & 3 deletions pkg/clustermanager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"encoding/base64"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -743,6 +744,11 @@ func compareEKSAClusterSpec(ctx context.Context, currentClusterSpec, newClusterS

// CreateRegistryCredSecret creates the registry-credentials secret on a managment cluster.
func (c *ClusterManager) CreateRegistryCredSecret(ctx context.Context, mgmt *types.Cluster) error {
registryUsername := os.Getenv("REGISTRY_USERNAME")
encodedRegistryUsername := base64.StdEncoding.EncodeToString([]byte(registryUsername))
registryPassword := os.Getenv("REGISTRY_PASSWORD")
encodedRegistryPassword := base64.StdEncoding.EncodeToString([]byte(registryPassword))

secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
Expand All @@ -752,9 +758,9 @@ func (c *ClusterManager) CreateRegistryCredSecret(ctx context.Context, mgmt *typ
Namespace: constants.EksaSystemNamespace,
Name: "registry-credentials",
},
StringData: map[string]string{
"username": os.Getenv("REGISTRY_USERNAME"),
"password": os.Getenv("REGISTRY_PASSWORD"),
Data: map[string][]byte{
"username": []byte(encodedRegistryUsername),
"password": []byte(encodedRegistryPassword),
},
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/clustermanager/cluster_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2955,9 +2955,9 @@ func TestCreateRegistryCredSecretSuccess(t *testing.T) {
Namespace: constants.EksaSystemNamespace,
Name: "registry-credentials",
},
StringData: map[string]string{
"username": "",
"password": "",
Data: map[string][]byte{
"username": []byte(""),
"password": []byte(""),
},
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/providers/docker/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ metadata:
namespace: {{.eksaSystemNamespace}}
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "{{.registryUsername}}"
password: "{{.registryPassword}}"
data:
username: {{.registryUsername | b64enc}}
password: {{.registryPassword | b64enc}}
---
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "username"
password: "password"
data:
username: dXNlcm5hbWU=
password: cGFzc3dvcmQ=
---
6 changes: 3 additions & 3 deletions pkg/providers/nutanix/config/cp-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ metadata:
namespace: {{.eksaSystemNamespace}}
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "{{.registryUsername}}"
password: "{{.registryPassword}}"
data:
username: {{.registryUsername | b64enc}}
password: {{.registryPassword | b64enc}}
---
{{- end }}
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "username"
password: "password"
data:
username: dXNlcm5hbWU=
password: cGFzc3dvcmQ=
---
apiVersion: v1
kind: ConfigMap
Expand Down
6 changes: 3 additions & 3 deletions pkg/providers/tinkerbell/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ metadata:
namespace: {{.eksaSystemNamespace}}
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "{{.registryUsername}}"
password: "{{.registryPassword}}"
data:
username: {{.registryUsername | b64enc}}
password: {{.registryPassword | b64enc}}
{{- end }}
6 changes: 3 additions & 3 deletions pkg/providers/tinkerbell/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ func secret() *corev1.Secret {
"clusterctl.cluster.x-k8s.io/move": "true",
},
},
StringData: map[string]string{
"username": "username",
"password": "password",
Data: map[string][]byte{
"username": []byte("username"),
"password": []byte("password"),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,6 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "username"
password: "password"
data:
username: dXNlcm5hbWU=
password: cGFzc3dvcmQ=
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,6 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "username"
password: "password"
data:
username: dXNlcm5hbWU=
password: cGFzc3dvcmQ=
4 changes: 2 additions & 2 deletions pkg/providers/vsphere/config/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type: kubernetes.io/basic-auth
data:
username: {{.vsphereUsername | b64enc}}
password: {{.vspherePassword | b64enc}}
usernameCP: "{{.eksaCloudProviderUsername | b64enc}}"
passwordCP: "{{.eksaCloudProviderPassword | b64enc}}"
usernameCP: {{.eksaCloudProviderUsername | b64enc}}
passwordCP: {{.eksaCloudProviderPassword | b64enc}}
---
apiVersion: v1
kind: Secret
Expand Down
18 changes: 9 additions & 9 deletions pkg/providers/vsphere/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,9 @@ metadata:
namespace: {{.eksaSystemNamespace}}
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "{{.eksaVsphereUsername}}"
password: "{{.eksaVspherePassword}}"
data:
username: {{.eksaVsphereUsername | b64enc}}
password: {{.eksaVspherePassword | b64enc}}
---
{{- if .registryAuth }}
apiVersion: v1
Expand All @@ -663,9 +663,9 @@ metadata:
namespace: {{.eksaSystemNamespace}}
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "{{.registryUsername}}"
password: "{{.registryPassword}}"
data:
username: {{.registryUsername | b64enc}}
password: {{.registryPassword | b64enc}}
---
{{- end }}
apiVersion: v1
Expand Down Expand Up @@ -694,9 +694,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
{{.vsphereServer}}.password: "{{.eksaCloudProviderPassword}}"
{{.vsphereServer}}.username: "{{.eksaCloudProviderUsername}}"
data:
{{.vsphereServer}}.password: {{.eksaCloudProviderPassword | b64enc}}
{{.vsphereServer}}.username: {{.eksaCloudProviderUsername | b64enc}}
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
10 changes: 7 additions & 3 deletions pkg/providers/vsphere/template_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package vsphere_test

import (
"os"
"testing"
"time"

Expand All @@ -12,6 +11,11 @@ import (
"github.com/aws/eks-anywhere/pkg/providers/vsphere"
)

const (
expectedVSphereUsername = "vsphere_username"
expectedVSpherePassword = "vsphere_password"
)

func TestVsphereTemplateBuilderGenerateCAPISpecWorkersInvalidSSHKey(t *testing.T) {
g := NewWithT(t)
spec := test.NewFullClusterSpec(t, "testdata/cluster_main.yaml")
Expand Down Expand Up @@ -52,8 +56,8 @@ func TestVsphereTemplateBuilderGenerateCAPISpecControlPlaneInvalidEtcdSSHKey(t *
}

func TestTemplateBuilder_CertSANs(t *testing.T) {
os.Unsetenv(config.EksavSphereUsernameKey)
os.Unsetenv(config.EksavSpherePasswordKey)
t.Setenv(config.EksavSphereUsernameKey, expectedVSphereUsername)
t.Setenv(config.EksavSpherePasswordKey, expectedVSpherePassword)

for _, tc := range []struct {
Input string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: ""
password: ""
data:
username: dnNwaGVyZV91c2VybmFtZQ==
password: dnNwaGVyZV9wYXNzd29yZA==
---
apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -418,9 +418,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
vsphere_server.password: ""
vsphere_server.username: ""
data:
vsphere_server.password: dnNwaGVyZV9wYXNzd29yZA==
vsphere_server.username: dnNwaGVyZV91c2VybmFtZQ==
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: ""
password: ""
data:
username: dnNwaGVyZV91c2VybmFtZQ==
password: dnNwaGVyZV9wYXNzd29yZA==
---
apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -418,9 +418,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
vsphere_server.password: ""
vsphere_server.username: ""
data:
vsphere_server.password: dnNwaGVyZV9wYXNzd29yZA==
vsphere_server.username: dnNwaGVyZV91c2VybmFtZQ==
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "vsphere_username"
password: "vsphere_password"
data:
username: dnNwaGVyZV91c2VybmFtZQ==
password: dnNwaGVyZV9wYXNzd29yZA==
---
apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -532,9 +532,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
vsphere_server.password: "vsphere_password"
vsphere_server.username: "vsphere_username"
data:
vsphere_server.password: dnNwaGVyZV9wYXNzd29yZA==
vsphere_server.username: dnNwaGVyZV91c2VybmFtZQ==
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "vsphere_username"
password: "vsphere_password"
data:
username: dnNwaGVyZV91c2VybmFtZQ==
password: dnNwaGVyZV9wYXNzd29yZA==
---
apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -560,9 +560,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
vsphere_server.password: "vsphere_password"
vsphere_server.username: "vsphere_username"
data:
vsphere_server.password: dnNwaGVyZV9wYXNzd29yZA==
vsphere_server.username: dnNwaGVyZV91c2VybmFtZQ==
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "vsphere_username"
password: "vsphere_password"
data:
username: dnNwaGVyZV91c2VybmFtZQ==
password: dnNwaGVyZV9wYXNzd29yZA==
---
apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -504,9 +504,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
vsphere_server.password: "vsphere_password"
vsphere_server.username: "vsphere_username"
data:
vsphere_server.password: dnNwaGVyZV9wYXNzd29yZA==
vsphere_server.username: dnNwaGVyZV91c2VybmFtZQ==
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ metadata:
namespace: eksa-system
labels:
clusterctl.cluster.x-k8s.io/move: "true"
stringData:
username: "vsphere_username"
password: "vsphere_password"
data:
username: dnNwaGVyZV91c2VybmFtZQ==
password: dnNwaGVyZV9wYXNzd29yZA==
---
apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -511,9 +511,9 @@ stringData:
metadata:
name: cloud-provider-vsphere-credentials
namespace: kube-system
stringData:
vsphere_server.password: "vsphere_password"
vsphere_server.username: "vsphere_username"
data:
vsphere_server.password: dnNwaGVyZV9wYXNzd29yZA==
vsphere_server.username: dnNwaGVyZV91c2VybmFtZQ==
type: Opaque
type: addons.cluster.x-k8s.io/resource-set
---
Expand Down
Loading