consul.api.acl.token module

consul.api.acl.token.parse_identities(node_identities)[source]
Parameters:

node_identities (list[str] | None)

Return type:

dict[str, list[dict[str, str]]]

Bases: TypedDict

ID: str
Name: str
class consul.api.acl.token.AclToken[source]

Bases: TypedDict

AccessorID: str
SecretID: str
Description: str
Policies: builtins.list[AclPolicyLink]
Roles: builtins.list[AclPolicyLink]
ServiceIdentities: builtins.list[dict[str, Any]]
NodeIdentities: builtins.list[dict[str, Any]]
TemplatedPolicies: builtins.list[dict[str, Any]]
Local: bool
AuthMethod: str
CreateTime: str
Hash: str
CreateIndex: int
ModifyIndex: int
class consul.api.acl.token.Token(agent)[source]

Bases: object

list(policy=None, role=None, authmethod=None, servicename=None, token=None)[source]

Lists all the active ACL tokens. This is a privileged endpoint, and requires a management token. token will override this client’s default token. Requires a token with acl:read capability. ACLPermissionDenied raised otherwise :param policy: Optional policy ID to filter the results by. :param role: Optional role ID to filter the results by. :param authmethod: Optional auth method name to filter the results by. :param servicename: Optional service name to filter the results by

(matches tokens with a ServiceIdentity for this service).

Parameters:
  • policy (str | None)

  • role (str | None)

  • authmethod (str | None)

  • servicename (str | None)

  • token (str | None)

Return type:

builtins.list[AclToken]

read(accessor_id, token=None)[source]

Returns the token information for accessor_id. Requires a token with acl:read capability. :param accessor_id: The accessor ID of the token to read :param token: token with acl:read capability :return: selected token information

Parameters:
  • accessor_id (str)

  • token (str | None)

Return type:

AclToken

read_self(token=None)[source]

Returns the token information for the token used to authenticate the request (via token, or the client’s default token). Requires no specific privileges beyond possessing the token’s own secret. :param token: the token to introspect; defaults to the client’s configured token :return: the token information

Parameters:

token (str | None)

Return type:

AclToken

delete(accessor_id, token=None)[source]

Deletes the token with accessor_id. This is a privileged endpoint, and requires a token with acl:write. :param accessor_id: The accessor ID of the token to delete :param token: token with acl:write capability :return: True if the token was deleted

Parameters:
  • accessor_id (str)

  • token (str | None)

Return type:

bool

clone(accessor_id, token=None, description='')[source]

Clones the token identified by accessor_id. This is a privileged endpoint, and requires a token with acl:write. :param accessor_id: The accessor ID of the token to clone :param token: token with acl:write capability :param description: Optional new token description :return: The cloned token information

Parameters:
  • accessor_id (str)

  • token (str | None)

  • description (str)

Return type:

AclToken

create(token=None, accessor_id=None, secret_id=None, node_identities=None, service_identities=None, policies_id=None, description='', policies_name=None, roles_id=None, roles_name=None, templated_policies=None, expiration_time=None, expiration_ttl=None, local=None)[source]

Create a token (optionally identified by secret_id and accessor_id). This is a privileged endpoint, and requires a token with acl:write. :param token: token with acl:write capability :param accessor_id: The accessor ID of the token to create :param secret_id: The secret ID of the token to create :param node_identities: Optional list of node identities (format: ‘nodename:datacenter’), requires consul>=1.8.1 :param service_identities: Optional list of service identities, e.g.

[{“ServiceName”: “web”, “Datacenters”: [“dc1”]}] (“Datacenters” is optional)

Parameters:
  • description (str) – Optional new token description

  • policies_id (builtins.list[str] | None) – Optional list of policies id

  • roles_id (builtins.list[str] | None) – Optional list of roles id

  • roles_name (builtins.list[str] | None) – Optional list of roles name

  • templated_policies (builtins.list[builtins.dict[str, builtins.dict[str, str]]] | None) – Optional list of templated policies,

  • expiration_time (str | None) – Optional absolute expiration timestamp (RFC3339), 1 minute to 24 hours in the future. Mutually exclusive with expiration_ttl.

  • expiration_ttl (str | None) – Optional expiration duration (e.g. “1h”) relative to the token’s creation time, 1 minute to 24 hours. Mutually exclusive with expiration_time.

  • local (bool | None) – Optional, if True the token is local to this datacenter and not replicated globally.

  • token (str | None)

  • accessor_id (str | None)

  • secret_id (str | None)

  • node_identities (builtins.list[str] | None)

  • service_identities (builtins.list[builtins.dict[str, Any]] | None)

  • policies_name (builtins.list[str] | None)

Returns:

The cloned token information

Return type:

AclToken

update(accessor_id, token=None, secret_id=None, node_identities=None, service_identities=None, description='', policies_id=None, policies_name=None, roles_id=None, roles_name=None, templated_policies=None, expiration_time=None, expiration_ttl=None, local=None)[source]

Update a token (optionally identified by secret_id and accessor_id). This is a privileged endpoint, and requires a token with acl:write. :param accessor_id: The accessor ID of the token to update :param token: token with acl:write capability :param secret_id: Optional secret ID of the token to update :param node_identities: Optional list of node identities (format: ‘nodename:datacenter’), requires consul>=1.8.1 :param service_identities: Optional list of service identities, e.g.

[{“ServiceName”: “web”, “Datacenters”: [“dc1”]}] (“Datacenters” is optional)

Parameters:
  • description (str) – Optional new token description

  • policies_id (builtins.list[str] | None) – Optional list of policies id

  • roles_id (builtins.list[str] | None) – Optional list of roles id

  • roles_name (builtins.list[str] | None) – Optional list of roles name

  • templated_policies (builtins.list[builtins.dict[str, builtins.dict[str, str]]] | None) – Optional list of templated policies

  • expiration_time (str | None) – Optional absolute expiration timestamp (RFC3339). Note Consul does not allow extending a token’s expiration once set.

  • expiration_ttl (str | None) – Optional expiration duration (e.g. “1h”) relative to the token’s creation time. Mutually exclusive with expiration_time.

  • local (bool | None) – Optional, if True the token is local to this datacenter.

  • accessor_id (str)

  • token (str | None)

  • secret_id (str | None)

  • node_identities (builtins.list[str] | None)

  • service_identities (builtins.list[builtins.dict[str, Any]] | None)

  • policies_name (builtins.list[str] | None)

Returns:

The updated token information

Return type:

AclToken