Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to restrict API tokens by IP address #17773

Open
di opened this issue Mar 13, 2025 · 2 comments
Open

Add ability to restrict API tokens by IP address #17773

di opened this issue Mar 13, 2025 · 2 comments
Labels
APIs/feeds tokens Issues relating to API tokens

Comments

@di
Copy link
Member

di commented Mar 13, 2025

The npm repository has the notion of an access/API token that can be optionally restricted by IP address ranges:

Image

We could add a similar option, include it as a caveat on the token, and compare it with remote_addr when authenticating.

@di di added APIs/feeds tokens Issues relating to API tokens labels Mar 13, 2025
@woodruffw
Copy link
Member

I think this would be awesome!

Spitballing a bit further (from a DM with @di): I think we could enable a variant of this by default for some Trusted Publisher providers: if a provider (like GitHub) provides IP ranges (either static or retrievable from an API endpoint) for their CI/CD service, then we could add a variant of the IP caveat that only permits token use from those IPs.

Broken down, using GitHub as an example:

  1. PyPI maintains a record of GitHub's known IP ranges for GitHub Actions, via https://api.github.com/meta
  2. When a token exchange for a GHA-based Trusted Publisher comes in, PyPI adds a new caveat (e.g. allowed_ips: GitHubOnly) to the minted token before returning it to the user
  3. The minted token behaves exactly the same as before, except that it's also exfiltration resistant (i.e., the attacker can't pull it from GHA and reuse it on another machine, such as their local machine).

In effect, this would more strongly bind the Trusted Publishing-issued credential to the lifecycle of the publisher that requested it -- the credential would be both short-lived, and couldn't be used outside of the service that we expect to use it.

On the other hand, the security benefit of this might be somewhat limited in the case of GitHub Actions: since any Actions IP would be valid, the attacker could just use the stolen credential from another GHA workflow on a repo they control.

@woodruffw
Copy link
Member

I looked a bit, and GitLab also has IP ranges, although not for their CI/CD platform: https://docs.gitlab.com/user/gitlab_com/#ip-range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIs/feeds tokens Issues relating to API tokens
Projects
None yet
Development

No branches or pull requests

2 participants