airflow.providers.hashicorp.hooks.vault¶
HashiCorp Vault 的 Hook。
类¶
用于与 HashiCorp Vault KeyValue Secrets 引擎交互的 Hook。 |
模块内容¶
- class airflow.providers.hashicorp.hooks.vault.VaultHook(vault_conn_id=default_conn_name, auth_type=None, auth_mount_point=None, kv_engine_version=None, role_id=None, region=None, kubernetes_role=None, kubernetes_jwt_path=None, token_path=None, gcp_key_path=None, gcp_scopes=None, azure_tenant_id=None, azure_resource=None, radius_host=None, radius_port=None, **kwargs)[source]¶
基类:
airflow.hooks.base.BaseHook
用于与 HashiCorp Vault KeyValue Secrets 引擎交互的 Hook。
- HashiCorp hvac 文档
您连接到连接中指定为主机的地址。连接中的登录/密码通常用作凭据,您可以通过初始化参数或连接中的相应 extras 来指定不同的身份验证参数。
挂载点(mount point)应放在 URL 中的路径位置,类似于 Vault 的 URL 方案:这表示 Secrets 引擎挂载的“路径”。如果未指定,默认值为“secret”。请注意,如果通过其他引擎进行身份验证,则此
mount_point
不用于身份验证。每个引擎使用其特定的身份验证 mount_point。连接中的 extras 与参数名称相同(’kv_engine_version’, ‘auth_type’, …)。
您也可以使用 gcp_keyfile_dict extra 来传递 json 格式的字典,以进行 ‘gcp’ 身份验证。
支持的 URL 方案有“vault”、“http”(使用 http 连接到 vault)或“vaults”和“https”(使用 https 连接到 vault)。
示例 URL
vault://user:password@host:port/mount_point?kv_engine_version=1&auth_type=github
登录/密码用作凭据
approle: login -> connection.login
github: password -> token
token: password -> token
aws_iam: login -> key_id, password -> secret_id
azure: login -> client_id, password -> client_secret
ldap: login -> username, password -> password
userpass: login -> username, password -> password
radius: password -> radius_secret
- 参数:
vault_conn_id (str) – 要使用的连接 ID
auth_type (str | None) – Vault 的身份验证类型。默认为
token
。可用值包括:(‘approle’, ‘github’, ‘gcp’, ‘kubernetes’, ‘ldap’, ‘token’, ‘userpass’)auth_mount_point (str | None) – 可用于定义所选身份验证的挂载点。默认值取决于使用的身份验证方法。
kv_engine_version (int | None) – 选择要运行的引擎版本(
1
或2
)。默认为连接中定义的版本,如果连接中未定义,则默认为2
。role_id (str | None) – 用于
aws_iam
身份验证的角色 ID。region (str | None) – 用于 STS API 调用的 AWS 区域(用于
aws_iam
auth_type)。kubernetes_role (str | None) – 用于身份验证的角色(用于
kubernetes
auth_type)kubernetes_jwt_path (str | None) – kubernetes jwt 令牌的路径(用于
kubernetes
auth_type,默认值:/var/run/secrets/kubernetes.io/serviceaccount/token
)token_path (str | None) – 包含身份验证令牌的文件路径,用于发送到 Vault 的请求中(用于
token
和github
auth_type)。gcp_key_path (str | None) – Google Cloud Service Account 密钥文件(JSON)的路径(用于
gcp
auth_type)与 gcp_keyfile_dict 互斥。gcp_scopes (str | None) – 包含 OAuth2 范围的逗号分隔字符串(用于
gcp
auth_type)azure_tenant_id (str | None) – Azure Active Directory 的租户 ID(用于
azure
auth_type)azure_resource (str | None) – 在 Azure Active Directory 中注册的应用程序的配置 URL(用于
azure
auth_type)radius_host (str | None) – radius 主机(用于
radius
auth_type)radius_port (int | None) – radius 端口(用于
radius
auth_type)
- get_secret(secret_path, secret_version=None)[source]¶
从引擎获取秘密值。
有关详细信息,请参阅 https://hvac.readthedocs.io/en/stable/usage/secrets_engines/kv_v1.html 和 https://hvac.readthedocs.io/en/stable/usage/secrets_engines/kv_v2.html。
- get_secret_metadata(secret_path)[source]¶
从引擎读取秘密元数据(包括版本)。仅对 KV 版本 2 有效。
有关详细信息,请参阅 https://hvac.readthedocs.io/en/stable/usage/secrets_engines/kv_v2.html。
- get_secret_including_metadata(secret_path, secret_version=None)[source]¶
读取包含元数据的秘密。仅对 KV 版本 2 有效。
有关详细信息,请参阅 https://hvac.readthedocs.io/en/stable/usage/secrets_engines/kv_v2.html。
- create_or_update_secret(secret_path, secret, method=None, cas=None)[source]¶
创建或更新秘密。
- 参数:
secret_path (str) – 要读取的路径
secret (dict) – 用于指定路径的要创建或更新的秘密
method (str | None) – 可选参数,用于显式请求向选定的 kv secret 引擎发送 POST (创建) 或 PUT (更新) 请求。如果未为此参数提供参数,则 hvac 会尝试智能地确定哪种方法是合适的。仅对 KV 引擎版本 1 有效
cas (int | None) – 设置要使用 Check-And-Set 操作的“cas”值。如果未设置,则允许写入。如果设置为 0,则只有当密钥不存在时才允许写入。如果索引非零,则只有当密钥的当前版本与 cas 参数中指定的版本匹配时才允许写入。仅对 KV 引擎版本 2 有效。
- 返回:
create_or_update_secret 请求的响应。
- 返回类型:
有关详细信息,请参阅 https://hvac.readthedocs.io/en/stable/usage/secrets_engines/kv_v1.html 和 https://hvac.readthedocs.io/en/stable/usage/secrets_engines/kv_v2.html。