Skip to content

Commit dd9e07b

Browse files
authored
Merge pull request #1773 from agrare/embedded_workflows_set_credentials_documentation
Add documentation on setting credentials in workflows
2 parents c1aa721 + 7be1631 commit dd9e07b

File tree

1 file changed

+86
-4
lines changed

1 file changed

+86
-4
lines changed

managing_providers/_topics/embedded_workflows.md

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Workflows must be authored in Amazon State Languages (ASL) format. As part of au
173173

174174
#### Running an Embedded Workflow on Appliances
175175

176-
* On appliances, `podman` is used to execute the container so use [podman login](https://docs.podman.io/en/stable/markdown/podman-login.1.html) as the `manageiq` user.
176+
* On appliances, `podman` is used to execute the container so use [podman login](https://docs.podman.io/en/stable/markdown/podman-login.1.html) as the `manageiq` user.
177177

178178
```text
179179
# su manageiq
@@ -183,12 +183,12 @@ Workflows must be authored in Amazon State Languages (ASL) format. As part of au
183183
Login Succeeded!
184184
```
185185
186-
If you use the --root flag in the podman pull, images are pulled to a local directory '/var/www/miq/vmdb/data/containers/storage' as in the example
187-
186+
If you use the --root flag in the podman pull, images are pulled to a local directory '/var/www/miq/vmdb/data/containers/storage' as in the example
187+
188188
```text
189189
podman pull <repository>/<image>:<tag> --root /var/www/miq/vmdb/data/containers/storage
190190
```
191-
191+
192192
It is worth noting that the default /home/manageiq partition has insufficient space to store large images.
193193
194194
You can use any repository to store your images, for example you can use docker.io [access token](https://docs.docker.com/security/for-developers/access-tokens/) so that the token does not expire.
@@ -307,6 +307,88 @@ If the user is running an embedded workflow on OCP, and is using a docker reposi
307307
}
308308
```
309309

310+
#### Credentials
311+
312+
{{ site.data.product.title_short }} provides a mechanism for securely passing credentials to your running workflows. Credentials should never be set statically in your workflow definition.
313+
314+
Long lived credentials like usernames and passwords should be defined as Mapped Credentials as described in `Adding Credentials`.
315+
316+
Short lived credentials such as bearer tokens which are obtained while the workflow is running can be set as state output and stored securely in the Credentials field for further states. This can be accomplished by using `ResultPath` with a path starting with `$.Credentials`. This will set the output of the state in the `Credentials` payload.
317+
318+
For an example lets say we have a State which takes a username and password and outputs a bearer token to be used later on:
319+
320+
```asl
321+
"Login": {
322+
"Type": "Task",
323+
"Resource": "docker://login:latest",
324+
"Credentials": {
325+
"username.$": "$.username",
326+
"password.$": "$.password"
327+
},
328+
"ResultPath": "$.Credentials",
329+
"Next": "NextState"
330+
}
331+
```
332+
333+
If the output of the docker image is `{"bearer_token":"abcd"}` then we will be able to use this in the next state like so:
334+
335+
```asl
336+
"NextState": {
337+
"Type": "Task",
338+
"Resource": "docker://do-something:latest",
339+
"Credentials": {
340+
"token.$": "$.bearer_token"
341+
}
342+
}
343+
```
344+
345+
All of the normal Input/Output processing still applies so if you need to manipulate the output you can use `ResultSelector`. Say for example our login docker image outputs the token as `{"result":"abcd"}` but we want to store it as `"bearer_token"`. We can use `ResultSelector` to change this:
346+
347+
```asl
348+
"Login": {
349+
"Type": "Task",
350+
"Resource": "docker://login:latest",
351+
"Credentials": {
352+
"username.$": "$.username",
353+
"password.$": "$.password"
354+
},
355+
"ResultSelector": {
356+
"bearer_token.$": "$.result"
357+
},
358+
"ResultPath": "$.Credentials",
359+
"Next": "NextState"
360+
}
361+
```
362+
363+
We can also store the result in a parent node for organization:
364+
365+
```asl
366+
"Login": {
367+
"Type": "Task",
368+
"Resource": "docker://login:latest",
369+
"Credentials": {
370+
"username.$": "$.username",
371+
"password.$": "$.password"
372+
},
373+
"ResultPath": "$.Credentials.VMware",
374+
"Next": "NextState"
375+
}
376+
```
377+
378+
And then access it like:
379+
380+
```asl
381+
"NextState": {
382+
"Type": "Task",
383+
"Resource": "docker://do-something:latest",
384+
"Credentials": {
385+
"token.$": "$.VMware.bearer_token"
386+
}
387+
}
388+
```
389+
390+
If you have a mapped credential and your state overwrites its, a new non-mapped entry will be created and the original mapped credential will be left intact.
391+
310392
### Viewing workflow details
311393

312394
Once a workflow is imported, you can view the details, such as to verify the payload. To view the details for a workflow:

0 commit comments

Comments
 (0)