Skip to content

Commit ea14a66

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 ea14a66

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Diff for: docs/usage.md

+23-12
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ 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
41+
It is extremely important that `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/).
42+
4043
#### With Helm
4144
If you want to use Helm along with argocd-vault-plugin, use the instructions matching your [plugin installation method](../installation).
4245

@@ -49,7 +52,7 @@ configManagementPlugins: |
4952
command: [sh, -c]
5053
args: ["helm dependency build"]
5154
generate:
52-
command: ["sh", "-c"]
55+
command: ["sh", "-o", "pipefail", "-c"]
5356
args: ["helm template $ARGOCD_APP_NAME . --include-crds | argocd-vault-plugin generate -"]
5457
```
5558
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -71,6 +74,8 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
7174
generate:
7275
command:
7376
- sh
77+
- "-o"
78+
- "pipefail" # exit with non-zero code if any command in pipeline fails
7479
- "-c"
7580
- |
7681
helm template $ARGOCD_APP_NAME --include-crds . |
@@ -82,8 +87,8 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
8287

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

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
90+
**IMPORTANT**: passing `${ARGOCD_ENV_HELM_ARGS}` effectively allows users to run arbitrary code in the Argo CD
91+
repo-server (or, if using a sidecar, in the plugin sidecar). Only use this when the users are completely trusted. If
8792
possible, determine which Helm arguments are needed by your users and explicitly pass only those arguments.
8893

8994
For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
@@ -94,7 +99,7 @@ configManagementPlugins: |
9499
command: [sh, -c]
95100
args: ["helm dependency build"]
96101
generate:
97-
command: ["sh", "-c"]
102+
command: ["sh", "-o", "pipefail", "-c"]
98103
args: ["helm template $ARGOCD_APP_NAME -n $ARGOCD_APP_NAMESPACE ${ARGOCD_ENV_HELM_ARGS} . --include-crds | argocd-vault-plugin generate -"]
99104
```
100105
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -115,7 +120,9 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
115120
- "find . -name 'Chart.yaml' && find . -name 'values.yaml'"
116121
generate:
117122
command:
118-
- sh
123+
- "sh"
124+
- "-o"
125+
- "pipefail" # exit with non-zero code if any command in pipeline fails
119126
- "-c"
120127
- |
121128
helm template $ARGOCD_APP_NAME --include-crds -n $ARGOCD_APP_NAMESPACE ${ARGOCD_ENV_HELM_ARGS} . |
@@ -134,7 +141,7 @@ Helm args must be defined in the application manifest:
134141
value: -f values-dev.yaml -f values-dev-tag.yaml
135142
```
136143

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.**
144+
**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.**
138145

139146
##### With an inline values file
140147
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 +151,7 @@ For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
144151
configManagementPlugins: |
145152
- name: argocd-vault-plugin-helm
146153
generate:
147-
command: ["bash", "-c"]
154+
command: ["bash", "-o", "pipefail", "-c"]
148155
args: ['helm template "$ARGOCD_APP_NAME" -f <(echo "$ARGOCD_ENV_HELM_VALUES") . | argocd-vault-plugin generate -']
149156
```
150157
For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [add a sidecar to run it](../installation#initcontainer-and-configuration-via-sidecar):
@@ -165,7 +172,9 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
165172
- "find . -name 'Chart.yaml' && find . -name 'values.yaml'"
166173
generate:
167174
command:
168-
- bash
175+
- "sh"
176+
- "-o"
177+
- "pipefail"
169178
- "-c"
170179
- |
171180
helm template $ARGOCD_APP_NAME -n $ARGOCD_APP_NAMESPACE -f <(echo "$ARGOCD_ENV_HELM_VALUES") . |
@@ -205,7 +214,7 @@ For `argocd-cm` ConfigMap configured plugins, add this to `argod-cm` ConfigMap:
205214
configManagementPlugins: |
206215
- name: argocd-vault-plugin-kustomize
207216
generate:
208-
command: ["sh", "-c"]
217+
command: ["sh" , "-o", "pipefail", "-c"]
209218
args: ["kustomize build . | argocd-vault-plugin generate -"]
210219
```
211220
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 +236,9 @@ For sidecar configured plugins, add this to `cmp-plugin` ConfigMap, and then [ad
227236
- kustomization.yaml
228237
generate:
229238
command:
230-
- sh
239+
- "sh"
240+
- "-o"
241+
- "pipefail"
231242
- "-c"
232243
- "kustomize build . | argocd-vault-plugin generate -"
233244
lockRepo: false
@@ -276,7 +287,7 @@ The plugin will work with both YAML and JSON output from jsonnet.
276287
#### Refreshing values from Secrets Managers
277288
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`.
278289

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

281292
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.
282293

0 commit comments

Comments
 (0)