Integrate external secret management systems with Kubernetes
Integrate external secret management systems with Kubernetes
This project has been deprecated. Please take a look at ESO (External Secrets Operator) instead https://github.com/external-secrets/external-secrets
This project was moved from the GoDaddy to the external-secrets GitHub organization in an effort to consolidate different projects with the same objective. More information here.
Kubernetes External Secrets allows you to use external secret management systems, like AWS Secrets Manager or HashiCorp Vault, to securely add secrets in Kubernetes. Read more about the design and motivation for Kubernetes External Secrets on the GoDaddy Engineering Blog.
The community and maintainers of this project and related Kubernetes
secret management projects use the
#external-secrets
channel on the Kubernetes slack for discussion and brainstorming.
The project extends the Kubernetes API by adding an ExternalSecrets object using Custom Resource Definition and a controller to implement the behavior of the object itself.
An ExternalSecret declares how to fetch the secret data, while the controller converts all ExternalSecrets to Secrets.
The conversion is completely transparent to Pods that can access Secrets normally.
By default Secrets are not encrypted at rest and are open to attack, either via the etcd server or via backups of etcd data.
To mitigate this risk, use an
external secret management system with a KMS plugin
to encrypt Secrets stored in etcd.
ExternalSecrets are added in the cluster (e.g., kubectl apply -f external-secret-example.yml)ExternalSecrets using the Kubernetes APIExternalSecrets to fetch secret data from external providers (e.g, AWS Secrets Manager)SecretsPods can access Secrets normallyThe official helm chart can be used to create the kubernetes-external-secrets resources and Deployment on a Kubernetes cluster using the Helm package manager.
$ helm repo add external-secrets https://external-secrets.github.io/kubernetes-external-secrets/
$ helm install [RELEASE_NAME] external-secrets/kubernetes-external-secretsFor more details about configuration see the helm chart docs
If you don't want to install helm on your cluster and just want to use kubectl to install kubernetes-external-secrets, you could get the helm client cli first and then use the following sample command to generate kubernetes manifests:
$ helm template --include-crds --output-dir ./output_dir external-secrets/kubernetes-external-secretsThe generated kubernetes manifests will be in ./output_dir and can be applied to deploy kubernetes-external-secrets to the cluster.
For kubernetes-external-secrets to be able to retrieve your secrets it will need access to your secret backend.
Access to AWS secrets backends (SSM & secrets manager) can be granted in various ways:
Granting your nodes explicit access to your secrets using the node instance role (easy for experimentation, not recommended)
Directly provide AWS access credentials to the kubernetes-external-secrets pod by environmental variables.
Optionally configure custom endpoints using environment variables
Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars in the kubernetes-external-secrets session/pod.
You can use envVarsFromSecret in the helm chart to create these env vars from existing k8s secrets.
Additionally, you can specify a roleArn which will be assumed before retrieving the secret.
You can limit the range of roles which can be assumed by this particular namespace by using annotations on the namespace resource. The annotation key is configurable (see above). The annotation value is evaluated as a regular expression and tries to match the roleArn.
kind: Namespace
metadata:
name: iam-example
annotations:
# annotation key is configurable
iam.amazonaws.com/permitted: "arn:aws:iam::123456789012:role/.*"Add your secret data to your backend. For example, AWS Secrets Manager:
aws secretsmanager create-secret --name hello-service/password --secret-string "1234"AWS Parameter Store:
aws ssm put-parameter --name "/hello-service/password" --type "String" --value "1234"and then create a hello-service-external-secret.yml file:
…or
apiVersion: "kubernetes-client.io/v1"
kind: ExternalSecret
metadata:
name: hello-service
spec:
backendType: systemManager
data:
- key: /hello-service/password
name: passwordThe following IAM policy allows a user or role to access parameters matching prod-*.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ssm:GetParameter",
"Resource": "arn:aws:ssm:us-west-2:123456789012:parameter/prod-*"
}
]
}The IAM policy for Secrets Manager is similar (see docs):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
],
"Resource": [
"arn:aws:secretsmanager:us-west-2:111122223333:secret:aes128-1a2b3c",
"arn:aws:secretsmanager:us-west-2:111122223333:secret:aes192-4D5e6F",
"arn:aws:secretsmanager:us-west-2:111122223333:secret:aes256-7g8H9i"
]
}
]
}Save the file and run:
kubectl apply -f hello-service-external-secret.ymlWait a few minutes and verify that the associated Secret has been created:
kubectl get secret hello-service -o=yamlThe Secret created by the controller should look like:
apiVersion: v1
kind: Secret
metadata:
name: hello-service
annotations:
cat: cheese
labels:
dog: farfel
type: Opaque
data:
password: MTIzNA==You can override ExternalSecret type using template, for example:
apiVersion: kubernetes-client.io/v1
kind: ExternalSecret
metadata:
name: hello-docker
spec:
backendType: systemManager
template:
type: kubernetes.io/dockerconfigjson
data:
- key: /hello-service/hello-docker
name: .dockerconfigjsonKubernetes External Secrets supports templating in ExternalSecret using lodash.template.
Template is applied to all ExternalSecret.template sections of the manifest.
Data retrieved from secure backend is available via the data variable.
Additonal object yaml of instance of js-yaml is available in lodash templates.
It can be leveraged for easier YAML content manipulation.
Templating can be used for:
Secret keys:ExternalSecret.template.stringDataExternalSecret.template.dataSecret object.To demonstrate templating functionality let's assume the secure backend, e.g. Hashicorp Vault, contains the following data
| kv/extsec/secret1 | kv/extsec/secret2 |
|---|---|
|
|
Then, one could create the following ExternalSecret
…After applying this ExternalSecret to the K8S cluster, the operator will generate following Secret
apiVersion: v1
data:
file.txt: eyJzdHJLZXkiOiJoZWxsbyB3b3JsZCJ9
file.yaml: aW50S2V5OiAxMQpvYmpLZXk6CiAgc3RyS2V5OiBoZWxsbyB3b3JsZAoKYXJyXzA6IDEKYXJyXzE6IDIKYXJyXzI6IDMKYAo=
s1: eyJpbnRLZXkiOjExLCJvYmpLZXkiOnsic3RyS2V5IjoiaGVsbG8gd29ybGQifX0=
s2: eyJhcnJLZXkiOlsxLDIsM119
kind: Secret
metadata:
name: tmpl-ext-sec
labels:
label1: "11"
label2: hello-world
type: OpaqueResulting Secret could be inspected to see that result is generated by lodash templating engine
…Enforcing naming conventions for backend keys could be done by using namespace annotations.
By default an ExternalSecret may access arbitrary keys from the backend e.g.
data:
- key: /dev/cluster1/core-namespace/hello-service/password
name: passwordAn enforced naming convention helps to keep the structure tidy and limits the access according to your naming schema.
Configure the schema as a regular expression in the namespace using an annotation.
This allows ExternalSecrets in core-namespace only access to secrets that start with
/dev/cluster1/core-namespace/:
kind: Namespace
metadata:
name: core-namespace
annotations:
# annotation key is configurable
externalsecrets.kubernetes-client.io/permitted-key-name: "/dev/cluster1/core-namespace/.*"ExternalSecret config allows scoping the access of kubernetes-external-secrets controller. This allows deployment of multiple kubernetes-external-secrets instances in the same cluster and each instance can access a set of predefined namespaces.
To enable this option, set the env var in the controller side to a list of namespaces:
env:
WATCHED_NAMESPACES: "default,qa,dev"ExternalSecret manifest allows scoping the access of kubernetes-external-secrets controller. This allows deployment of multiple kubernetes-external-secrets instances at the same cluster and each instance can access a set of ExternalSecrets.
To enable this option, set the env var in the controller side:
env:
INSTANCE_ID: "dev-team-instance"And in ExternalSecret side:
apiVersion: kubernetes-client.io/v1
kind: ExternalSecret
metadata:
name: foo
spec:
controllerId: 'dev-team-instance'
[...]Please note
Scoping access by ExternalSecret config provides only a logical separation and it doesn't cover the security
No open issues yet, or sync has not completed.