Retrieves a list of policies that the IAM identity (user, group, or role) can use to access each specified service.
This operation does not use other policy types when determining whether a resource could access a service. These other policy types include resource-based policies, access control lists, Organizations policies, IAM permissions boundaries, and STS assume role policies. It only applies permissions policy logic. For more about the evaluation of policy types, see Evaluating policies in the IAM User Guide.
The list of policies returned by the operation depends on the ARN of the identity that you provide.
-
User – The list of policies includes the managed and inline policies that are attached to the user directly. The list also includes any additional managed and inline policies that are attached to the group to which the user belongs.
-
Group – The list of policies includes only the managed and inline policies that are attached to the group directly. Policies that are attached to the group’s user are not included.
-
Role – The list of policies includes only the managed and inline policies that are attached to the role.
For each managed policy, this operation returns the ARN and policy name. For each inline policy, it returns the policy name and the entity to which it is attached. Inline policies do not have an ARN. For more information about these policy types, see Managed policies and inline policies in the IAM User Guide.
Policies that are attached to users and roles as permissions boundaries are not returned. To view which managed policy is currently used to set the permissions boundary for a user or role, use the GetUser or GetRole operations.
Parameters:
-
marker
(Optional[markerType], default:
None
)
–
Use this parameter only when paginating results and only after you receive a response indicating that the results are truncated. Set it to the value of the Marker element in the response that you received to indicate where the next call should start.
-
arn
(arnType)
–
The ARN of the IAM identity (user, group, or role) whose policies you want to list.
-
service_namespaces
(serviceNamespaceListType)
–
Raises:
-
InvalidInputException
–
The request was rejected because an invalid or out-of-range value was supplied for an input parameter.
-
NoSuchEntityException
–
The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
To list policies that allow access to a service
The following operation lists policies that allow ExampleUser01 to access IAM or EC2.
>>> client.list_policies_granting_service_access(arn='arn:aws:iam::123456789012:user/ExampleUser01', service_namespaces=['iam', 'ec2'])
Source code in docs_src/capo_iam/_services/iam.py
| def list_policies_granting_service_access(
self,
arn: "capo_iam.types.arn_type.arnType",
service_namespaces: "capo_iam.types.service_namespace_list_type.serviceNamespaceListType",
*,
config_overrides: Optional[IAMClientConfig] = None,
marker: Optional["capo_iam.types.marker_type.markerType"] = None,
) -> "capo_iam.types.list_policies_granting_service_access_response.ListPoliciesGrantingServiceAccessResponse":
"""<p>Retrieves a list of policies that the IAM identity (user, group, or role) can use to access each specified service.</p> <note> <p>This operation does not use other policy types when determining whether a resource could access a service. These other policy types include resource-based policies, access control lists, Organizations policies, IAM permissions boundaries, and STS assume role policies. It only applies permissions policy logic. For more about the evaluation of policy types, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html#policy-eval-basics">Evaluating policies</a> in the <i>IAM User Guide</i>.</p> </note> <p>The list of policies returned by the operation depends on the ARN of the identity that you provide.</p> <ul> <li> <p> <b>User</b> – The list of policies includes the managed and inline policies that are attached to the user directly. The list also includes any additional managed and inline policies that are attached to the group to which the user belongs. </p> </li> <li> <p> <b>Group</b> – The list of policies includes only the managed and inline policies that are attached to the group directly. Policies that are attached to the group’s user are not included.</p> </li> <li> <p> <b>Role</b> – The list of policies includes only the managed and inline policies that are attached to the role.</p> </li> </ul> <p>For each managed policy, this operation returns the ARN and policy name. For each inline policy, it returns the policy name and the entity to which it is attached. Inline policies do not have an ARN. For more information about these policy types, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html">Managed policies and inline policies</a> in the <i>IAM User Guide</i>.</p> <p>Policies that are attached to users and roles as permissions boundaries are not returned. To view which managed policy is currently used to set the permissions boundary for a user or role, use the <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetUser.html">GetUser</a> or <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetRole.html">GetRole</a> operations.</p>
Args:
marker: <p>Use this parameter only when paginating results and only after you receive a response indicating that the results are truncated. Set it to the value of the <code>Marker</code> element in the response that you received to indicate where the next call should start.</p>
arn: <p>The ARN of the IAM identity (user, group, or role) whose policies you want to list.</p>
service_namespaces: <p>The service namespace for the Amazon Web Services services whose policies you want to list.</p> <p>To learn the service namespace for a service, see <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html">Actions, resources, and condition keys for Amazon Web Services services</a> in the <i>IAM User Guide</i>. Choose the name of the service to view details for that service. In the first paragraph, find the service prefix. For example, <code>(service prefix: a4b)</code>. For more information about service namespaces, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-aws-service-namespaces">Amazon Web Services service namespaces</a> in the <i>Amazon Web Services General Reference</i>.</p>
Raises:
capo_iam.errors.invalid_input_exception.InvalidInputException: <p>The request was rejected because an invalid or out-of-range value was supplied for an input parameter.</p>
capo_iam.errors.no_such_entity_exception.NoSuchEntityException: <p>The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.</p>
capo_iam.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To list policies that allow access to a service
The following operation lists policies that allow ExampleUser01 to access IAM or EC2.
>>> client.list_policies_granting_service_access(arn='arn:aws:iam::123456789012:user/ExampleUser01', service_namespaces=['iam', 'ec2'])
"""
def _handler(
req: "OperationRequest[capo_iam.types.list_policies_granting_service_access_request.ListPoliciesGrantingServiceAccessRequest]",
) -> OperationResponse[
"capo_iam.types.list_policies_granting_service_access_response.ListPoliciesGrantingServiceAccessResponse"
]:
import capo_iam._operations.aws_identity_management_v20100508.list_policies_granting_service_access
output, http_response = (
capo_iam._operations.aws_identity_management_v20100508.list_policies_granting_service_access.list_policies_granting_service_access(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("ListPoliciesGrantingServiceAccess")
)
input_: capo_iam.types.list_policies_granting_service_access_request.ListPoliciesGrantingServiceAccessRequest = {
"arn": arn,
"service_namespaces": service_namespaces,
}
if marker is not None:
input_["marker"] = marker
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|