π― Objectives
- Mounting Secrets from AWS Systems Manager Parameter Store for AWS EKS
Why Parameter Store ?
- Leverages AWS KMS to encrypt values.
- Support versioning of secret values
- It is free and no additional charge for storage and standard throughput. For higher throughput, API interactions cost is $0.05 per 10,000 API calls.
- You want cheaper option to store encrypted or unencrypted secrets.
Prerequisite
- An AWS account and AWS CLI
- An existing EKS Cluster
- Helm, Docker, and Kubectl installation.
- Export variables
1 | export AWS_ACCESS_KEY_ID="ASIAV....." |
- Install the AWS Secrets and Config Provider (ASCP) and Container Storage Interface (CSI) driver
1 | helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts |
- Create IAM policy with permissions that allow your your pods to access the parameters in Parameter Store
1 | cat > parameter-policy.json <<EOF |
- Create an IAM role:
i. View your clusterβs OIDC provider URL
1 | aws eks describe-cluster --name $EKS_CLUSTER_NAME --query "cluster.identity.oidc.issuer" --output text |
ii. Create the following IAM trust policy file , replace YOUR_AWS_ACCOUNT_ID
with your account ID. Replace YOUR_AWS_REGION
with your AWS Region. Replace XXXXXXXXXX45D83924220DC4815XXXXX
with the value returned in step 4i.
1 | cat <<EOF > trust-policy.json |
iii. Create an IAM role
1 | aws iam create-role \ |
iv. Attach your new IAM policy created in step 3 to the role:
1 | aws iam attach-role-policy \ |
- Annotate the Kubernetes service account with the Amazon Resource Name (ARN) of the IAM role that you created earlier and replace with your
AWS_ACCOUNT_ID
:
1 | cat > service-account.yaml <<EOF |
- Create fake parameters , I will create a fake staging
postgresql
DB username and password
1 | aws ssm put-parameter --name "/staging/postgresql/username" --value "admin" --description "username for staging postgreSQL DB" \ |
- Create SecretProviderClass and Sync with Native Kubernetes Secrets
Create SecretProviderClass custom resource withprovider:aws
The SecretProviderClass must be in the same namespace as the pod using it later.
1 | cat << EOF > k8s-secrets.yaml |
- Create pod , mount secrets volumes and set up Environment variables
1 | cat << EOF > deployment.yaml |
References