Skip to content

Commit

Permalink
quote base64 strings in the yaml files; use k8s compatible encoding f…
Browse files Browse the repository at this point in the history
…or base64 values (Azure#3248)

* put double quotes around the base64 string in the yaml file to protect against base64 strings which contain '-'  (note: not all dialects of base64 have '-' in index 62, some have '+', '_', '~'

* use standard encoding for base64 string encoding encryption secret as kubernetes 1.8 does not recognize `-_` characters in encoding

* use standard encoding for base64 string encoding encryption secret as kubernetes 1.8 does not recognize `-_` characters in encoding

* update unit test for proper encoding scheme on key for etcd encryption at rest

* update validation test for proper encoding scheme on key for etcd encryption at rest
  • Loading branch information
PaulCharlton authored and Cecile Robert-Michon committed Jun 13, 2018
1 parent 1f306d2 commit 347d695
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions parts/k8s/kubernetesmastercustomdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ MASTER_ARTIFACTS_CONFIG_PLACEHOLDER
{{end}}

{{if EnableDataEncryptionAtRest }}
sed -i "s|<etcdEncryptionSecret>|{{WrapAsVariable "etcdEncryptionKey"}}|g" "/etc/kubernetes/encryption-config.yaml"
sed -i "s|<etcdEncryptionSecret>|\"{{WrapAsVariable "etcdEncryptionKey"}}\"|g" "/etc/kubernetes/encryption-config.yaml"
{{end}}

{{if eq .OrchestratorProfile.KubernetesConfig.NetworkPolicy "calico"}}
Expand All @@ -297,9 +297,9 @@ MASTER_ARTIFACTS_CONFIG_PLACEHOLDER
{{if eq .OrchestratorProfile.KubernetesConfig.NetworkPolicy "cilium"}}
# If Cilium Policy enabled then update the etcd certs and address
sed -i "s|<ETCD_URL>|{{WrapAsVerbatim "variables('masterEtcdClientURLs')[copyIndex(variables('masterOffset'))]"}}|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
sed -i "s|<ETCD_CA>|$(base64 -w 0 /etc/kubernetes/certs/ca.crt)|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
sed -i "s|<ETCD_CLIENT_KEY>|$(base64 -w 0 /etc/kubernetes/certs/etcdclient.key)|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
sed -i "s|<ETCD_CLIENT_CERT>|$(base64 -w 0 /etc/kubernetes/certs/etcdclient.crt)|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
sed -i "s|<ETCD_CA>|\"$(base64 -w 0 /etc/kubernetes/certs/ca.crt)\"|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
sed -i "s|<ETCD_CLIENT_KEY>|\"$(base64 -w 0 /etc/kubernetes/certs/etcdclient.key)\"|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
sed -i "s|<ETCD_CLIENT_CERT>|\"$(base64 -w 0 /etc/kubernetes/certs/etcdclient.crt)\"|g" "/etc/kubernetes/addons/cilium-daemonset.yaml"
{{end}}
{{if UseCloudControllerManager }}
sed -i "s|<kubernetesCcmImageSpec>|{{WrapAsVariable "kubernetesCcmImageSpec"}}|g" "/etc/kubernetes/manifests/cloud-controller-manager.yaml"
Expand Down
2 changes: 1 addition & 1 deletion pkg/acsengine/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,5 +1087,5 @@ func k8sVersionMetricsServerAddonEnabled(o *api.OrchestratorProfile) *bool {
func generateEtcdEncryptionKey() string {
b := make([]byte, 32)
rand.Read(b)
return base64.URLEncoding.EncodeToString(b)
return base64.StdEncoding.EncodeToString(b)
}
2 changes: 1 addition & 1 deletion pkg/acsengine/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestGenerateEtcdEncryptionKey(t *testing.T) {
t.Fatalf("generateEtcdEncryptionKey should return a unique key each time, instead returned identical %s and %s", key1, key2)
}
for _, val := range []string{key1, key2} {
_, err := base64.URLEncoding.DecodeString(val)
_, err := base64.StdEncoding.DecodeString(val)
if err != nil {
t.Fatalf("generateEtcdEncryptionKey should return a base64 encoded key, instead returned %s", val)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/vlabs/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (a *Properties) validateOrchestratorProfile(isUpdate bool) error {
minVersion.String(), o.OrchestratorVersion)
}
if o.KubernetesConfig.EtcdEncryptionKey != "" {
_, err = base64.URLEncoding.DecodeString(o.KubernetesConfig.EtcdEncryptionKey)
_, err = base64.StdEncoding.DecodeString(o.KubernetesConfig.EtcdEncryptionKey)
if err != nil {
return fmt.Errorf("etcdEncryptionKey must be base64 encoded. Please provide a valid base64 encoded value or leave the etcdEncryptionKey empty to auto-generate the value")
}
Expand Down

0 comments on commit 347d695

Please sign in to comment.