I have:
- EKS deployed by aws-cdk script, with kubectl enabled, and apps deployed by
eks.Cluster.addResource()
- AWS Secrets Manager with a set of secrets I want to be available for EKS application
I tried to deploy Secret this way:
import * as sm from "@aws-cdk/aws-secretsmanager";
getSecret(secretKey: string): string {
let secretTokens = sm.Secret.fromSecretArn(scope, "ImportedSecrets", awsSecretStorageArn);
return secretTokens.secretValueFromJson(secretKey).toString();
}
createKubernetesImagePullSecrets(k8s: eks.Cluster): void {
let eksSecretStorageName = this.env.awsResourcesConfig.k8sImagePullSecretStorageName;
k8s.addResource(eksSecretStorageName, {
apiVersion: "v1",
kind: "Secret",
metadata: {
name: eksSecretStorageName,
},
data: {
".dockerconfigjson": this.getSecret('hub-secret'),
},
type: "kubernetes.io/dockerconfigjson",
});
}
I'm getting an error from CloudFormation:
Secret in version "v1" cannot be handled as a Secret: v1.Secret.ObjectMeta: v1.ObjectMeta.TypeMeta: Kind: Data: decode base64: illegal base64 data at input byte 0
This happens because the secret token is not expanded and the ".dockerconfigjson" field value, in this case, looks like ${Token[TOKEN.417]}
Is there a way to deploy the EKS Secret resource and expand secret tokens correctly during deployment?