Skip to content

Commit

Permalink
Add Sealed Secrets installation guide and usage example
Browse files Browse the repository at this point in the history
Added installation instructions for Sealed Secrets using Kustomize
along with example
  • Loading branch information
pratik705 committed Mar 20, 2024
1 parent 5bddc8b commit 7f58cdc
Show file tree
Hide file tree
Showing 6 changed files with 620 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/kustomize-sealed-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Kustomize GitHub Actions for sealed-secrets

on:
pull_request:
paths:
- kustomize/sealed-secrets/**
- .github/workflows/kustomize-sealed-secrets.yaml
jobs:
kustomize:
strategy:
matrix:
overlays:
- base
name: Kustomize
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: azure/setup-helm@v3
with:
version: latest
token: "${{ secrets.GITHUB_TOKEN }}"
id: helm
- name: Kustomize Install
working-directory: /usr/local/bin/
run: |
if [ ! -f /usr/local/bin/kustomize ]; then
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | sudo bash
fi
- name: Run Kustomize Build
run: |
kustomize build kustomize/sealed-secrets/${{ matrix.overlays }} --enable-helm --helm-command ${{ steps.helm.outputs.helm-path }} > /tmp/rendered.yaml
- name: Return Kustomize Build
uses: actions/upload-artifact@v2
with:
name: kustomize-sealed-secrets-artifact-${{ matrix.overlays }}
path: /tmp/rendered.yaml
76 changes: 76 additions & 0 deletions docs/sealed-secrets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Sealed Secrets Introduction and Installation Guide


Sealed Secrets is a Kubernetes-native solution for securely storing and managing sensitive information within Kubernetes Secrets. It ensures secure secret management by encrypting Kubernetes Secrets and storing them as SealedSecret resources, which can only be decrypted by the cluster itself.

Sealed Secrets utilizes public-key cryptography to encrypt secrets, enabling safe storage in your version control system.


## Installation

``` shell
cd kustomize/sealed-secrets/base
```

- Modify the `values.yaml` file with your desired configurations. Refer to the sample configuration in this directory, already updated for installation.

``` shell
vi values.yaml
```

- Perform the installation:

``` shell
kubectl kustomize . --enable-helm | kubectl apply -f -
```

!!! note
Ensure to take a backup of the `sealed-secrets-keyxxxx` Kubernetes Secret from the sealed-secrets namespace, as it will be required for the restoration process if needed.

```
kubectl get secret -n sealed-secrets -l sealedsecrets.bitnami.com/sealed-secrets-key=active -o yaml > sealed-secrets-key.yaml
```

## Usage Example:
In this example, we will use Sealed Secrets to encrypt a Grafana certificate from Kubernetes Secret yaml file.

### Encrypting Kubernetes Secret:
- Kubernetes Secret yaml file containing Grafana certificate:
```
# cat grafana-cert.yaml
apiVersion: v1
data:
ca.crt:
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJjVENDQVJhZ0F3SUJBZ0lRYjBYbHp2d3JIWTd0MjNBREJ5Y2NnekFLQmdncWhrak9QUVFEQWpBWU1SWXcKRkFZRFZRUURFdzF5WVdOcmMzQmhZMlV1WTI5dE1CNFhEVEkwTURJeU5ERXdOVFExT0ZvWERUTTBNREl5TVRFdwpOVFExT0Zvd0dERVdNQlFHQTFVRUF4TU5jbUZqYTNOd1lXTmxMbU52YlRCWk1CTUdCeXFHU000OUFnRUdDQ3FHClNNNDlBd0VIQTBJQUJPd0owMU1ZTWw4MUNyV1dMODlQQkhvVG5telZCT2xRMkdMMDFTd2JjYXZQVmRCWnVHamIKeFlwR3VKVDd1UG5xdVp4eFZ4djhUSFlPcVVVL1ZYT2ZtdkNqUWpCQU1BNEdBMVVkRHdFQi93UUVBd0lDcERBUApCZ05WSFJNQkFmOEVCVEFEQVFIL01CMEdBMVVkRGdRV0JCUU5weXZnNk1CSWFnZENuOVR1ejZ3SkZDMVIvekFLCkJnZ3Foa2pPUFFRREFnTkpBREJHQWlFQTY5T25ScUZ5SHZQbjJkWFZ6YjBTVFRZY2UxUUZGUEphWXFVYnQrc2kKdG13Q0lRRDE2ODV0UDBKcnZRRnB6NVlPNFdYQ2xEQWxabTgxUWRwN1lWY0FJS1RhbWc9PQotLS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NEdIZXZzCnd0UkVldWtDZ1lFQSt1ZExMZllCRitFaDZIVldvT3NXU2lqZCtrTnh4ajhaK2VSMWhOaWxtN1I5RlNkVzJHVEoKY2lvMlIrSDhWU0xudnFjZ29oWXNxZ0N0VXViTnpNbjdlbEt4RkNOOHRaS1lUYnhHcU5IUHJ4WE43M3RQNy83WAp2MWF4UXQvbm5lcDEvaVYzODVBcUZLdGZ6UU9Ua25sdGJBcmxyZzRvRFk4d0NtUmcwTi9aLzJFPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
kind: Secret
metadata:
annotations:
cert-manager.io/alt-names: grafana-lab.demo.mk8s.net
name: grafana
namespace: rackspace-system
type: kubernetes.io/tls
```
- Download [kubeseal](https://github.com/bitnami-labs/sealed-secrets/releases) binary.
- Use `kubeseal` for the Kuberntes Secret entryption:
``` shell
kubeseal --scope cluster-wide --allow-empty-data -o yaml --controller-namespace rackspace-system < ~/grafana-cert.yaml > encrypted_grafana-cert.yaml
cat encrypted_grafana-cert.yaml
```
For more options around `kubeseal` please check help page.

- Upload the encrypted Sealed Secret resource(`encrypted_grafana-cert.yaml`) to your version control system. It can only be decrypted using the secret created during the Sealed Secrets installation.

### Deploying Kubernetes Secret from Sealed Secret Resource:
- Apply sealed-secret resource(`encrypted_grafana-cert.yaml`):
```shell
kubectl apply -f encrypted_grafana-cert.yaml
```
- Verify that the Sealed Secret has been created and the Kubernetes Secret has been decrypted:
```shell
kubectl get sealedsecret/grafana -n rackspace-system
kubectl get secret grafana -n rackspace-system
```
12 changes: 12 additions & 0 deletions kustomize/sealed-secrets/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resources:
- './namespace.yaml'
namespace: sealed-secrets
helmGlobals:
chartHome: ../charts/
helmCharts:
- name: sealed-secrets
includeCRDs: true
releaseName: sealed-secrets
valuesFile: values.yaml
version: 2.14.2
repo: https://bitnami-labs.github.io/sealed-secrets
8 changes: 8 additions & 0 deletions kustomize/sealed-secrets/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: v1
kind: Namespace
metadata:
labels:
kubernetes.io/metadata.name: sealed-secrets
name: sealed-secrets
name: sealed-secrets
Loading

0 comments on commit 7f58cdc

Please sign in to comment.