square-agency-59624
11/24/2025, 8:13 PM@fl.task(
container_image=basic_image_spec,
resources=fl.Resources(cpu="1", mem="1Gi", ephemeral_storage="1Gi"),
secret_requests=[
fl.Secret(group="test", key="RAMA_WAS_HERE"),
fl.Secret(group="test", key="RAMA_WAS_HERE_2"),
],
)
def test_secrets_task():
context = fl.current_context()
secret_val = context.secrets.get("test", "RAMA_WAS_HERE")
print(secret_val)
secret_val2 = context.secrets.get("test", "RAMA_WAS_HERE_2")
print(secret_val2)
test = os.getenv("RAMA_WAS_HERE")
if test is None:
raise ValueError("secret1 is not set")
test2 = os.getenv("RAMA_WAS_HERE_2")
if test2 is None:
raise ValueError("secret2 is not set")
return {"test": test, "test2": test2}
@fl.workflow()
def test_secrets():
test_secrets_task()ancient-wolf-19325
11/24/2025, 8:13 PM_FSEC_ and including the group and key (e.g., _FSEC_TEST_RAMA_WAS_HERE). The recommended and portable way to access secrets in Flyte tasks is through the context object: `context.secrets.get("test", "RAMA_WAS_HERE")`βthis abstracts away the underlying environment variable or file mounting details and ensures compatibility across secret managers and Flyte versions. Directly using os.getenv("RAMA_WAS_HERE") will not work unless you manually set tSorry, there was a temporary error when processing your request.
Please try again. If this problem persists, please contact support. π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.square-agency-59624
11/24/2025, 8:16 PMancient-wolf-19325
11/24/2025, 8:16 PMsecret_requests parameter are not automatically injected as environment variables with the key name you specify (e.g., RAMA_WAS_HERE). Instead, Flyte injects secrets using internal environment variable names (like _FSEC_<GROUP>_<KEY>) or mounts them as files, and the recommended way to access them is through flytekit.current_context().secrets.get(group, key). Direct access via os.getenv("RAMA_WAS_HERE") will not work unless you explicitly configure the secret to be mounted as an environment variable with that exact name, which is not the default behavior in Flyte v1. This is confirmed in this issue and the documentation.
If you want to control the environment variable name, you must use the env_var parameter in the Secret object (supported in newer Flyte versions, e.g., v1.15+), or read the secret using the context manager as shown in your code. For Flyte v1, the context-based access is the supported and portable method. Would you like more detail or examples on how to set the env_var parameter or upgrade to a version that supports it?
Sources:
- Flyte issue: control ENV var name for injected secrets
- Flyte documentation: Using secrets in tasks π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.