使用 AWS 身份验证管理器管理 Airflow 环境¶
当使用 AWS 身份验证管理器时,所有用户及其权限不再由 Airflow 默认的 Flask 身份验证管理器管理,而是通过基于 AWS 的授权集成,由两个不同的服务管理:AWS IAM Identity Center(用户)和 Amazon Verified Permissions(权限)。
通过 AWS IAM Identity Center 管理用户¶
用户¶
所有有权访问 Airflow 环境的用户都必须在 AWS IAM Identity Center 中定义。您可以将 AWS IAM Identity Center 用作身份源,或用作身份源(例如 Active Directory)与 Airflow 环境之间的代理。有关如何管理身份源的更多详细信息,请参阅文档。
您可以按照以下步骤查看在 AWS IAM Identity Center 中定义的用户列表。
选择 用户。
组¶
您可以在 AWS IAM Identity Center 中使用组将用户分组为逻辑实体(例如,按团队、按部门等)。之后,可以在 Amazon Verified Permissions 中使用这些组为用户组分配权限。有关将用户添加到组的更多详细信息,请参阅文档。
您可以按照以下步骤查看在 AWS IAM Identity Center 中定义的组列表。
选择 组。
将用户和组分配到 Airflow 环境¶
注意
在 AWS IAM Identity Center 中定义的所有用户和组不会自动获得 Airflow 环境的访问权限。您需要手动分配哪些用户可以访问 Airflow。
要将用户和组分配到 Airflow,请按照以下步骤操作。
注意
如果您在 AWS Managed Microsoft AD 中管理用户,请在执行下一步之前确保 IAM Identity Center 控制台正在使用您的 AWS Managed Microsoft AD 目录所在的 AWS 区域。
选择 应用程序。
选择 客户管理 选项卡。
在应用程序列表中,选择应用程序名称
Airflow
。在应用程序详细信息页面上,在 已分配用户和组 部分中,选择 分配用户和组。
在 分配用户或组 页面上,选择要分配给 Airflow 的不同用户和组。您也可以搜索用户和组。您可以通过在搜索结果中出现时选择适用的账户来指定多个用户或组。
选择 分配用户。
通过 Amazon Verified Permissions 管理用户权限¶
AWS 身份验证管理器使用 Amazon Verified Permissions 来定义和验证用户权限。它使用 Cedar 语言 为用户定义精细的权限。AWS 身份验证管理器使用一个策略存储来存储与 Airflow 环境相关的所有策略。要管理这些策略,请按照以下步骤操作。
选择 Airflow 使用的策略存储(默认情况下,其描述为
Airflow
)。在左侧导航窗格中,选择 策略。
在 策略 页面上,您可以看到策略列表。要创建新策略,请按照以下步骤操作。
选择 创建策略。
在 创建策略 下,选择 创建静态策略。
策略格式¶
在 Amazon Verified Permissions 中,策略使用 Cedar 语言 定义。有关完整文档,请参阅 cedar 语言网站。在 cedar 语言中,策略由三个元素组成:
主体。谁发起了请求?
操作。主体想要执行什么操作?
资源。主体想要对什么执行操作?
在 Airflow 环境的上下文中,这三个元素中的每一个都只允许特定的值集合。您可以按照以下步骤在策略存储模式中查看主体、操作和资源的列表。
选择 Airflow 使用的策略存储(默认情况下,其描述为
Airflow
)。在左侧导航窗格中,选择 模式。
策略示例¶
以下是您可以在 Amazon Verified Permissions 中定义的一些策略示例。您可以修改和/或组合它们来创建自定义策略。
授予特定用户所有权限¶
permit( principal == Airflow::User::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action, resource );
注意
您必须使用用户的用户 ID 来引用用户,而不是其用户名或任何其他属性。您可以在 AWS IAM Identity Center 中找到用户 ID。
授予用户组所有权限¶
这相当于 Flask AppBuilder 中的 Admin 角色。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action, resource );
注意
您必须使用组的组 ID 来引用组,而不是其名称。您可以在 AWS IAM Identity Center 中找到组 ID。
授予用户组只读权限¶
这相当于 Flask AppBuilder 中的 Viewer 角色。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action in [ Airflow::Action::"Configuration.GET", Airflow::Action::"Connection.GET", Airflow::Action::"Custom.GET", Airflow::Action::"Dag.GET", Airflow::Action::"Menu.MENU", Airflow::Action::"Pool.GET", Airflow::Action::"Variable.GET", Airflow::Action::"Asset.GET", Airflow::Action::"View.GET" ], resource );
授予用户组标准 Airflow 用户权限¶
这相当于 Flask AppBuilder 中的 User 角色。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action in [ Airflow::Action::"Configuration.GET", Airflow::Action::"Connection.GET", Airflow::Action::"Custom.GET", Airflow::Action::"Dag.GET", Airflow::Action::"Menu.MENU", Airflow::Action::"Pool.GET", Airflow::Action::"Variable.GET", Airflow::Action::"Asset.GET", Airflow::Action::"View.GET", Airflow::Action::"Dag.POST", Airflow::Action::"Dag.PUT", Airflow::Action::"Dag.DELETE", ], resource );
授予用户组操作权限¶
这相当于 Flask AppBuilder 中的 Op 角色。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action in [ Airflow::Action::"Configuration.GET", Airflow::Action::"Connection.GET", Airflow::Action::"Custom.GET", Airflow::Action::"Dag.GET", Airflow::Action::"Menu.MENU", Airflow::Action::"Pool.GET", Airflow::Action::"Variable.GET", Airflow::Action::"Asset.GET", Airflow::Action::"View.GET", Airflow::Action::"Dag.POST", Airflow::Action::"Dag.PUT", Airflow::Action::"Dag.DELETE", Airflow::Action::"Connection.POST", Airflow::Action::"Connection.PUT", Airflow::Action::"Connection.DELETE", Airflow::Action::"Pool.POST", Airflow::Action::"Pool.PUT", Airflow::Action::"Pool.DELETE", Airflow::Action::"Variable.POST", Airflow::Action::"Variable.PUT", Airflow::Action::"Variable.DELETE", Airflow::Action::"Asset.POST", Airflow::Action::"Asset.PUT", Airflow::Action::"Asset.DELETE", ], resource );
授予用户组特定 DAG 权限¶
以下策略授予用户组 DAG test
的所有与 DAG 相关的权限。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action, resource == Airflow::Dag::"test" );
以下策略授予用户组 DAG financial-1
和 financial-2
的所有与 DAG 相关的权限。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action, resource in [Airflow::Dag::"financial-1", Airflow::Dag::"financial-2"] );
以下策略授予用户组 DAG test
的日志访问权限。
permit( principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action, resource == Airflow::Dag::"test" ) when { context has dag_entity && context.dag_entity == "TASK_LOGS" };
禁止特定用户执行特定操作¶
在进行授权检查时,Amazon Verified Permissions 中定义的所有策略都会被考虑在内。例如,如果一个 permit 策略和一个 forbid 策略都匹配请求,则该用户将被拒绝访问。如果您想限制某个属于被授予所有权限的组的特定用户的访问权限,这会非常有用。
以下策略从特定用户移除对 DAG secret-dag-1
和 secret-dag-2
的访问权限。
forbid( principal == Airflow::User::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", action, resource in [Airflow::Dag::"secret-dag-1", Airflow::Dag::"secret-dag-2"] );