Skip to content

Commit bd03356

Browse files
authored
Merge pull request #211 from bank-vaults/chore/match-annotations-with-secrets_webhook-with-backwards-compatibility
chore: match annotations with secrets webhook
2 parents f5e9f06 + e757412 commit bd03356

File tree

10 files changed

+58
-25
lines changed

10 files changed

+58
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Vault Secrets Reloader can periodically check if a secret that is used in watche
1515

1616
Upon deployment, the Reloader spawns two “workers”, that run periodically at two different time intervals:
1717

18-
1. The `collector` collects and stores information about the workloads that are opted in via the `alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"` annotation in their pod template metadata and the Vault secrets they use.
18+
1. The `collector` collects and stores information about the workloads that are opted in via the `secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"` annotation in their pod template metadata and the Vault secrets they use.
1919

20-
2. The `reloader` iterates on the data collected by the `collector`, polling the configured Vault instance for the current version of the secrets, and if it finds that it differs from the stored one, adds the workloads where the secret is used to a list of workloads that needs reloading. In a following step, it modifies these workloads by incrementing the value of the `alpha.vault.security.banzaicloud.io/secret-reload-count` annotation in their pod template metadata, initiating a new rollout.
20+
2. The `reloader` iterates on the data collected by the `collector`, polling the configured Vault instance for the current version of the secrets, and if it finds that it differs from the stored one, adds the workloads where the secret is used to a list of workloads that needs reloading. In a following step, it modifies these workloads by incrementing the value of the `secrets-reloader.security.bank-vaults.io/secret-reload-count` annotation in their pod template metadata, initiating a new rollout.
2121

2222
To get familiarized, check out [how Reloader fits in the Bank-Vaults ecosystem](https://github.com/bank-vaults/vault-secrets-reloader/blob/main/examples/reloader-in-bank-vaults-ecosystem.md), and how can you [give Reloader a spin](https://github.com/bank-vaults/vault-secrets-reloader/blob/main/examples/try-locally.md) on your local machine.
2323

@@ -29,7 +29,7 @@ To get familiarized, check out [how Reloader fits in the Bank-Vaults ecosystem](
2929

3030
- It can only check for updated versions of secrets in one specific instance of Hashicorp Vault, no other secret stores are supported yet.
3131

32-
- It can only “reload” Deployments, DaemonSets and StatefulSets that have the `alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"` annotation set among their `spec.template.metadata.annotations`.
32+
- It can only “reload” Deployments, DaemonSets and StatefulSets that have the `secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"` annotation set among their `spec.template.metadata.annotations`.
3333

3434
- The `collector` can only look for secrets in the workload’s pod template environment variables directly, and in their `secrets-webhook.security.bank-vaults.io/vault-from-path` annotation, in the format the `secrets-webhook` also uses, and are unversioned.
3535

deploy/charts/vault-secrets-reloader/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Reloader works in conjunction with the [Secrets Webhook](https://github.com/bank
1111
You will need to add the following annotations to the pod template spec of the workloads (i.e. Deployments, DaemonSets and StatefulSets) that you wish to reload:
1212

1313
```yaml
14-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
14+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
1515
```
1616
1717
## Installing the Chart

deploy/charts/vault-secrets-reloader/README.md.gotmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Reloader works in conjunction with the [Secrets Webhook](https://github.com/bank
1111
You will need to add the following annotations to the pod template spec of the workloads (i.e. Deployments, DaemonSets and StatefulSets) that you wish to reload:
1212

1313
```yaml
14-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
14+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
1515
```
1616

1717
## Installing the Chart

e2e/deploy/workloads/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
secrets-webhook.security.bank-vaults.io/provider: "vault"
1616
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
1717
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
18-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
18+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
1919
spec:
2020
initContainers:
2121
- name: init-ubuntu

e2e/deploy/workloads/deployments.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ spec:
1212
labels:
1313
app.kubernetes.io/name: reloader-test-deployment-to-be-reloaded
1414
annotations:
15+
secrets-webhook.security.bank-vaults.io/provider: "vault"
1516
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
1617
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
17-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
18+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
1819
spec:
1920
initContainers:
2021
- name: init-ubuntu
@@ -62,6 +63,7 @@ spec:
6263
labels:
6364
app.kubernetes.io/name: reloader-test-deployment-no-reload
6465
annotations:
66+
secrets-webhook.security.bank-vaults.io/provider: "vault"
6567
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
6668
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
6769
spec:
@@ -98,9 +100,10 @@ spec:
98100
labels:
99101
app.kubernetes.io/name: reloader-test-deployment-fixed-versions-no-reload
100102
annotations:
103+
secrets-webhook.security.bank-vaults.io/provider: "vault"
101104
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
102105
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
103-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
106+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
104107
spec:
105108
containers:
106109
- name: alpine
@@ -135,10 +138,11 @@ spec:
135138
labels:
136139
app.kubernetes.io/name: reloader-test-deployment-annotated-reload
137140
annotations:
141+
secrets-webhook.security.bank-vaults.io/provider: "vault"
138142
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
139143
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
140144
secrets-webhook.security.bank-vaults.io/vault-from-path: "secret/data/accounts/aws"
141-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
145+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
142146
spec:
143147
containers:
144148
- name: alpine
@@ -177,7 +181,7 @@ spec:
177181
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
178182
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
179183
secrets-webhook.security.bank-vaults.io/vault-from-path: "secret/data/dockerrepo#1"
180-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
184+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
181185
spec:
182186
containers:
183187
- name: alpine

e2e/deploy/workloads/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
secrets-webhook.security.bank-vaults.io/provider: "vault"
1616
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
1717
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
18-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
18+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
1919
spec:
2020
initContainers:
2121
- name: init-ubuntu

examples/reloader-in-bank-vaults-ecosystem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a high level overview of how the Reloader plays along with other compone
66

77
![flowchart](./assets/flowchart.png)
88

9-
1. The `collector` worker periodically collects unversioned secrets from workloads with the `alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"` annotation that are in the format for injection by the Webhook.
9+
1. The `collector` worker periodically collects unversioned secrets from workloads with the `secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"` annotation that are in the format for injection by the Webhook.
1010

1111
2. At its scheduled time, the `reloader` worker checks in Vault if there is a new version of any of the collected secrets since the last sync. If it is the case, it continues to step 3, otherwise the workflow stops.
1212

examples/try-locally.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Now that we have the Bank-Vaults ecosystem running in our kind cluster, we can d
6969
kubectl apply -f e2e/deploy/workloads
7070
```
7171

72-
Looking at the manifest of one of the deployments, the only difference from one that is prepared to work with the Bank-Vaults Webhook with all the annotations starting with `secrets-webhook.security.bank-vaults.io` and the env values starting with `vault:` is the presence of the new `alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"` annotation telling the Reloader to collect secrets and reload it if necessary.
72+
Looking at the manifest of one of the deployments, the only difference from the one that is prepared to work with the Bank-Vaults Webhook with all the annotations starting with `secrets-webhook.security.bank-vaults.io` and the env values starting with `vault:` is the presence of the new `secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"` annotation telling the Reloader to collect secrets and reload it if necessary.
7373

7474
```yaml
7575
apiVersion: apps/v1
@@ -86,9 +86,10 @@ spec:
8686
labels:
8787
app.kubernetes.io/name: reloader-test-deployment-to-be-reloaded
8888
annotations:
89+
secrets-webhook.security.bank-vaults.io/provider: "vault"
8990
secrets-webhook.security.bank-vaults.io/vault-addr: "https://vault:8200"
9091
secrets-webhook.security.bank-vaults.io/vault-tls-secret: vault-tls
91-
alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"
92+
secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"
9293
spec:
9394
initContainers:
9495
- name: init-ubuntu
@@ -140,10 +141,10 @@ Now everything is set to try some things out with the Reloader:
140141

141142
Also notice that there are two pods with the now changed `MYSQL_PASSWORD` injected into them not being restarted, for the following reasons:
142143

143-
- the pod `reloader-test-deployment-no-reload-xxx` does not have the `alpha.vault.security.banzaicloud.io/reload-on-secret-change: "true"` annotation set
144+
- the pod `reloader-test-deployment-no-reload-xxx` does not have the `secrets-reloader.security.bank-vaults.io/reload-on-secret-change: "true"` annotation set
144145
- the pod `reloader-test-deployment-fixed-versions-no-reload-xxx` - although it does have the annotation - only uses versioned secrets, so they won't be reloaded for the latest version of the secret.
145146
146-
2. Change two secrets used in a workload, observe the previous pod to be recreated again, also that the pod `reloader-test-daemonset-xxx` only restarted once, although it uses both of these secrets. The number a workload got "reloaded" by the Reloader can be checked on the `alpha.vault.security.banzaicloud.io/secret-reload-count` annotation that is used to trigger a new rollout.
147+
2. Change two secrets used in a workload, observe the previous pod to be recreated again, also that the pod `reloader-test-daemonset-xxx` only restarted once, although it uses both of these secrets. The number a workload got "reloaded" by the Reloader can be checked on the `secrets-reloader.security.bank-vaults.io/secret-reload-count` annotation that is used to trigger a new rollout.
147148
148149
```bash
149150
vault kv patch secret/accounts/aws AWS_SECRET_ACCESS_KEY=s3cr3t2

pkg/reloader/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const (
3737
DaemonSetKind = "DaemonSet"
3838
StatefulSetKind = "StatefulSet"
3939

40-
SecretReloadAnnotationName = "alpha.vault.security.banzaicloud.io/reload-on-secret-change"
41-
ReloadCountAnnotationName = "alpha.vault.security.banzaicloud.io/secret-reload-count"
40+
SecretReloadAnnotationName = "secrets-reloader.security.bank-vaults.io/reload-on-secret-change"
41+
ReloadCountAnnotationName = "secrets-reloader.security.bank-vaults.io/secret-reload-count"
4242
)
4343

4444
// Controller is the controller implementation for Foo resources

pkg/reloader/reloader_test.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,42 @@ import (
2323
)
2424

2525
func TestIncrementReloadCountAnnotation(t *testing.T) {
26-
podTemplate := corev1.PodTemplateSpec{
27-
ObjectMeta: metav1.ObjectMeta{
28-
Annotations: map[string]string{},
26+
tests := []struct {
27+
name string
28+
annotations map[string]string
29+
expectedAnnotations map[string]string
30+
}{
31+
{
32+
name: "no annotation should add annotation",
33+
annotations: map[string]string{},
34+
expectedAnnotations: map[string]string{
35+
ReloadCountAnnotationName: "1",
36+
},
37+
},
38+
{
39+
name: "existing annotation should increment annotation",
40+
annotations: map[string]string{
41+
ReloadCountAnnotationName: "1",
42+
},
43+
expectedAnnotations: map[string]string{
44+
ReloadCountAnnotationName: "2",
45+
},
2946
},
3047
}
3148

32-
incrementReloadCountAnnotation(&podTemplate)
33-
assert.Equal(t, "1", podTemplate.GetAnnotations()[ReloadCountAnnotationName])
34-
incrementReloadCountAnnotation(&podTemplate)
35-
assert.Equal(t, "2", podTemplate.GetAnnotations()[ReloadCountAnnotationName])
49+
for _, tt := range tests {
50+
ttp := tt
51+
t.Run(ttp.name, func(t *testing.T) {
52+
53+
podTemplateSpec := &corev1.PodTemplateSpec{
54+
ObjectMeta: metav1.ObjectMeta{
55+
Annotations: ttp.annotations,
56+
},
57+
}
58+
59+
incrementReloadCountAnnotation(podTemplateSpec)
60+
61+
assert.Equal(t, ttp.expectedAnnotations, podTemplateSpec.Annotations)
62+
})
63+
}
3664
}

0 commit comments

Comments
 (0)