Skip to main content

Magic API Proxy

This is a stateless API proxy that allows creation and use of access-limited API tokens.

Basically, it's identity and access management for API tokens.

Why is this useful?

GitHub's API tokens (or other APIs, like DigitalOcean's) do not allow fine-grained control over which actions a token can perform (see this Dear GitHub issue). For example, you basically have to create a token that has full control over a repository to allow a token to just apply labels to issues.

This can be problematic. When you have many jobs, processes, and/or bots interacting with the GitHub API you increase the likelihood that a token could be compromised and tokens with broad permissions have very high consequences.

This proxy allows you to create API tokens with fine-grained permissions (a magic token) and then talk to an API using those magic tokens through a proxy. The proxy validates the magic token is allows to perform the requested action and then forwards the request to the API using the real API token.

What does stateless mean?

This proxy requires no backing storage and stores all of its state in the magic token itself. Although the plugin system permits to add a stateful layer if you so wish. e.g. allowing a token to create a record on a DNS provider, and delete it afterwards, but not delete any other record. TODO: document plugin system

What? How?

The proxy uses asymmetric cryptography (a public and private key pair) and JWTs to encode its state into the magic token.

Each magic token is a simple JWT signed by the proxy's private key with these claims:

{
  "iat": 1541616032,
  "exp": 1699296032,
  "token": "[long encrypted key]",
  "allowed": [
    "GET /user",
    "GET /repos/theacodes/nox/issues"
  ]
}

The token claim is an encrypted version of the raw API token. It's encrypted using the proxy's public key, so that only the proxy itself can decrypt it (using its private key).

The allowed claim determines what the magic token has access to. This proxy has a basic, rudimentary scope implementation described below

The JWT is generated and signed by the proxy itself using its private key. This means the contents can not be tampered with without invalidating the JWT.

Scoping

By default, this proxy has a simple scope strategy using the format:

METHOD /url/pattern

Where METHOD can be GET, POST, PUT, etc. and /url/pattern can be any regular expression that's used to check the URL.

For instance, to create a token that has access to any repository's issues in someorg, you could do:

GET /repos/someorg/.+?/issues

Usage

TODO

Disclaimer

This is was adaptaed from an unofficial inside-Google project, experimental. This is not a magic bullet for security. You assume all risks when using this project.

Metadata

Release files for magic-api-proxy 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magic-api-proxy 0.1.14
File Size Uploaded
magic-api-proxy-0.1.14.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for magic-api-proxy 0.1.14
File Interpreter ABI Platform
magic_api_proxy-0.1.14-py3-none-any.whl Python 3 none any Details

Total release size: 39.6 kB

Release files / magic-api-proxy-0.1.14.tar.gz

Download URL magic-api-proxy-0.1.14.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a152f14d62e631d440fa94412eb5b931b8172d72d0bdd6ebf501c5cc81a0210a
BLAKE2b-256 checksum
How to use checksums
de99a9ceca12836b8ca24667a2132c85beca704191dcfaf4de5103c35f94188f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release files / magic_api_proxy-0.1.14-py3-none-any.whl

Download URL magic_api_proxy-0.1.14-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df626f0756e62fc89e592c86d468e2a4bff9efe93cfac2a624252b6165a8a6de
BLAKE2b-256 checksum
How to use checksums
61570146b6102468475fbf727eb574d0beefd15458664c18c6e7dbf465b77fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.14 This release

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page