Skip to main content

A stateless API proxy

Project description

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.

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

magic-api-proxy-0.1.7.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

magic_api_proxy-0.1.7-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file magic-api-proxy-0.1.7.tar.gz.

File metadata

  • Download URL: magic-api-proxy-0.1.7.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for magic-api-proxy-0.1.7.tar.gz
Algorithm Hash digest
SHA256 9706795a7dfa3ed66d05fdd673691365fa27d4bb2258e37f82bd4e4d456a687f
MD5 fe4616f17506572653989bfa23fe82f3
BLAKE2b-256 bf241b8e7e27692eefdc6d8020a2fad43f1266f3c801061c9224e9c4acde836a

See more details on using hashes here.

File details

Details for the file magic_api_proxy-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for magic_api_proxy-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a8414a397abbe79e2106253f9b6022a3e5c49bb44e55f95d9fe929e699a41e30
MD5 06c5af9d2ef1b2026a9dc8c8c8f3ede0
BLAKE2b-256 3aca0a6d637f27608bd9283df7da7b3c3dd340f81dc03980b6d61eb07d7642ff

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