-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8548fa2
commit 03c43c0
Showing
8 changed files
with
217 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
manifests/modules/security/secrets-manager/external-secrets/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: catalog | ||
namespace: catalog | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: catalog | ||
env: | ||
- name: DB_USER | ||
valueFrom: | ||
secretKeyRef: | ||
name: catalog-external-secret | ||
key: username | ||
- name: DB_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: catalog-external-secret | ||
key: password |
13 changes: 13 additions & 0 deletions
13
manifests/modules/security/secrets-manager/external-secrets/external-secret.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: external-secrets.io/v1beta1 | ||
kind: ExternalSecret | ||
metadata: | ||
name: "catalog-external-secret" | ||
namespace: "catalog" | ||
spec: | ||
refreshInterval: 1h | ||
secretStoreRef: | ||
name: "cluster-secret-store" | ||
kind: ClusterSecretStore | ||
dataFrom: | ||
- extract: | ||
key: "eks-workshop/catalog-secret" |
8 changes: 8 additions & 0 deletions
8
manifests/modules/security/secrets-manager/external-secrets/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
bases: | ||
- ../../../../base-application/catalog | ||
patches: | ||
- deployment.yaml | ||
resources: | ||
- external-secret.yaml |
2 changes: 1 addition & 1 deletion
2
...ets-manager/validate-cluster-resources.md → ...ecrets-management/secrets-manager/ascp.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 128 additions & 2 deletions
130
website/docs/security/secrets-management/secrets-manager/external-secrets.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,132 @@ | ||
--- | ||
title: "Using External Secrets" | ||
title: "External Secrets Operator" | ||
sidebar_position: 64 | ||
--- | ||
|
||
As seen in earlier steps, we have a `Deployment` in the **Catalog** `Namespace` with some credentials declared as environment variables, using values stored in a `Secret` in the same `Namespace`. We could also check that this is not the best approach to store sensitive information, since the secret values are just encoded using *base64*, and can be easily decoded in the command line. We will then modify the **catalog-db** `Deployment` to use the secret stored in AWS Secrets Manager, as the source for the sensitive credentials information. | ||
The `prepare-environment` script that you ran in a [previous step](./index.md), has already deployed the External Secrets Operator addon required for this lab. | ||
|
||
Let's validate the created addon. | ||
|
||
```bash | ||
$ kubectl -n external-secrets get pods | ||
NAME READY STATUS RESTARTS AGE | ||
external-secrets-6d95d66dc8-5trlv 1/1 Running 0 7m | ||
external-secrets-cert-controller-774dff987b-krnp7 1/1 Running 0 7m | ||
external-secrets-webhook-6565844f8f-jxst8 1/1 Running 0 7m | ||
$ kubectl -n external-secrets get sa | ||
NAME SECRETS AGE | ||
default 0 7m | ||
external-secrets-sa 0 7m | ||
``` | ||
|
||
As you can see, you have a ServiceAccount named `external-secrets-sa`, this SA is tied to an [IRSA](../../iam-roles-for-service-accounts/), with access to AWS Secrets Manager, for retrieving secrets information. | ||
|
||
```bash | ||
$ kubectl -n external-secrets describe sa external-secrets-sa | grep Annotations | ||
Annotations: eks.amazonaws.com/role-arn: arn:aws:iam::068535243777:role/eks-workshop-external-secrets-sa-irsa | ||
``` | ||
|
||
There is also a ClusterResource called `ClusterSecretStore` which is a cluster wide SecretStore that can be referenced by all ExternalSecrets from all namespaces. | ||
|
||
```bash | ||
$ kubectl get clustersecretstores.external-secrets.io | ||
NAME AGE STATUS CAPABILITIES READY | ||
cluster-secret-store 81s Valid ReadWrite True | ||
$ kubectl get clustersecretstores.external-secrets.io cluster-secret-store -o yaml | yq '.spec' | ||
provider: | ||
aws: | ||
auth: | ||
jwt: | ||
serviceAccountRef: | ||
name: external-secrets-sa | ||
namespace: external-secrets | ||
region: us-west-2 | ||
service: SecretsManager | ||
|
||
``` | ||
|
||
You can see here, that it's using a [JSON Web Token (jwt)](https://jwt.io/), referenced to the ServiceAccount we just checked, to sync with AWS Secrets Manager. | ||
|
||
Let's move forward and create an `ExternalSecret`, that describes what data should be fetched from AWS Secrets Manager, how the data should be transformed and saved as a Kubernetes Secret. And also patch our `catalog` Deployment to use the External Secret as source for the credentials. | ||
|
||
```kustomization | ||
modules/security/secrets-manager/external-secrets/kustomization.yaml | ||
Deployment/catalog | ||
ExternalSecret/catalog-external-secret | ||
``` | ||
|
||
```bash | ||
$ kubectl apply -k eks-workshop/modules/security/secrets-manager/external-secrets/ | ||
``` | ||
|
||
Check the newly created `ExternalSecret` resouce. | ||
|
||
```bash | ||
$ kubectl -n catalog get externalsecrets.external-secrets.io | ||
NAME STORE REFRESH INTERVAL STATUS READY | ||
catalog-external-secret cluster-secret-store 1h SecretSynced True | ||
``` | ||
|
||
Verify that the resource has a `SecretSynced` status, which means that it was successfully syncronized from AWS Secrets Manager. Let's take a closer look to this resource specifications. | ||
|
||
```bash | ||
$ kubectl -n catalog get externalsecrets.external-secrets.io catalog-external-secret -o yaml | yq '.spec' | ||
dataFrom: | ||
- extract: | ||
conversionStrategy: Default | ||
decodingStrategy: None | ||
key: eks-workshop/catalog-secret | ||
refreshInterval: 1h | ||
secretStoreRef: | ||
kind: ClusterSecretStore | ||
name: cluster-secret-store | ||
target: | ||
creationPolicy: Owner | ||
deletionPolicy: Retain | ||
``` | ||
|
||
Notice the `key` and the `secretStoreRef` parameter, pointing to the secret we stored on AWS Secrets Manager, and the `ClusterSecretStore` previously created. Also the `refreshInterval` is set to 1 hours, which means that the value from this secret will be checked and refreshed every hour. | ||
|
||
But how do we use this ExternalSecret in our Pods? After we create this resouces, it automatically created a Kubernetes secret with the same name in the Namespace. | ||
|
||
```bash | ||
$ kubectl -n catalog get secrets | ||
NAME TYPE DATA AGE | ||
catalog-db Opaque 2 21h | ||
catalog-external-secret Opaque 2 1m | ||
catalog-secret Opaque 2 5h40m | ||
``` | ||
|
||
Take a deeper look in this secret. | ||
|
||
```bash | ||
$ kubectl -n catalog get secret catalog-external-secret -o yaml | yq '.metadata.ownerReferences' | ||
- apiVersion: external-secrets.io/v1beta1 | ||
blockOwnerDeletion: true | ||
controller: true | ||
kind: ExternalSecret | ||
name: catalog-external-secret | ||
uid: b8710001-366c-44c2-8e8d-462d85b1b8d7 | ||
``` | ||
|
||
See that it has an `ownerReference` that points to External Secrets Operator. | ||
|
||
Now check that the `catalog` Pod, is already updated with the values from this new secret, and it's up and running! | ||
|
||
```bash | ||
$ kubectl -n catalog get pods | ||
NAME READY STATUS RESTARTS AGE | ||
catalog-777c4d5dc8-lmf6v 1/1 Running 0 14m | ||
catalog-mysql-0 1/1 Running 0 24h | ||
$ kubectl -n catalog get deployment catalog -o yaml | yq '.spec.template.spec.containers[] | .env' | ||
- name: DB_USER | ||
valueFrom: | ||
secretKeyRef: | ||
key: username | ||
name: catalog-external-secret | ||
- name: DB_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
key: password | ||
name: catalog-external-secret | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters