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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AvpEntities(Enum):
DAG = "Dag"
MENU = "Menu"
POOL = "Pool"
TEAM = "Team"
VARIABLE = "Variable"
VIEW = "View"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class IsAuthorizedRequest(TypedDict, total=False):
entity_type: AvpEntities
entity_id: str | None
context: dict | None
team_name: str | None


class AwsAuthManagerAmazonVerifiedPermissionsFacade(LoggingMixin):
Expand Down Expand Up @@ -87,6 +88,7 @@ def is_authorized(
user: AwsAuthManagerUser,
entity_id: str | None = None,
context: dict | None = None,
team_name: str | None = None,
) -> bool:
"""
Make an authorization decision against Amazon Verified Permissions.
Expand All @@ -102,7 +104,9 @@ def is_authorized(
:param entity_id: the entity ID the user accesses. If not provided, all entities of the type will be
considered.
:param context: optional additional context to pass to Amazon Verified Permissions.
:param team_name: optional team name for multi-team authorization.
"""
context = self._enrich_context_with_team(context, team_name)
entity_list = self._get_user_group_entities(user)

self.log.debug(
Expand Down Expand Up @@ -259,6 +263,21 @@ def _get_user_group_entities(user: AwsAuthManagerUser) -> list[dict]:
]
return [user_entity, *group_entities]

@staticmethod
def _enrich_context_with_team(context: dict | None, team_name: str | None) -> dict | None:
"""
Add team_name to context if provided.

:param context: existing context dict or None
:param team_name: team name to add to context
"""
if not team_name:
return context
team_context = {"team_name": {"string": team_name}}
if context is None:
return team_context
return {**context, **team_context}

@staticmethod
def _build_context(context: dict | None) -> dict | None:
if context is None or len(context) == 0:
Expand All @@ -275,6 +294,7 @@ def _build_is_authorized_request_payload(self, request: IsAuthorizedRequest, use
:param request: the request information
:param user: the user
"""
context = self._enrich_context_with_team(request.get("context"), request.get("team_name"))
return prune_dict(
{
"principal": {"entityType": get_entity_type(AvpEntities.USER), "entityId": user.get_id()},
Expand All @@ -288,6 +308,6 @@ def _build_is_authorized_request_payload(self, request: IsAuthorizedRequest, use
"entityType": get_entity_type(request["entity_type"]),
"entityId": request.get("entity_id", "*"),
},
"context": self._build_context(request.get("context")),
"context": self._build_context(context),
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,76 @@
"Connection.DELETE": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Connection"]
"resourceTypes": ["Connection"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Connection.GET": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Connection"]
"resourceTypes": ["Connection"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Connection.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Connection"]
"resourceTypes": ["Connection"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Connection.POST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Connection"]
"resourceTypes": ["Connection"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Connection.PUT": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Connection"]
"resourceTypes": ["Connection"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Custom.DELETE": {
Expand Down Expand Up @@ -142,6 +187,10 @@
"dag_entity": {
"type": "String",
"required": false
},
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
Expand All @@ -157,6 +206,10 @@
"dag_entity": {
"required": false,
"type": "String"
},
"team_name": {
"required": false,
"type": "String"
}
},
"type": "Record"
Expand All @@ -172,6 +225,10 @@
"dag_entity": {
"required": false,
"type": "String"
},
"team_name": {
"required": false,
"type": "String"
}
},
"type": "Record"
Expand All @@ -187,6 +244,10 @@
"dag_entity": {
"required": false,
"type": "String"
},
"team_name": {
"required": false,
"type": "String"
}
},
"type": "Record"
Expand All @@ -202,6 +263,10 @@
"dag_entity": {
"required": false,
"type": "String"
},
"team_name": {
"required": false,
"type": "String"
}
},
"type": "Record"
Expand All @@ -217,61 +282,163 @@
"Pool.DELETE": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Pool"]
"resourceTypes": ["Pool"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Pool.GET": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Pool"]
"resourceTypes": ["Pool"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Pool.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Pool"]
"resourceTypes": ["Pool"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Pool.POST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Pool"]
"resourceTypes": ["Pool"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Pool.PUT": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Pool"]
"resourceTypes": ["Pool"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Team.GET": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Team"]
}
},
"Team.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Team"]
}
},
"Variable.DELETE": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Variable"]
"resourceTypes": ["Variable"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Variable.GET": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Variable"]
"resourceTypes": ["Variable"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Variable.LIST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Variable"]
"resourceTypes": ["Variable"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Variable.POST": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Variable"]
"resourceTypes": ["Variable"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"Variable.PUT": {
"appliesTo": {
"principalTypes": ["User"],
"resourceTypes": ["Variable"]
"resourceTypes": ["Variable"],
"context": {
"attributes": {
"team_name": {
"type": "String",
"required": false
}
},
"type": "Record"
}
}
},
"View.GET": {
Expand All @@ -291,6 +458,7 @@
"Dag": {},
"Menu": {},
"Pool": {},
"Team": {},
"Group": {},
"User": {
"memberOfTypes": [
Expand Down
Loading
Loading