Pyjo.GCP.X509 - Certificates of X.509 of the workloads

from Pyjo.GCP.X509 import Certificate

certificate = Certificate.from_pem(pem)
print(certificate.fingerprint(), certificate.uris(), certificate.is_agent_identity())

# Or import the module, as in Google Python Style Guide

import Pyjo.GCP.X509

fingerprint = Pyjo.GCP.X509.agent_fingerprint()

# Or the steps that wait for the certificate, as a provider of credentials
fingerprint = await Pyjo.GCP.X509.agent_fingerprint_steps()

Pyjo.GCP.X509 is a certificate of X.509 of a workload, of the configuration of the certificate of Pyjo.GCP.Config, as much of it as the tokens of Google Cloud that are bound to it need: its DER, the fingerprint of SHA-256 of its DER, and the URIs of its subjectAltName, of which the SPIFFE ID of an agent identity of Google Cloud tells its certificate, as _agent_identity_utils.py of google-auth has them, without the package cryptography.

A token of the metadata server and of an external account of a certificate is bound to the certificate of an agent identity, with its fingerprint, unless GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES is false, so that the token is of the calls of mTLS with that certificate only. The steps of agent_fingerprint_steps() wait for a certificate that is not there yet, as of an agent that starts before its certificate is written, for 30 seconds, as google-auth does.

See also

Pyjo.GCP.Config, Pyjo.GCP.Credentials.Metadata, Pyjo.GCP.Credentials.IdentityPool, RFC 5280.

Classes

Pyjo.GCP.X509.AGENT_TRUST_DOMAINS = (re.compile('^agents\\.global\\.org-\\d+\\.system\\.id\\.goog$'), re.compile('^agents\\.global\\.proj-\\d+\\.system\\.id\\.goog$'))

The trust domains of SPIFFE of the agent identities of Google Cloud.

Pyjo.GCP.X509.POLLING_INTERVALS: Sequence[float] = (0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)

The seconds of agent_fingerprint_steps() between the attempts to find the certificate of an agent identity, 30 in all, as _POLLING_INTERVALS of google-auth has them.

class Pyjo.GCP.X509.Pyjo_GCP_X509_Certificate(der: bytes)[source]

Certificate inherits all attributes and methods from Pyjo.Base and implements the following new ones.

__init__(der: bytes) → None[source]
certificate = Pyjo.GCP.X509.Certificate.new(der)

Construct a new certificate of its DER.

__weakref__

list of weak references to the object

der
der = certificate.der

The DER of the certificate.

fingerprint() → str[source]
fingerprint = certificate.fingerprint()

The fingerprint of SHA-256 of the DER, in Base64 without its padding, percent-encoded but its slashes, as google-auth sends it.

classmethod from_pem(pem: str | bytes) → Self[source]
certificate = Certificate.from_pem(pem)

The first certificate of PEM, or a Pyjo.Exception without one.

is_agent_identity() → bool[source]
boolean = certificate.is_agent_identity()

Whether a URI of the certificate is the SPIFFE ID of an agent identity, of a trust domain of AGENT_TRUST_DOMAINS.

uris() → list[str][source]
uris = certificate.uris()

The URIs of the subjectAltName of the certificate, or a Pyjo.Exception of an invalid DER.

Pyjo.GCP.X509.agent_fingerprint(config: Pyjo_GCP_Config | None = None) → str | None[source]
fingerprint = Pyjo.GCP.X509.agent_fingerprint()

The fingerprint of the certificate of the agent identity of the workload, of the configuration of GOOGLE_API_CERTIFICATE_CONFIG, or of the well-known one of Cloud Run, or None without them, of a certificate that is not of an agent identity, or of GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES=false, as get_and_parse_agent_identity_certificate of google-auth has it, or a Pyjo.Exception of a configuration whose certificate is not there yet, at once, which agent_fingerprint_steps() waits for.

Pyjo.GCP.X509.agent_fingerprint_steps(config: Pyjo_GCP_Config | None = None, intervals: Sequence[float] | None = None) → Pyjo_Steps[str | None][source]
fingerprint = await Pyjo.GCP.X509.agent_fingerprint_steps()
fingerprint = Pyjo.GCP.X509.agent_fingerprint_steps().run(ua)

Same as agent_fingerprint(), but the Pyjo.Steps that wait for a certificate that is not there yet, with a sleep of each of the intervals, POLLING_INTERVALS by default, as get_agent_identity_certificate_path of google-auth does, and raise the Pyjo.Exception after them.

Pyjo.GCP.X509.from_pem(pem: str | bytes) → Pyjo_GCP_X509_Certificate[source]
certificate = Pyjo.GCP.X509.from_pem(pem)

Alias for Pyjo_GCP_X509_Certificate.from_pem().

Pyjo.GCP.X509.should_bind() → bool[source]
boolean = Pyjo.GCP.X509.should_bind()

Whether a token is bound to the certificate of an agent identity, unless GOOGLE_API_PREVENT_AGENT_TOKEN_SHARING_FOR_GCP_SERVICES is false.