Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Generic Webhook #29

Merged
merged 49 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8dc1b67
refactor: wip
csatib02 Mar 23, 2024
df816da
refactor
csatib02 Mar 24, 2024
a4cb69b
refactor: genericize main functionality
csatib02 Mar 24, 2024
5aa9a9a
refactor: all mutate objects, only pod remains
csatib02 Mar 24, 2024
3abe477
refactor: all mutate objects, only pod remains
csatib02 Mar 26, 2024
c184da1
refactor
csatib02 Mar 26, 2024
ba0c7b9
refactor: last commit before refactoring pod.go
csatib02 Mar 26, 2024
2ff08d0
refactor: finished
csatib02 Mar 26, 2024
1978752
refactor: finished
csatib02 Mar 26, 2024
af73b9b
fix: Minor fixes
csatib02 Mar 27, 2024
ef438bf
feat(bao_tests): Add bao unit tests
csatib02 Mar 27, 2024
d0467e1
refactor: Done
csatib02 Mar 27, 2024
94880bd
refactor: Final
csatib02 Mar 28, 2024
2f19ef2
refactor: finishing touches
csatib02 Mar 28, 2024
8717ee1
refactor: finishing touches
csatib02 Mar 28, 2024
ed33ed3
refactor: done
csatib02 Apr 2, 2024
8819a76
fix
csatib02 Apr 4, 2024
57a0615
ci: trigger
csatib02 Apr 5, 2024
13b7d18
ci: trigger
csatib02 Apr 5, 2024
4be4f70
ci(e2e-test): use version matrix for operator
csatib02 May 14, 2024
ab03d86
refactor: Prepare backwards compatibility
csatib02 May 14, 2024
2edfe07
feat: preserve backwards compatibility
csatib02 May 14, 2024
8508a23
refactor: finish up config
csatib02 May 14, 2024
93231d6
refactor: factour out env-vars
csatib02 May 14, 2024
d5ac900
chore: go mod tidy
csatib02 May 15, 2024
fad117d
refactor: make env-vars backwards compatible
csatib02 May 15, 2024
60742f8
fix: CI errors
csatib02 May 15, 2024
eea9637
fix: add startup probe checks
csatib02 May 16, 2024
e47bd94
feat: add all probes to mutate probes tests
csatib02 May 16, 2024
ab5ea54
refactor: finished webhook refactoring
csatib02 May 17, 2024
fef50cb
fix: add logger to provider struct
csatib02 May 17, 2024
a087474
fix: only create client when not using vault-agent
csatib02 May 17, 2024
d8b489f
chore: update nix
csatib02 May 17, 2024
a0ee1b6
chore: remove obsolete docker-compose version
csatib02 May 17, 2024
b50e601
chore: finishing touches
csatib02 May 17, 2024
5f60746
chore: update dependencies
csatib02 May 20, 2024
6a02e3b
fix: use original Bao image
csatib02 May 23, 2024
13930e7
chore: export default timeout on e2e tests
csatib02 May 23, 2024
dc2dec7
refactor: Use obj namespace instead of ar namespace, factor out secre…
csatib02 May 23, 2024
0514849
fix: old annotations only checked, but not deleted
csatib02 May 25, 2024
1b59c50
feat: Add example fiels recently deleted from operator repo
csatib02 May 25, 2024
91f33bf
fix: linters
csatib02 May 25, 2024
3cd84ab
chore: update dependencies
csatib02 May 27, 2024
f825dd9
chore: take out annotation prefix
csatib02 Jun 3, 2024
7b4f9e5
chore: move out params to structs, common for all providers
csatib02 Jun 3, 2024
6697a7c
chore: use secret-init env-vars from secret-init repo
csatib02 Jun 3, 2024
f6b7ada
chore: add comment to agent configs
csatib02 Jun 3, 2024
f2dcf0a
fix
csatib02 Jun 3, 2024
a4cf882
fix: introduced error
csatib02 Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ jobs:
VAULT_DEV_ROOT_TOKEN_ID: 227e1cce-6bf7-30bb-2d2a-acc854318caf
ports:
- 8200:8200
bao:
image: quay.io/openbao/openbao@sha256:a015ae0adb1af5b45b33632e29879ff87063d0878e9359584a50b2706e500e9a # 2.0.0-alpha20240329
env:
SKIP_SETCAP: true
BAO_ADDR: http://127.0.0.1:8200
BAO_TOKEN: 227e1cce-6bf7-30bb-2d2a-acc854318caf
BAO_DEV_ROOT_TOKEN_ID: 227e1cce-6bf7-30bb-2d2a-acc854318caf
ports:
- 8300:8200

steps:
- name: Checkout repository
Expand Down Expand Up @@ -227,6 +236,7 @@ jobs:
strategy:
matrix:
k8s_version: ["v1.24.15", "v1.25.11", "v1.26.6", "v1.27.3"]
operator_version: ["v1.22.1"] # First version that works with the generic webhook: v1.22.1
# vault_version: ["1.11.12", "1.12.8", "1.13.4", "1.14.8"]

steps:
Expand Down Expand Up @@ -262,7 +272,8 @@ jobs:
env:
KIND_K8S_VERSION: ${{ matrix.k8s_version }}
LOAD_IMAGE_ARCHIVE: ${{ github.workspace }}/docker.tar
# VAULT_VERSION: ${{ matrix.vault_version }}
WEBHOOK_VERSION: ${{ needs.artifacts.outputs.container-image-tag }}
OPERATOR_VERSION: ${{ matrix.operator_version }}
# VAULT_VERSION: ${{ matrix.vault_version }}
HELM_CHART: "${{ github.workspace }}/${{ needs.artifacts.outputs.helm-chart-package }}"
LOG_VERBOSE: "true"
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export PATH := $(abspath bin/):${PATH}

CONTAINER_IMAGE_REF = ghcr.io/bank-vaults/secrets-webhook:dev
OPERATOR_VERSION ?= latest

##@ General

Expand Down Expand Up @@ -72,7 +73,7 @@ test-e2e: ## Run e2e tests

.PHONY: test-e2e-local
test-e2e-local: container-image ## Run e2e tests locally
LOAD_IMAGE=${CONTAINER_IMAGE_REF} WEBHOOK_VERSION=dev ${MAKE} test-e2e
LOAD_IMAGE=${CONTAINER_IMAGE_REF} WEBHOOK_VERSION=dev OPERATOR_VERSION=$(OPERATOR_VERSION) ${MAKE} test-e2e

.PHONY: lint
lint: lint-go lint-helm lint-docker lint-yaml
Expand Down
18 changes: 9 additions & 9 deletions deploy/charts/secrets-webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ It can also inject statically into ConfigMaps, Secrets, and CustomResources.
You will need to add the following annotations to the resources that you wish to mutate:

```yaml
vault.security.banzaicloud.io/vault-addr: https://[URL FOR VAULT]
vault.security.banzaicloud.io/vault-path: [Auth path]
vault.security.banzaicloud.io/vault-role: [Auth role]
vault.security.banzaicloud.io/vault-skip-verify: "true" # Container is missing Trusted Mozilla roots too.
secrets-webhook.security.bank-vaults.io/vault-addr: https://[URL FOR VAULT]
secrets-webhook.security.bank-vaults.io/vault-path: [Auth path]
secrets-webhook.security.bank-vaults.io/vault-role: [Auth role]
secrets-webhook.security.bank-vaults.io/vault-skip-verify: "true" # Container is missing Trusted Mozilla roots too.
```

Be mindful how you reference Vault secrets itself. For KV v2 secrets, you will need to add the `/data/` to the path of the secret.

```
```bash
$ vault kv get kv/rax/test
====== Metadata ======
Key Value
Expand All @@ -39,7 +39,7 @@ MYSQL_ROOT_PASSWORD s3cr3t

The secret shown above is referenced like this:

```
```plaintext
vault:[ENGINE]/data/[SECRET_NAME]#[KEY]
vault:kv/rax/data/test#MYSQL_PASSWORD
```
Expand Down Expand Up @@ -71,15 +71,15 @@ kubectl label namespace "${WEBHOOK_NS}" name="${WEBHOOK_NS}"
### Install the chart

```bash
$ helm install vswh --namespace vswh --wait oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --create-namespace
helm install vswh --namespace vswh --wait oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --create-namespace
```

### Openshift 4.3

For security reasons, the `runAsUser` must be in the range between 1000570000 and 1000579999. By setting the value of `securityContext.runAsUser` to `""`, OpenShift chooses a valid User.

```bash
$ helm upgrade --namespace vswh --install vswh oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --set-string securityContext.runAsUser="" --create-namespace
helm upgrade --namespace vswh --install vswh oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --set-string securityContext.runAsUser="" --create-namespace
```

### About GKE Private Clusters
Expand Down Expand Up @@ -192,7 +192,7 @@ The default option is to let helm generate the CA and TLS certificates on deploy

This will renew the certificates on each deployment.

```
```yaml
certificate:
generate: true
```
Expand Down
18 changes: 9 additions & 9 deletions deploy/charts/secrets-webhook/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ It can also inject statically into ConfigMaps, Secrets, and CustomResources.
You will need to add the following annotations to the resources that you wish to mutate:

```yaml
vault.security.banzaicloud.io/vault-addr: https://[URL FOR VAULT]
vault.security.banzaicloud.io/vault-path: [Auth path]
vault.security.banzaicloud.io/vault-role: [Auth role]
vault.security.banzaicloud.io/vault-skip-verify: "true" # Container is missing Trusted Mozilla roots too.
secrets-webhook.security.bank-vaults.io/vault-addr: https://[URL FOR VAULT]
secrets-webhook.security.bank-vaults.io/vault-path: [Auth path]
secrets-webhook.security.bank-vaults.io/vault-role: [Auth role]
secrets-webhook.security.bank-vaults.io/vault-skip-verify: "true" # Container is missing Trusted Mozilla roots too.
```

Be mindful how you reference Vault secrets itself. For KV v2 secrets, you will need to add the `/data/` to the path of the secret.

```
```bash
$ vault kv get kv/rax/test
====== Metadata ======
Key Value
Expand All @@ -39,7 +39,7 @@ MYSQL_ROOT_PASSWORD s3cr3t

The secret shown above is referenced like this:

```
```plaintext
vault:[ENGINE]/data/[SECRET_NAME]#[KEY]
vault:kv/rax/data/test#MYSQL_PASSWORD
```
Expand Down Expand Up @@ -71,15 +71,15 @@ kubectl label namespace "${WEBHOOK_NS}" name="${WEBHOOK_NS}"
### Install the chart

```bash
$ helm install vswh --namespace vswh --wait oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --create-namespace
helm install vswh --namespace vswh --wait oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --create-namespace
```

### Openshift 4.3

For security reasons, the `runAsUser` must be in the range between 1000570000 and 1000579999. By setting the value of `securityContext.runAsUser` to `""`, OpenShift chooses a valid User.

```bash
$ helm upgrade --namespace vswh --install vswh oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --set-string securityContext.runAsUser="" --create-namespace
helm upgrade --namespace vswh --install vswh oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook --set-string securityContext.runAsUser="" --create-namespace
```

### About GKE Private Clusters
Expand Down Expand Up @@ -116,7 +116,7 @@ The default option is to let helm generate the CA and TLS certificates on deploy

This will renew the certificates on each deployment.

```
```yaml
certificate:
generate: true
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ metadata:
cert-manager.io/inject-ca-from: "{{ .Release.Namespace }}/{{ .Values.certificate.servingCertificate }}"
{{- end }}
webhooks:
- name: pods.{{ template "secrets-webhook.name" . }}.admission.banzaicloud.com
- name: pods.{{ template "secrets-webhook.name" . }}.admission.bank-vaults.com
{{- if semverCompare ">=1.14-0" (include "secrets-webhook.capabilities.kubeVersion" .) }}
{{- with .Values.reinvocationPolicy }}
reinvocationPolicy: {{ . }}
Expand Down Expand Up @@ -162,7 +162,7 @@ webhooks:
{{- if $podsObjectSelector.matchExpressions }}
{{ toYaml $podsObjectSelector.matchExpressions | indent 4 }}
{{- end }}
- key: security.banzaicloud.io/mutate
- key: security.bank-vaults.io/mutate
operator: NotIn
values:
- skip
Expand All @@ -171,7 +171,7 @@ webhooks:
sideEffects: {{ .Values.apiSideEffectValue }}
{{- end }}
{{- if .Values.secretsMutation }}
- name: secrets.{{ template "secrets-webhook.name" . }}.admission.banzaicloud.com
- name: secrets.{{ template "secrets-webhook.name" . }}.admission.bank-vaults.com
{{- with .Values.reinvocationPolicy }}
reinvocationPolicy: {{ . }}
{{- end }}
Expand Down Expand Up @@ -231,7 +231,7 @@ webhooks:
operator: NotIn
values:
- helm
- key: security.banzaicloud.io/mutate
- key: security.bank-vaults.io/mutate
operator: NotIn
values:
- skip
Expand All @@ -241,7 +241,7 @@ webhooks:
{{- end }}
{{- end }}
{{- if .Values.configMapMutation }}
- name: configmaps.{{ template "secrets-webhook.name" . }}.admission.banzaicloud.com
- name: configmaps.{{ template "secrets-webhook.name" . }}.admission.bank-vaults.com
{{- if semverCompare ">=1.14-0" (include "secrets-webhook.capabilities.kubeVersion" .) }}
admissionReviewVersions: ["v1beta1"]
{{- with .Values.reinvocationPolicy }}
Expand Down Expand Up @@ -301,7 +301,7 @@ webhooks:
operator: NotIn
values:
- helm
- key: security.banzaicloud.io/mutate
- key: security.bank-vaults.io/mutate
operator: NotIn
values:
- skip
Expand All @@ -311,7 +311,7 @@ webhooks:
{{- end }}
{{- end }}
{{- if .Values.customResourceMutations }}
- name: objects.{{ template "secrets-webhook.name" . }}.admission.banzaicloud.com
- name: objects.{{ template "secrets-webhook.name" . }}.admission.bank-vaults.com
{{- if semverCompare ">=1.14-0" (include "secrets-webhook.capabilities.kubeVersion" .) }}
admissionReviewVersions: ["v1beta1"]
{{- if .Values.timeoutSeconds }}
Expand Down Expand Up @@ -364,7 +364,7 @@ webhooks:
{{- if $crObjectSelector.matchExpressions }}
{{ toYaml $crObjectSelector.matchExpressions | indent 4 }}
{{- end }}
- key: security.banzaicloud.io/mutate
- key: security.bank-vaults.io/mutate
operator: NotIn
values:
- skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
labels:
app.kubernetes.io/name: {{ template "secrets-webhook.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
security.banzaicloud.io/mutate: skip
security.bank-vaults.io/mutate: skip
{{- if .Values.labels }}
{{ toYaml .Values.labels | indent 8 }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/charts/secrets-webhook/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespaceSelector:
# -- Object selector to use, will limit webhook scope (K8s version 1.15+)
objectSelector: {}
# matchExpressions:
# - key: security.banzaicloud.io/mutate
# - key: security.bank-vaults.io/mutate
# operator: NotIn
# values:
# - skip
Expand Down
18 changes: 15 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
version: "3.9"

services:
vault:
container_name: secrets-webhook-vault
image: hashicorp/vault:1.14.8
ports:
- 127.0.0.1:8200:8200
environment:
SKIP_SETCAP: true
SKIP_SETCAP: "true"
VAULT_ADDR: http://127.0.0.1:8200
VAULT_TOKEN: 227e1cce-6bf7-30bb-2d2a-acc854318caf
VAULT_DEV_ROOT_TOKEN_ID: 227e1cce-6bf7-30bb-2d2a-acc854318caf

bao:
container_name: secrets-webhook-bao
image: quay.io/openbao/openbao@sha256:a015ae0adb1af5b45b33632e29879ff87063d0878e9359584a50b2706e500e9a # 2.0.0-alpha20240329
ports:
- 127.0.0.1:8300:8200
environment:
SKIP_SETCAP: "true"
BAO_ADDR: http://127.0.0.1:8200
BAO_TOKEN: 227e1cce-6bf7-30bb-2d2a-acc854318caf
BAO_DEV_ROOT_TOKEN_ID: 227e1cce-6bf7-30bb-2d2a-acc854318caf
Loading
Loading