Hi, I have an EKS cluster running on my AWS, currently I am passing credentials/sensitive information as secret and use as environment variable in deployment yaml. Now we are trying to move on to use AWS Secret Manager. Therefore we have put credentials in the AWS Secret Manager.
I want to know how can I pass those AWS Secret Manager key value to Deployment/Pods as environment variables.
Few solutions, I came across are CSI driver but it uses Volumes/Volume mount then set as environment variable (Wouldn’t like to use it don’t want to use Volumes/volume mount to pass secrets), External Secrets has a con that if we update the Secret in AWS Secret Manager then we have to again apply all the secrets and restart deployment again.
Please correct me if I am wrong somewhere. Thanks in advance
I use terraform for this. Refer to the aws secret as a data source and use kubectl_manifest resource to kubectl apply the deployments and inject the terrafrom data source (aws secret) as env variables in the yaml.
External secrets enables you to map secrets from aws secrets manager to native kube secrets, it also updates the k8s secrets when it is updated on AWS. While reloader will watch out for changes on config maps/secrets and restart said deployments accordingly.
Instructions to setup should be pretty straight forward from the repos themselves feel free to comment or pm me if you have additional questions.
Initially I tried using CSI driver, but since in the CSI method the secrets are mounted as a file. Applications are designed to search in the ENV not from files.
(plus read a medium article where it was mentioned reading configuration from environment variable, is a best practice recommended by the Twelve-Factor App methodology) .
The 12Factor app is not something you must adhere to exactly as they are written. They’re recommendations, not literal requirements, and you can achieve them in gradations.
The Secrets CSI Driver is perfectly capable of taking an external cloud provider secret and converting that into an env var for your pod. The volume mount is required as part of that process, but your app does not need to know or care about the file. Even so, the use of these files if you wanted to use them ‘as is’ you aren’t violating 12factor app principles. The key thing that the 12factor site is trying to get across there is to separate your code from its deployment specific configuration so that you have increased portability and flexibility.
In the above code, the parameters contains the mapping of the actual SSM ParameterStore object from AWS to an object alias. This is what will show up in the volume mount as a file. The secretObjects then tells the CSI Driver to create an ephemeral k8s Secret when the SecretProviderClass is mounted to a pod. The volume mount is mandatory for this feature. Its documentation refers to this as a ‘secret synchronization’. (There’s supposedly some way to make it synch into an existing Secret object but I’ve had issues getting that to work)
Next, adjust your Deployment template so that it mounts the volume and then you can map the Secret into the environment configuration.
Voila, you have brought your AWS (or other cloud provider) secrets into K8s and injected it into your pods as an environment variable. When all pods utilizing the volume mount are removed, the corresponding Secret is destroyed.
Refer to sections 2.2, 2.3, and 2.4 of the documentation.