Skip to content

Commit ba6153f

Browse files
committed
docs: use pipefail option in shell commands to prevent accidental deletions
Signed-off-by: Jack Henschel <[email protected]>
1 parent d3aa647 commit ba6153f

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

Diff for: docs/usage.md

+28-18
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ spec:
3434
project: default
3535
```
3636
37-
3. Or you can pass the config-management-plugin flag to the Argo CD CLI app create command:
37+
3. Or you can pass the config-management-plugin flag to the Argo CD CLI app create command:
3838
`argocd app create you-app-name --config-management-plugin argocd-vault-plugin`
3939

40+
**WARNING**: it is extremely important that the `command` used in the plugin definition produces a non-zero exit code if *any* errors occurs. Otherwise, Argo CD will treat partial or empty output as valid and start deleting or modifying resources. Thus it is **strongly recommended** to use the `pipefail`, `errexit` and `nounset` shell options, see also [Writing Safe Shell Scripts](https://sipb.mit.edu/doc/safe-shell/).
41+
4042
#### With Helm
4143
If you want to use Helm along with argocd-vault-plugin, use the instructions matching your [plugin installation method](../installation).
4244

@@ -46,10 +48,10 @@ For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
4648
configManagementPlugins: |
4749
- name: argocd-vault-plugin-helm
4850
init:
49-
command: [sh, -c]
51+
command: ["/bin/sh", "-c"]
5052
args: ["helm dependency build"]
5153
generate:
52-
command: ["sh", "-c"]
54+
command: ["/bin/bash", "-o", "pipefail", "-c"]
5355
args: ["helm template $ARGOCD_APP_NAME . --include-crds | argocd-vault-plugin generate -"]
5456
```
5557
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -65,12 +67,14 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
6567
discover:
6668
find:
6769
command:
68-
- sh
70+
- "/bin/sh"
6971
- "-c"
7072
- "find . -name 'Chart.yaml' && find . -name 'values.yaml'"
7173
generate:
7274
command:
73-
- sh
75+
- "/bin/bash"
76+
- "-o"
77+
- "pipefail" # exit with non-zero code if any command in pipeline fails
7478
- "-c"
7579
- |
7680
helm template $ARGOCD_APP_NAME --include-crds . |
@@ -82,19 +86,19 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
8286

8387
Use this option if you want to use Helm along with argocd-vault-plugin and use additional helm args.
8488

85-
**IMPORTANT**: passing `${ARGOCD_ENV_HELM_ARGS}` effectively allows users to run arbitrary code in the Argo CD
86-
repo-server (or, if using a sidecar, in the plugin sidecar). Only use this when the users are completely trusted. If
89+
**IMPORTANT**: passing `${ARGOCD_ENV_HELM_ARGS}` effectively allows users to run arbitrary code in the Argo CD
90+
repo-server (or, if using a sidecar, in the plugin sidecar). Only use this when the users are completely trusted. If
8791
possible, determine which Helm arguments are needed by your users and explicitly pass only those arguments.
8892

8993
For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
9094
```yaml
9195
configManagementPlugins: |
9296
- name: argocd-vault-plugin-helm
9397
init:
94-
command: [sh, -c]
98+
command: ["/bin/sh", "-c"]
9599
args: ["helm dependency build"]
96100
generate:
97-
command: ["sh", "-c"]
101+
command: ["/bin/bash", "-o", "pipefail", "-c"]
98102
args: ["helm template $ARGOCD_APP_NAME -n $ARGOCD_APP_NAMESPACE ${ARGOCD_ENV_HELM_ARGS} . --include-crds | argocd-vault-plugin generate -"]
99103
```
100104
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -110,12 +114,14 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
110114
discover:
111115
find:
112116
command:
113-
- sh
117+
- "/bin/sh"
114118
- "-c"
115119
- "find . -name 'Chart.yaml' && find . -name 'values.yaml'"
116120
generate:
117121
command:
118-
- sh
122+
- "/bin/bash"
123+
- "-o"
124+
- "pipefail" # exit with non-zero code if any command in pipeline fails
119125
- "-c"
120126
- |
121127
helm template $ARGOCD_APP_NAME --include-crds -n $ARGOCD_APP_NAMESPACE ${ARGOCD_ENV_HELM_ARGS} . |
@@ -134,7 +140,7 @@ Helm args must be defined in the application manifest:
134140
value: -f values-dev.yaml -f values-dev-tag.yaml
135141
```
136142

137-
**Note: Bypassing the parameters like this can be dangerous in a multi-tenant environment as it could allow for malicious injection of arbitrary commands. So be cautious when doing something like in a production environment. Ensuring proper permissions and protections is very important when doing something like this.**
143+
**NOTE**: Bypassing the parameters like this can be dangerous in a multi-tenant environment as it could allow for malicious injection of arbitrary commands. So be cautious when doing something like in a production environment. Ensuring proper permissions and protections is very important when doing something like this.
138144

139145
##### With an inline values file
140146
Alternatively, if you'd like to use values inline in your application manifest (similar to the ArgoCD CLI's `--values-literal-file` option), you can create a plugin like this (note the use of `bash` instead of `sh` here):
@@ -144,7 +150,7 @@ For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
144150
configManagementPlugins: |
145151
- name: argocd-vault-plugin-helm
146152
generate:
147-
command: ["bash", "-c"]
153+
command: ["/bin/bash", "-o", "pipefail", "-c"]
148154
args: ['helm template "$ARGOCD_APP_NAME" -f <(echo "$ARGOCD_ENV_HELM_VALUES") . | argocd-vault-plugin generate -']
149155
```
150156
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -160,12 +166,14 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
160166
discover:
161167
find:
162168
command:
163-
- sh
169+
- "/bin/sh"
164170
- "-c"
165171
- "find . -name 'Chart.yaml' && find . -name 'values.yaml'"
166172
generate:
167173
command:
168-
- bash
174+
- "/bin/bash"
175+
- "-o"
176+
- "pipefail"
169177
- "-c"
170178
- |
171179
helm template $ARGOCD_APP_NAME -n $ARGOCD_APP_NAMESPACE -f <(echo "$ARGOCD_ENV_HELM_VALUES") . |
@@ -205,7 +213,7 @@ For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
205213
configManagementPlugins: |
206214
- name: argocd-vault-plugin-kustomize
207215
generate:
208-
command: ["sh", "-c"]
216+
command: ["/bin/bash" , "-o", "pipefail", "-c"]
209217
args: ["kustomize build . | argocd-vault-plugin generate -"]
210218
```
211219
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -227,7 +235,9 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
227235
- kustomization.yaml
228236
generate:
229237
command:
230-
- sh
238+
- "/bin/bash"
239+
- "-o"
240+
- "pipefail"
231241
- "-c"
232242
- "kustomize build . | argocd-vault-plugin generate -"
233243
lockRepo: false
@@ -276,7 +286,7 @@ The plugin will work with both YAML and JSON output from jsonnet.
276286
#### Refreshing values from Secrets Managers
277287
If you want to load in a new value from your Secret Manager without making any new code changes you must use the Hard-Refresh concept in Argo CD. This can be done in two ways. You can either use the UI and select the `Hard Refresh` button which is located within the `Refresh Button`.
278288

279-
<img src="https://github.com/argoproj-labs/argocd-vault-plugin/raw/main/assets/hard-refresh.png" width="300">
289+
<img src="https://github.com/argoproj-labs/argocd-vault-plugin/raw/main/assets/hard-refresh.png" width="300">
280290

281291
You can also use the `argocd app diff` command passing the `--hard-refresh` flag. This will run argocd-vault-plugin again and pull in the new values from your Secret Manager and then you can either have Auto Sync setup or Sync manually to apply the new values.
282292

0 commit comments

Comments
 (0)