Skip to main content

A set of custom plugins for Google Authentication Library

Project description

Google Auth Plugins Python Library

CI PyPI version

This library (built on top of Google's official SDK) aims to provide features not implemented by the standard library for whatever reason.

Common reason is that the latter is not a priority in the SDK's roadmap.

⚠️ This project doesn't want or plan to replace the official SDK but rather to be a space for experimentation providing beta features (because security does have to wait).

I hope that the features available in this repo will be integrated in the official library for the common good.

Index

Main difference with google-auth

For security reasons, this project will always drop support for a python version as soon as security support ends.

As an example, the version 2.16.1 of google-auth launched on 2023-02-17 still supports python3.6^1.

Installation

google-auth-plugins requires Python 3.7 or newer, and can be installed directly via pip:

python3 -m venv venv && source venv/bin/activate
python -m pip install google-auth-plugins

Usage

Domain-wide delegation credentials

A bit of context

As stated in this issue currently it's not possible to produce a delegated credentials via an impersonated identity.

To put it another way, today the only way to obtain those credentials is with a service account key 🤯.

Given the importance of this kind of service accounts it seems relevant to limit as much as possible long-term credentials in order to protect against leaks.

Domain-wide delegation credentials allows that.

Please find below an example:

import google.auth
from google_auth_plugins import dwd_credentials

target_scopes = ['https://www.googleapis.com/auth/calendar.readonly']
subject = "john.doe@pamplemousse.com"

# The impersonated service account must grant `Service Account Token Creator` to the identity represented by source_credentials
source_credentials, _ = google.auth.default()

delegated_credentials = dwd_credentials.Credentials(
  subject=subject,
  source_credentials=source_credentials,
  target_principal='dwd-impersonated-account@_project_.iam.gserviceaccount.com',
  target_scopes = target_scopes,
)

Alternatively, if source_credentials is the service account with domain-wide delegation, you can skip target_principal definition.

source_credentials, _ = google.auth.default()

delegated_credentials = dwd_credentials.Credentials(
  subject=subject,
  source_credentials=source_credentials,
  target_scopes = target_scopes,
)

Finally, you can switch delegated credentials as defined below:

alice_delegated_creds = dwd_credentials.Credentials(
  subject="alice@example.com",
  source_credentials=source_credentials,
  target_scopes = target_scopes,
)

bob_delegated_creds = alice_delegated_creds.with_subject("bob@example.com")

Note: this module is heavily inspired by Johannes Passing blog post 🚀.

Tests

make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google-auth-plugins-1.0.1rc0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_auth_plugins-1.0.1rc0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file google-auth-plugins-1.0.1rc0.tar.gz.

File metadata

  • Download URL: google-auth-plugins-1.0.1rc0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for google-auth-plugins-1.0.1rc0.tar.gz
Algorithm Hash digest
SHA256 b92f42abbf3126191da6a9b4af800b95709a5239ae1ac5b3d737aa06ae29f3f9
MD5 44e8c69fbd006981d16d8e9e5adcc8af
BLAKE2b-256 e6948ca048e3bbbe25905f702c0226414b3b025b40b4abe8764542a306334b3c

See more details on using hashes here.

File details

Details for the file google_auth_plugins-1.0.1rc0-py3-none-any.whl.

File metadata

File hashes

Hashes for google_auth_plugins-1.0.1rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 d937e6501322ea95e24a0864066d92191532afe6fe40d3d95553a800e9cd932b
MD5 18f03b07d0f35c7c229de3ec48c83116
BLAKE2b-256 df52464b46a1c67ca135077b2770c8f9f4751ac447ab6a8a9fb45851daf6ab53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page