https://flyte.org logo
#ask-ai
Title
# ask-ai
g

Greg Linklater

02/12/2024, 10:42 AM
@Glime is it possible to inject secrets into a Shell task?
g

Glime

02/12/2024, 10:43 AM
Based on the provided context, it appears that injecting secrets into a ShellTask directly is not straightforward or may not be supported in the same manner as other task types in Flyte. A discussion post from the Flyte community forum indicates a user having trouble using a ShellTask with secrets, suggesting limitations or challenges with this approach. However, there is a workaround mentioned in another discussion post where a user has managed to use secrets within a shell task by first retrieving the secret value in a separate task and then passing it to the ShellTask. This approach involves generating an environment variable name from the secret and then using it within the ShellTask. To summarize, while directly injecting secrets into a ShellTask might not be directly supported or may present challenges, a workaround involving intermediate tasks to handle secrets and pass them to the ShellTask as environment variables can be considered. --- This is an AI-generated response, take its recommendations with caution. Please help us improve the model accuracy by giving this response a thumbs up/thumbs down reaction. Sources https://discuss.flyte.org/t/1031/hey-all-i-m-having-trouble-using-a-shelltask-with-secrets-in/ https://discuss.flyte.org/t/12112334/is-there-a-recommended-way-to-use-secret-in-a-https-docs-fly/ ๐Ÿ‘ button ๐Ÿ‘Ž button
k

Ketan (kumare3)

02/12/2024, 3:48 PM
Secrets are supported in shell tasks, they are under given env vars
g

Greg Linklater

02/13/2024, 12:41 PM
@Ketan (kumare3) I suppose thereโ€™s a predictable way the
group
and
key
map to the env var name?
k

Ketan (kumare3)

02/14/2024, 12:47 AM
yes
Copy code
import os
from typing import Tuple

import flytekit
from flytekit import Secret, task, workflow
from flytekit.testing import SecretsManager

secret = Secret(
    group="<SECRET_GROUP>",
    key="<SECRET_KEY>",
    mount_requirement=Secret.MountType.ENV_VAR,
)