Skip to content

Commit

Permalink
Fix base64 encoding of already base64 encoded cluster ca
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwickenden committed Aug 8, 2022
1 parent 4aa197b commit 1de84d1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/eks/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,19 @@ func ParseCloudConfig(cloudConfig []byte, region string) (*clientcmdapi.Config,

re = regexp.MustCompile(`B64_CLUSTER_CA=(.*)`)
fetchedValue = re.FindStringSubmatch(kubeletEnvContent)
base64DecodedCAData := fetchedValue[1]
base64EncodedCA := fetchedValue[1]

base64DecodedCAData, err := base64.StdEncoding.DecodeString(base64EncodedCA)
if err != nil {
return nil, err
}

k = &clientcmdapi.Config{
// Define a cluster stanza
Clusters: map[string]*clientcmdapi.Cluster{
clusterName: {
Server: k8sMaster,
CertificateAuthorityData: []byte(base64DecodedCAData),
CertificateAuthorityData: base64DecodedCAData,
},
},
// Define auth based on the kubelet client cert retrieved
Expand Down Expand Up @@ -200,7 +205,7 @@ func ParseShellScript(userData string) (*clientcmdapi.Config, error) {
clusterNameAtStart := regexp.MustCompile(`(?m)/etc/eks/bootstrap.sh ([a-z0-9A-Z-_]*)\s*(--.*)`)
eksBootstrapCmd := clusterNameAtStart.FindStringSubmatch(userData)
if eksBootstrapCmd == nil {
return nil, errors.New("Error while parsing user-data, could not find /etc/eks/boostrap.sh")
return nil, errors.New("error while parsing user-data, could not find /etc/eks/boostrap.sh")
}

eksBootstrapArgs := strings.Fields(eksBootstrapCmd[2])
Expand Down

0 comments on commit 1de84d1

Please sign in to comment.