Hi Team, We are trying to use secrets in our task...
# ask-the-community
v
Hi Team, We are trying to use secrets in our task, but when we try to find in environment variable we are unable to find them
Copy code
@task(
    secret_requests=[
        Secret(
            group="proxy-credentials",
            key="proxy-addr",
            mount_requirement=Secret.MountType.ENV_VAR,
        ),
        Secret(
            group="proxy-credentials",
            key="proxy-username",
            mount_requirement=Secret.MountType.ENV_VAR,
        ),
        Secret(
            group="proxy-credentials",
            key="proxy-password",
            mount_requirement=Secret.MountType.ENV_VAR,
        ),
    ],
    requests=Resources(cpu="100m", mem="50Mi"),
    limits=Resources(cpu="200m", mem="1Gi"),
)
def secret_test(
    env: dict,
    brand: str,
) -> TestOutput:
    print(f"----------------------Calling Secret Test----------------------")
    PROXY_USERNAME = {os.environ["PROXY_USERNAME"]}
    PROXY_PASSWORD = {os.environ["PROXY_PASSWORD"]}
    PROXY_ADDR = {os.environ["PROXY_ADDR"]}
    return test_output(PROXY_USERNAME=PROXY_USERNAME, PROXY_PASSWORD=PROXY_PASSWORD, PROXY_ADDR=PROXY_ADDR)
When I print the all the environment i am unable to see them. As per doc it specify that if we add
mount_requirement=Secret.MountType.ENV_VAR,
it would be available in env variable. I have checked with
kubectl get secrets -A
i am able to see the secrets. So could you please help us if there any steps we are missing.
Copy code
"asctime": "2023-08-11 15:28:45,367", "name": "flytekit", "levelname": "ERROR", "message": "Exception when executing Unable to find secret for key None in group PROXY-CREDENTIALS in Env Var:_FSEC_PROXY-CREDENTIALS and FilePath: /etc/secrets/proxy-credentials", "exc_info": "Traceback (most recent call last):\n  File \"/opt/venv/lib/python3.9/site-packages/flytekit/exceptions/scopes.py\", line 206, in user_entry_point\n    return wrapped(*args, **kwargs)\n  File \"/root/model_training/collaborative_filtering.py\", line 171, in dbt_create_user_events\n    print(f\" Secrets: {context.secrets.get(group=SECRET_GROUP)}\")
I looked into the error traces and have find out this message
Unable to find secret for key None in group PROXY-CREDENTIALS in Env Var:_FSEC_PROXY-CREDENTIALS
why its looking for
_FSEC_PROXY-CREDENTIALS
?
y
This looks like the issue: https://github.com/flyteorg/flyte/issues/2260. Try removing
-
in the group name.
v
Thanks @Yicheng Lu, i will try