File: //usr/local/CyberCP/lib/python3.10/site-packages/google/auth/__pycache__/downscoped.cpython-310.pyc
o
�h!U � @ s� d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ dZdZ d Z
d
Zd ZG dd� de
�ZG d
d� de
�ZG dd� de
�ZG dd� dej�ZdS )a) Downscoping with Credential Access Boundaries
This module provides the ability to downscope credentials using
`Downscoping with Credential Access Boundaries`_. This is useful to restrict the
Identity and Access Management (IAM) permissions that a short-lived credential
can use.
To downscope permissions of a source credential, a Credential Access Boundary
that specifies which resources the new credential can access, as well as
an upper bound on the permissions that are available on each resource, has to
be defined. A downscoped credential can then be instantiated using the source
credential and the Credential Access Boundary.
The common pattern of usage is to have a token broker with elevated access
generate these downscoped credentials from higher access source credentials and
pass the downscoped short-lived access tokens to a token consumer via some
secure authenticated channel for limited access to Google Cloud Storage
resources.
For example, a token broker can be set up on a server in a private network.
Various workloads (token consumers) in the same network will send authenticated
requests to that broker for downscoped tokens to access or modify specific google
cloud storage buckets.
The broker will instantiate downscoped credentials instances that can be used to
generate short lived downscoped access tokens that can be passed to the token
consumer. These downscoped access tokens can be injected by the consumer into
google.oauth2.Credentials and used to initialize a storage client instance to
access Google Cloud Storage resources with restricted access.
Note: Only Cloud Storage supports Credential Access Boundaries. Other Google
Cloud services do not support this feature.
.. _Downscoping with Credential Access Boundaries: https://cloud.google.com/iam/docs/downscoping-short-lived-credentials
� N)�_helpers)�credentials)�
exceptions)�sts�
z/urn:ietf:params:oauth:grant-type:token-exchangez-urn:ietf:params:oauth:token-type:access_tokenzhttps://sts.{}/v1/tokenc @ sF e Zd ZdZg fdd�Zedd� �Zejdd� �Zdd� Zd d
� Z dS )�CredentialAccessBoundarya0 Defines a Credential Access Boundary which contains a list of access boundary
rules. Each rule contains information on the resource that the rule applies to,
the upper bound of the permissions that are available on that resource and an
optional condition to further restrict permissions.
c C s
|| _ dS )a� Instantiates a Credential Access Boundary. A Credential Access Boundary
can contain up to 10 access boundary rules.
Args:
rules (Sequence[google.auth.downscoped.AccessBoundaryRule]): The list of
access boundary rules limiting the access that a downscoped credential
will have.
Raises:
InvalidType: If any of the rules are not a valid type.
InvalidValue: If the provided rules exceed the maximum allowed.
N)�rules)�selfr � r
�I/usr/local/CyberCP/lib/python3.10/site-packages/google/auth/downscoped.py�__init__O s
z!CredentialAccessBoundary.__init__c C �
t | j�S )ai Returns the list of access boundary rules defined on the Credential
Access Boundary.
Returns:
Tuple[google.auth.downscoped.AccessBoundaryRule, ...]: The list of access
boundary rules defined on the Credential Access Boundary. These are returned
as an immutable tuple to prevent modification.
)�tuple�_rules�r r
r
r r ] s
zCredentialAccessBoundary.rulesc C sH t |�tkrt�d�t���|D ]}t|t�st�d��qt|�| _ dS )a� Updates the current rules on the Credential Access Boundary. This will overwrite
the existing set of rules.
Args:
value (Sequence[google.auth.downscoped.AccessBoundaryRule]): The list of
access boundary rules limiting the access that a downscoped credential
will have.
Raises:
InvalidType: If any of the rules are not a valid type.
InvalidValue: If the provided rules exceed the maximum allowed.
�@Credential access boundary rules can have a maximum of {} rules.zZList of rules provided do not contain a valid 'google.auth.downscoped.AccessBoundaryRule'.N)
�len� _MAX_ACCESS_BOUNDARY_RULES_COUNTr �InvalidValue�format�
isinstance�AccessBoundaryRule�InvalidType�listr )r �value�access_boundary_ruler
r
r r i s
��
��c C sB t | j�tkrt�d�t���t|t�st�d��| j �
|� dS )a� Adds a single access boundary rule to the existing rules.
Args:
rule (google.auth.downscoped.AccessBoundaryRule): The access boundary rule,
limiting the access that a downscoped credential will have, to be added to
the existing rules.
Raises:
InvalidType: If any of the rules are not a valid type.
InvalidValue: If the provided rules exceed the maximum allowed.
r zWThe provided rule does not contain a valid 'google.auth.downscoped.AccessBoundaryRule'.N)r r r r r r r r r r �append)r �ruler
r
r �add_rule� s ��
�z!CredentialAccessBoundary.add_rulec C s* g }| j D ] }|�|�� � qdd|iiS )a� Generates the dictionary representation of the Credential Access Boundary.
This uses the format expected by the Security Token Service API as documented in
`Defining a Credential Access Boundary`_.
.. _Defining a Credential Access Boundary:
https://cloud.google.com/iam/docs/downscoping-short-lived-credentials#define-boundary
Returns:
Mapping: Credential Access Boundary Rule represented in a dictionary object.
�accessBoundary�accessBoundaryRules)r r �to_json)r r r r
r
r r! � s
z CredentialAccessBoundary.to_jsonN)
�__name__�
__module__�__qualname__�__doc__r �propertyr �setterr r! r
r
r
r r H s
r c @ sr e Zd ZdZ ddd�Zedd� �Zejdd� �Zedd � �Zejd
d � �Zedd� �Z e jd
d� �Z dd� Z
dS )r z�Defines an access boundary rule which contains information on the resource that
the rule applies to, the upper bound of the permissions that are available on that
resource and an optional condition to further restrict permissions.
Nc C � || _ || _|| _dS )ay Instantiates a single access boundary rule.
Args:
available_resource (str): The full resource name of the Cloud Storage bucket
that the rule applies to. Use the format
"//storage.googleapis.com/projects/_/buckets/bucket-name".
available_permissions (Sequence[str]): A list defining the upper bound that
the downscoped token will have on the available permissions for the
resource. Each value is the identifier for an IAM predefined role or
custom role, with the prefix "inRole:". For example:
"inRole:roles/storage.objectViewer".
Only the permissions in these roles will be available.
availability_condition (Optional[google.auth.downscoped.AvailabilityCondition]):
Optional condition that restricts the availability of permissions to
specific Cloud Storage objects.
Raises:
InvalidType: If any of the parameters are not of the expected types.
InvalidValue: If any of the parameters are not of the expected values.
N)�available_resource�available_permissions�availability_condition)r r) r* r+ r
r
r r � s
zAccessBoundaryRule.__init__c C � | j S )zrReturns the current available resource.
Returns:
str: The current available resource.
)�_available_resourcer r
r
r r) � � z%AccessBoundaryRule.available_resourcec C � t |t�s
t�d��|| _dS )z�Updates the current available resource.
Args:
value (str): The updated value of the available resource.
Raises:
google.auth.exceptions.InvalidType: If the value is not a string.
z0The provided available_resource is not a string.N)r �strr r r- �r r r
r
r r) � s
�
c C r
)z�Returns the current available permissions.
Returns:
Tuple[str, ...]: The current available permissions. These are returned
as an immutable tuple to prevent modification.
)r �_available_permissionsr r
r
r r* � s
z(AccessBoundaryRule.available_permissionsc C sD |D ]}t |t�st�d��|�d�dkrt�d��qt|�| _dS )a Updates the current available permissions.
Args:
value (Sequence[str]): The updated value of the available permissions.
Raises:
InvalidType: If the value is not a list of strings.
InvalidValue: If the value is not valid.
z9Provided available_permissions are not a list of strings.zinRole:r z6available_permissions must be prefixed with 'inRole:'.N)r r0 r r �findr r r2 )r r �available_permissionr
r
r r* � s
���c C r, )z�Returns the current availability condition.
Returns:
Optional[google.auth.downscoped.AvailabilityCondition]: The current
availability condition.
)�_availability_conditionr r
r
r r+ s z)AccessBoundaryRule.availability_conditionc C �&