airflow.providers.yandex.secrets.lockbox¶
与从 Yandex Cloud Lockbox 获取密钥相关的对象。
类¶
从 Yandex Lockbox 检索连接、变量或配置。 |
模块内容¶
- class airflow.providers.yandex.secrets.lockbox.LockboxSecretBackend(yc_oauth_token=None, yc_sa_key_json=None, yc_sa_key_json_path=None, yc_connection_id=None, folder_id='', connections_prefix='airflow/connections', variables_prefix='airflow/variables', config_prefix='airflow/config', sep='/', endpoint=None)[source]¶
基类:
airflow.secrets.BaseSecretsBackend
,airflow.utils.log.logging_mixin.LoggingMixin
从 Yandex Lockbox 检索连接、变量或配置。
可通过
airflow.cfg
进行如下配置:[secrets] backend = airflow.providers.yandex.secrets.lockbox.LockboxSecretBackend backend_kwargs = {"connections_prefix": "airflow/connections"}
例如,当设置
{"connections_prefix": "airflow/connections"}
时,如果密钥使用路径airflow/connections/smtp_default
定义,则可以使用 conn_id 为smtp_default
的连接。当设置
{"variables_prefix": "airflow/variables"}
时,如果密钥使用路径airflow/variables/hello
定义,则可以使用名称为hello
的变量。当设置
{"config_prefix": "airflow/config"}
时,如果密钥使用路径airflow/config/sql_alchemy_conn
定义,则可以使用 key 为sql_alchemy_conn
的配置。如果前缀为空,则不会向 Yandex Lockbox 发送请求。
[secrets] backend = airflow.providers.yandex.secrets.lockbox.LockboxSecretBackend backend_kwargs = {"yc_connection_id": "<connection_ID>", "folder_id": "<folder_ID>"}
您需要指定凭据或
yandexcloud
连接的 ID 以连接到 Yandex Lockbox。凭据将按以下优先级使用:OAuth 令牌
文件中的 JSON 格式服务账号密钥
JSON 格式服务账号密钥
Yandex Cloud 连接
如果您未指定任何凭据,系统将使用默认连接 ID:
yandexcloud_default
。此外,您还需要指定 Yandex Cloud 文件夹 ID,以便在其中搜索 Yandex Lockbox 密钥。如果您未指定文件夹 ID,则请求将使用连接的
folder_id
(如果已指定)。- 参数:
yc_oauth_token (str | None) – 指定用于连接到 Yandex Lockbox 的用户账号 OAuth 令牌。参数值应类似于
y3_xx123
。yc_sa_key_json (dict | str | None) – 指定 JSON 格式的服务账号密钥。参数值应类似于
{"id": "...", "service_account_id": "...", "private_key": "..."}
。yc_sa_key_json_path (str | None) – 指定 JSON 格式服务账号密钥文件的路径。参数值应类似于
/home/airflow/authorized_key.json
,文件内容应采用以下格式:{"id": "...", "service_account_id": "...", "private_key": "..."}
。yc_connection_id (str | None) – 指定用于连接到 Yandex Lockbox 的连接 ID。默认值为
yandexcloud_default
。folder_id (str) – 指定用于在其中搜索 Yandex Lockbox 密钥的文件夹 ID。如果设置为
None
(在 JSON 中为null
),则请求将使用连接的folder_id
(如果已指定)。connections_prefix (str | None) – 指定读取密钥以获取连接的前缀。如果设置为
None
(在 JSON 中为null
),则不会向 Yandex Lockbox 发送连接请求。默认值为airflow/connections
。variables_prefix (str | None) – 指定读取密钥以获取变量的前缀。如果设置为
None
(在 JSON 中为null
),则不会向 Yandex Lockbox 发送变量请求。默认值为airflow/variables
。config_prefix (str | None) – 指定读取密钥以获取配置的前缀。如果设置为
None
(在 JSON 中为null
),则不会向 Yandex Lockbox 发送变量请求。默认值为airflow/config
。sep (str) – 指定用于连接
secret_prefix
和secret_id
的分隔符。默认值为/
。endpoint (str | None) – 指定 API 端点。如果设置为
None
(在 JSON 中为null
),则请求将使用连接的端点(如果已指定);否则,将使用默认端点。