Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions providers/amazon/docs/auth-manager/manage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,24 @@ This is equivalent to the :doc:`Viewer role in Flask AppBuilder <apache-airflow-
principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
action in [
Airflow::Action::"Configuration.GET",
Airflow::Action::"Configuration.LIST",
Airflow::Action::"Connection.GET",
Airflow::Action::"Connection.LIST",
Airflow::Action::"Custom.GET",
Airflow::Action::"Custom.LIST",
Airflow::Action::"Dag.GET",
Airflow::Action::"Dag.LIST",
Airflow::Action::"Menu.MENU",
Airflow::Action::"Pool.GET",
Airflow::Action::"Pool.LIST",
Airflow::Action::"Variable.GET",
Airflow::Action::"Variable.LIST",
Airflow::Action::"Asset.GET",
Airflow::Action::"Asset.LIST",
Airflow::Action::"AssetAlias.GET",
Airflow::Action::"AssetAlias.LIST",
Airflow::Action::"Backfill.GET",
Airflow::Action::"Backfill.LIST",
Airflow::Action::"View.GET"
],
resource
Expand All @@ -183,17 +192,24 @@ This is equivalent to the :doc:`User role in Flask AppBuilder <apache-airflow-pr
principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
action in [
Airflow::Action::"Configuration.GET",
Airflow::Action::"Configuration.LIST",
Airflow::Action::"Connection.GET",
Airflow::Action::"Connection.LIST",
Airflow::Action::"Custom.GET",
Airflow::Action::"Custom.LIST",
Airflow::Action::"Dag.GET",
Airflow::Action::"Dag.LIST",
Airflow::Action::"Menu.MENU",
Airflow::Action::"Pool.GET",
Airflow::Action::"Pool.LIST",
Airflow::Action::"Variable.GET",
Airflow::Action::"Variable.LIST",
Airflow::Action::"Asset.GET",
Airflow::Action::"Asset.LIST",
Airflow::Action::"View.GET",
Airflow::Action::"Dag.POST",
Airflow::Action::"Dag.PUT",
Airflow::Action::"Dag.DELETE",
Airflow::Action::"Dag.DELETE"
],
resource
);
Expand All @@ -209,13 +225,20 @@ This is equivalent to the :doc:`Op role in Flask AppBuilder <apache-airflow-prov
principal in Airflow::Group::"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
action in [
Airflow::Action::"Configuration.GET",
Airflow::Action::"Configuration.LIST",
Airflow::Action::"Connection.GET",
Airflow::Action::"Connection.LIST",
Airflow::Action::"Custom.GET",
Airflow::Action::"Custom.LIST",
Airflow::Action::"Dag.GET",
Airflow::Action::"Dag.LIST",
Airflow::Action::"Menu.MENU",
Airflow::Action::"Pool.GET",
Airflow::Action::"Pool.LIST",
Airflow::Action::"Variable.GET",
Airflow::Action::"Variable.LIST",
Airflow::Action::"Asset.GET",
Airflow::Action::"Asset.LIST",
Airflow::Action::"View.GET",
Airflow::Action::"Dag.POST",
Airflow::Action::"Dag.PUT",
Expand All @@ -230,11 +253,9 @@ This is equivalent to the :doc:`Op role in Flask AppBuilder <apache-airflow-prov
Airflow::Action::"Variable.PUT",
Airflow::Action::"Variable.DELETE",
Airflow::Action::"Asset.POST",
Airflow::Action::"Asset.PUT",
Airflow::Action::"Asset.DELETE",
Airflow::Action::"Backfill.POST",
Airflow::Action::"Backfill.PUT",

Airflow::Action::"Backfill.PUT"
],
resource
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def get_entity_type(resource_type: AvpEntities) -> str:
return AVP_PREFIX_ENTITIES + resource_type.value


def get_action_id(resource_type: AvpEntities, method: ResourceMethod | str):
def get_action_id(resource_type: AvpEntities, method: ResourceMethod | str, entity_id: str | None):
"""
Return action id.

Convention for action ID is <resource_type>.<method>. Example: Variable.GET.

:param resource_type: Resource type.
:param method: Resource method.
:param entity_id: The entity ID.
"""
if method == "GET" and not entity_id:
method = "LIST"

return f"{resource_type.value}.{method}"
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def is_authorized(
"principal": {"entityType": get_entity_type(AvpEntities.USER), "entityId": user.get_id()},
"action": {
"actionType": get_entity_type(AvpEntities.ACTION),
"actionId": get_action_id(entity_type, method),
"actionId": get_action_id(entity_type, method, entity_id),
},
"resource": {"entityType": get_entity_type(entity_type), "entityId": entity_id or "*"},
"entities": {"entityList": entity_list},
Expand Down Expand Up @@ -281,7 +281,9 @@ def _build_is_authorized_request_payload(self, request: IsAuthorizedRequest, use
"principal": {"entityType": get_entity_type(AvpEntities.USER), "entityId": user.get_id()},
"action": {
"actionType": get_entity_type(AvpEntities.ACTION),
"actionId": get_action_id(request["entity_type"], request["method"]),
"actionId": get_action_id(
request["entity_type"], request["method"], request.get("entity_id")
),
},
"resource": {
"entityType": get_entity_type(request["entity_type"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,48 @@
"resourceTypes": ["Asset"]
}
},
"Asset.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Asset"]
}
},
"Asset.POST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Asset"]
}
},
"Asset.DELETE": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Asset"]
}
},
"AssetAlias.GET": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["AssetAlias"]
}
},
"AssetAlias.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["AssetAlias"]
}
},
"Backfill.GET": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Backfill"]
}
},
"Backfill.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Backfill"]
}
},
"Backfill.POST": {
"appliesTo": {
"principalTypes": ["User"],
Expand All @@ -43,6 +73,12 @@
"resourceTypes": ["Connection"]
}
},
"Connection.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Connection"]
}
},
"Connection.POST": {
"appliesTo": {
"principalTypes": ["User"],
Expand All @@ -67,6 +103,12 @@
"resourceTypes": ["Custom"]
}
},
"Custom.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Custom"]
}
},
"Custom.POST": {
"appliesTo": {
"principalTypes": ["User"],
Expand All @@ -85,6 +127,12 @@
"resourceTypes": ["Configuration"]
}
},
"Configuration.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Configuration"]
}
},
"Dag.DELETE": {
"appliesTo": {
"principalTypes": ["User"],
Expand Down Expand Up @@ -115,6 +163,21 @@
}
}
},
"Dag.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Dag"],
"context": {
"attributes": {
"dag_entity": {
"required": false,
"type": "String"
}
},
"type": "Record"
}
}
},
"Dag.POST": {
"appliesTo": {
"principalTypes": ["User"],
Expand Down Expand Up @@ -163,6 +226,12 @@
"resourceTypes": ["Pool"]
}
},
"Pool.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Pool"]
}
},
"Pool.POST": {
"appliesTo": {
"principalTypes": ["User"],
Expand All @@ -187,6 +256,12 @@
"resourceTypes": ["Variable"]
}
},
"Variable.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Variable"]
}
},
"Variable.POST": {
"appliesTo": {
"principalTypes": ["User"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@ def test_get_entity_type():
assert get_entity_type(AvpEntities.VARIABLE) == "Airflow::Variable"


def test_get_action_id():
assert get_action_id(AvpEntities.VARIABLE, "GET") == "Variable.GET"
def test_get_action_id_get():
assert get_action_id(AvpEntities.VARIABLE, "GET", "1") == "Variable.GET"


def test_get_action_id_post():
assert get_action_id(AvpEntities.VARIABLE, "POST", None) == "Variable.POST"


def test_get_action_id_list():
assert get_action_id(AvpEntities.VARIABLE, "GET", None) == "Variable.LIST"
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ def test_is_authorized_successful(
{
"policyStoreId": AVP_POLICY_STORE_ID,
"principal": {"entityType": "Airflow::User", "entityId": user.get_id()},
"action": {"actionType": "Airflow::Action", "actionId": get_action_id(entity_type, method)},
"action": {
"actionType": "Airflow::Action",
"actionId": get_action_id(entity_type, method, entity_id),
},
"resource": {"entityType": get_entity_type(entity_type), "entityId": entity_id or "*"},
"entities": {"entityList": expected_entities},
"context": expected_context,
Expand Down Expand Up @@ -246,7 +249,7 @@ def test_get_batch_is_authorized_single_result_successful(self, facade):
single_result = {
"request": {
"principal": {"entityType": "Airflow::User", "entityId": "test_user"},
"action": {"actionType": "Airflow::Action", "actionId": "Connection.GET"},
"action": {"actionType": "Airflow::Action", "actionId": "Connection.LIST"},
"resource": {"entityType": "Airflow::Connection", "entityId": "*"},
},
"decision": "ALLOW",
Expand All @@ -257,7 +260,7 @@ def test_get_batch_is_authorized_single_result_successful(self, facade):
{
"request": {
"principal": {"entityType": "Airflow::User", "entityId": "test_user"},
"action": {"actionType": "Airflow::Action", "actionId": "Variable.GET"},
"action": {"actionType": "Airflow::Action", "actionId": "Variable.LIST"},
"resource": {"entityType": "Airflow::Variable", "entityId": "*"},
},
"decision": "ALLOW",
Expand Down