Enabling Azure Key Vault
This documentation exists for customers who must use Azure Key Vault for organizational reasons. For everyone else, we strongly recommend using the Union.ai secrets manager to manage secrets rather than Azure Key Vault.
The Union.ai-managed userflyterole identity must be granted permission to access
Azure Key Vault secrets.
Refer to Azure official documentation for details on creating and managing secrets.
Providing permissions to Azure Key Vault
Union.ai data plane tasks employ Azure Workload Identity Federation to access Azure resources using an Azure user-assigned identity. Access to Azure Key Vault containers requires updating permissions to permit this Union.ai-managed user-assigned identity.
Create a role assignment assigning the Key Vault Secrets User role to the userflyterole user-assigned identity. Make sure it is scoped to the Azure Key Vault Secret.
Refer to
Azure portal’s user assigned managed identitites if assistance is required identifying the userflyterole user-assigned identity within the Union.ai data plane resource group.
Accessing the secret within Union.ai
- Declare a
flyte.Secretin thesecretsof yourTaskEnvironment, wheregroupis the HTTP URI of the secret, in the formathttps://<KEY_VAULT_NAME>.vault.azure.net/secrets/<SECRET_NAME>keyis the secret name,<SECRET_NAME>mountis"/etc/flyte/secrets". Azure Key Vault secrets can only be delivered as files.
- Inside the task, read the secret from the file
/etc/flyte/secrets/<SECRET_NAME>, with the name in lower case.
The latest version of the secret is always retrieved: flyte.Secret has no parameter for a secret version.
Here is an example:
import pathlib
import flyte
VAULT_NAME = "examplevault"
SECRET_NAME = "example-secret"
SECRET_GROUP = f"https://{VAULT_NAME}.vault.azure.net/secrets/{SECRET_NAME}"
env = flyte.TaskEnvironment(
name="azure-key-vault",
secrets=[flyte.Secret(key=SECRET_NAME, group=SECRET_GROUP, mount="/etc/flyte/secrets")],
)
@env.task
def task_with_secret():
secret_val = (pathlib.Path("/etc/flyte/secrets") / SECRET_NAME.lower()).read_text()
# do something with the secret. For example, communication with an external API.
...