Skip to content

Commit 5acb722

Browse files
authored
Merge pull request #579 from mbaldessari/push-secrets
Add a pushsecrets policy and vault path for ESO syncing
2 parents 0a20ea6 + 9aef778 commit 5acb722

14 files changed

Lines changed: 117 additions & 43 deletions

ansible/plugins/filter/parse_acm_secrets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ def parse_acm_secrets(secrets):
7979

8080

8181
class FilterModule:
82+
8283
def filters(self):
8384
return {"parse_acm_secrets": parse_acm_secrets}

ansible/plugins/module_utils/load_secrets_v1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727

2828
class LoadSecretsV1:
29+
2930
def __init__(
3031
self,
3132
module,

ansible/plugins/module_utils/load_secrets_v2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141

4242
class LoadSecretsV2:
43+
4344
def __init__(self, module, syaml, namespace, pod):
4445
self.module = module
4546
self.namespace = namespace

ansible/plugins/module_utils/parse_secrets_v2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343

4444
class ParseSecretsV2:
45+
4546
def __init__(self, module, syaml, secrets_backing_store):
4647
self.module = module
4748
self.syaml = syaml

ansible/plugins/modules/vault_load_parsed_secrets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383

8484
class VaultSecretLoader:
85+
8586
def __init__(
8687
self,
8788
module,

ansible/roles/vault_utils/README.md

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ unseal_namespace: "imperative"
4040
4141
This relies on [kubernetes.core](https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html)
4242
43+
## Vault out of the box configuration
44+
45+
This role configures four secret paths in vault:
46+
47+
1. `secret/global` - Any secret under this path is accessible in read-only only to all clusters known to ACM (hub and spokes)
48+
2. `secret/hub` - Any secret under this path is accessible in read-only only to the ACM hub cluster
49+
3. `secret/<fqdn.of.spoke.cluster>` - Any secret under this path is accessible in read-only only to the spoke cluster
50+
4. `secret/pushsecrets` - Any secret here can be accessed in read and write mode to all clusters known to ACM. This area can
51+
be used with ESO's `PushSecrets` so you can push an existing secret from one namespace, to the vault under this path and
52+
then it can be retrieved by an `ExternalSecret` either in a different namespace *or* from an entirely different cluster.
53+
4354
## Values secret file format
4455

4556
Currently this role supports two formats: version 1.0 (which is the assumed
@@ -58,46 +69,6 @@ secret file.
5869
The values secret YAML files can be encrypted with `ansible-vault`. If the role detects they are encrypted, the password to
5970
decrypt them will be prompted when needed.
6071

61-
### Version 1.0
62-
63-
Here is a well-commented example of a version 1.0 file:
64-
65-
```yaml
66-
---
67-
# By default when a top-level 'version: 1.0' is missing it is assumed to be '1.0'
68-
# NEVER COMMIT THESE VALUES TO GIT
69-
70-
secrets:
71-
# These secrets will be pushed in the vault at secret/hub/test The vault will
72-
# have secret/hub/test with secret1 and secret2 as keys with their associated
73-
# values (secrets)
74-
test:
75-
secret1: foo
76-
secret2: bar
77-
78-
# This ends up as the s3Secret attribute to the path secret/hub/aws
79-
aws:
80-
s3Secret: test-secret
81-
82-
# This will create the vault key secret/hub/testfoo which will have two
83-
# properties 'b64content' and 'content' which will be the base64-encoded
84-
# content and the normal content respectively
85-
files:
86-
testfoo: ~/ca.crt
87-
# These secrets will be pushed in the vault at secret/region1/test The vault will
88-
# have secret/region1/test with secret1 and secret2 as keys with their associated
89-
# values (secrets)
90-
secrets.region1:
91-
test:
92-
secret1: foo1
93-
secret2: bar1
94-
# This will create the vault key secret/region2/testbar which will have two
95-
# properties 'b64content' and 'content' which will be the base64-encoded
96-
# content and the normal content respectively
97-
files.region2:
98-
testbar: ~/ca.crt
99-
```
100-
10172
### Version 2.0
10273

10374
Here is a version 2.0 example file (specifying `version: 2.0` is mandatory in this case):
@@ -210,6 +181,46 @@ secrets:
210181
ini_key: aws_secret_access_key
211182
```
212183

184+
### Version 1.0
185+
186+
Here is a well-commented example of a version 1.0 file:
187+
188+
```yaml
189+
---
190+
# By default when a top-level 'version: 1.0' is missing it is assumed to be '1.0'
191+
# NEVER COMMIT THESE VALUES TO GIT
192+
193+
secrets:
194+
# These secrets will be pushed in the vault at secret/hub/test The vault will
195+
# have secret/hub/test with secret1 and secret2 as keys with their associated
196+
# values (secrets)
197+
test:
198+
secret1: foo
199+
secret2: bar
200+
201+
# This ends up as the s3Secret attribute to the path secret/hub/aws
202+
aws:
203+
s3Secret: test-secret
204+
205+
# This will create the vault key secret/hub/testfoo which will have two
206+
# properties 'b64content' and 'content' which will be the base64-encoded
207+
# content and the normal content respectively
208+
files:
209+
testfoo: ~/ca.crt
210+
# These secrets will be pushed in the vault at secret/region1/test The vault will
211+
# have secret/region1/test with secret1 and secret2 as keys with their associated
212+
# values (secrets)
213+
secrets.region1:
214+
test:
215+
secret1: foo1
216+
secret2: bar1
217+
# This will create the vault key secret/region2/testbar which will have two
218+
# properties 'b64content' and 'content' which will be the base64-encoded
219+
# content and the normal content respectively
220+
files.region2:
221+
testbar: ~/ca.crt
222+
```
223+
213224
Internals
214225
---------
215226

ansible/roles/vault_utils/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ vault_spoke_capabilities: '[\\\"read\\\"]'
1717
vault_spoke_ttl: "15m"
1818
vault_global_policy: global
1919
vault_global_capabilities: '[\\\"read\\\"]'
20+
vault_pushsecrets_policy: pushsecrets
21+
vault_pushsecrets_capabilities: '[\\\"create\\\",\\\"read\\\",\\\"update\\\",\\\"delete\\\"]'
2022
external_secrets_ns: golang-external-secrets
2123
external_secrets_sa: golang-external-secrets
2224
external_secrets_secret: golang-external-secrets

ansible/roles/vault_utils/tasks/vault_secrets_init.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@
7171
pod: "{{ vault_pod }}"
7272
command: "vault policy write {{ vault_global_policy }}-secret /tmp/policy-{{ vault_global_policy }}.hcl"
7373

74+
- name: Configure VP pushsecrets policy template
75+
kubernetes.core.k8s_exec:
76+
namespace: "{{ vault_ns }}"
77+
pod: "{{ vault_pod }}"
78+
command: >
79+
bash -e -c "echo \"path \\\"secret/data/{{ vault_pushsecrets_policy }}/*\\\" {
80+
capabilities = {{ vault_pushsecrets_capabilities }} }\" > /tmp/policy-{{ vault_pushsecrets_policy }}.hcl"
81+
82+
- name: Add metadata path to the pushsecrets policy
83+
kubernetes.core.k8s_exec:
84+
namespace: "{{ vault_ns }}"
85+
pod: "{{ vault_pod }}"
86+
command: >
87+
bash -e -c "echo \"path \\\"secret/metadata/{{ vault_pushsecrets_policy }}/*\\\" {
88+
capabilities = {{ vault_pushsecrets_capabilities }} }\" >> /tmp/policy-{{ vault_pushsecrets_policy }}.hcl"
89+
90+
- name: Configure VP pushsecrets policy
91+
kubernetes.core.k8s_exec:
92+
namespace: "{{ vault_ns }}"
93+
pod: "{{ vault_pod }}"
94+
command: "vault policy write {{ vault_pushsecrets_policy }}-secret /tmp/policy-{{ vault_pushsecrets_policy }}.hcl"
95+
7496
- name: Configure policy template for hub
7597
kubernetes.core.k8s_exec:
7698
namespace: "{{ vault_ns }}"
@@ -93,4 +115,4 @@
93115
vault write auth/"{{ vault_hub }}"/role/"{{ vault_hub }}"-role
94116
bound_service_account_names="{{ external_secrets_sa }}"
95117
bound_service_account_namespaces="{{ external_secrets_ns }}"
96-
policies="default,{{ vault_global_policy }}-secret,{{ vault_hub }}-secret" ttl="{{ vault_hub_ttl }}"
118+
policies="default,{{ vault_global_policy }}-secret,{{ vault_pushsecrets_policy }}-secret,{{ vault_hub }}-secret" ttl="{{ vault_hub_ttl }}"

ansible/roles/vault_utils/tasks/vault_spokes_init.yaml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
loop_control:
158158
label: "{{ item.key }}"
159159

160-
- name: Configure policy template
160+
- name: Configure spoke policy template
161161
kubernetes.core.k8s_exec:
162162
namespace: "{{ vault_ns }}"
163163
pod: "{{ vault_pod }}"
@@ -171,6 +171,34 @@
171171
loop_control:
172172
label: "{{ item.key }}"
173173

174+
- name: Configure spoke pushsecrets policy template
175+
kubernetes.core.k8s_exec:
176+
namespace: "{{ vault_ns }}"
177+
pod: "{{ vault_pod }}"
178+
command: >
179+
bash -e -c "echo \"path \\\"secret/data/{{ vault_pushsecrets_policy }}/*\\\" {
180+
capabilities = {{ vault_pushsecrets_capabilities }} }\" >> /tmp/policy-{{ item.value['vault_path'] }}.hcl"
181+
loop: "{{ clusters_info | dict2items }}"
182+
when:
183+
- item.value['esoToken'] is defined
184+
- item.key != "local-cluster"
185+
loop_control:
186+
label: "{{ item.key }}"
187+
188+
- name: Configure spoke pushsecrets metadata policy template
189+
kubernetes.core.k8s_exec:
190+
namespace: "{{ vault_ns }}"
191+
pod: "{{ vault_pod }}"
192+
command: >
193+
bash -e -c "echo \"path \\\"secret/metadata/{{ vault_pushsecrets_policy }}/*\\\" {
194+
capabilities = {{ vault_pushsecrets_capabilities }} }\" >> /tmp/policy-{{ item.value['vault_path'] }}.hcl"
195+
loop: "{{ clusters_info | dict2items }}"
196+
when:
197+
- item.value['esoToken'] is defined
198+
- item.key != "local-cluster"
199+
loop_control:
200+
label: "{{ item.key }}"
201+
174202
- name: Configure policy for spokes
175203
kubernetes.core.k8s_exec:
176204
namespace: "{{ vault_ns }}"
@@ -191,7 +219,7 @@
191219
vault write auth/"{{ item.value['vault_path'] }}"/role/"{{ item.value['vault_path'] }}"-role
192220
bound_service_account_names="{{ external_secrets_sa }}"
193221
bound_service_account_namespaces="{{ external_secrets_ns }}"
194-
policies="default,{{ vault_global_policy }}-secret,{{ item.value['vault_path'] }}-secret" ttl="{{ vault_spoke_ttl }}"
222+
policies="default,{{ vault_global_policy }}-secret,{{ vault_pushsecrets_policy }}-secret,{{ item.value['vault_path'] }}-secret" ttl="{{ vault_spoke_ttl }}"
195223
loop: "{{ clusters_info | dict2items }}"
196224
when:
197225
- item.value['esoToken'] is defined

ansible/tests/unit/test_ini_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
class TestMyModule(unittest.TestCase):
32+
3233
def setUp(self):
3334
self.testdir_v2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), "v2")
3435

0 commit comments

Comments
 (0)