-
Notifications
You must be signed in to change notification settings - Fork 983
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
Token not working, always causing 403 #11217
Comments
This is likely due to #11122. @woodruffw can you look into this? |
Yeah, taking a look now. Just for clarification: the |
Hmm, I couldn't immediately reproduce this locally (on Here's what I did:
Am I missing any of your steps, @novitae? I'll try with some different 2FA configurations in a moment as well. |
I'm trying this with a public repository + package as well, with an API token associated with my 2FA-enabled PyPI account. Will report the results in a moment. |
Publishing with the official GitHub Action works for me: https://github.com/trailofbits/blight/runs/6096536844?check_suite_focus=true Here's the relevant GitHub Action step: - name: publish
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
(where |
I'm going to try cycling that API token as well. One moment. |
Okay, I think I was able to reproduce this:
Via: https://github.com/trailofbits/blight/runs/6096668206?check_suite_focus=true That was with a brand new token, rather than a pre-existing one, on a 2FA-enabled account. Trying to repro locally now. |
Tried to reproduce this under the same conditions locally, with no luck:
|
...okay. I tried creating the API token again, under the exact same conditions, and this time it succeeded: https://github.com/trailofbits/blight/runs/6096846818?check_suite_focus=true The only thing I changed is how I entered the token into GitHub's secrets interface: this time, I noticed that there was a trailing newline and removed it. My best guess is that the PyPI GitHub Action isn't trimming the secret's trailing whitespace and is therefore passing a token that's slightly off. But I'm amazed that we haven't seen this before. |
@novitae Could you check your secret, and see whether it has a trailing newline? If so, could you remove it and retry publishing? |
This is how we yank the Macaroon from the HTTP headers: def _extract_basic_macaroon(auth):
"""
A helper function for extracting a macaroon from a
HTTP Basic Authentication-style header.
Returns None if the header doesn't contain a structurally
valid macaroon, or the candidate (not yet verified) macaroon
in a serialized form.
"""
try:
authorization = base64.b64decode(auth).decode()
auth_method, _, auth = authorization.partition(":")
except ValueError:
return None
if auth_method != "__token__":
return None
return auth Note that we don't do any whitespace stripping, so this is looking like the culprit to me. So this is not a result of #11122, but just something that's been lurking and (somehow) hadn't been triggered yet. |
More root-causing: it looks like the GitHub Action for PyPI publishing also doesn't remove any trailing whitespace from the secret: |
Sorry for the late answer @woodruffw
Yep it's this one
Not really ... Here are the more detailed steps I did (sorry if I wasn't very clear):
Thanks for your help ! |
No problem, thanks for following up. Our current operating theory is that it's a whitespace problem -- could you try re-adding the API token, but making sure that there's no newline after? |
So I retried, there's no whitespace for me, I checked many times. Still 403. |
Okay, thanks for checking. I'll continue trying to repro. |
Can you confirm your token starts with |
yep |
@di @woodruffw so, do you have more for me ? otherwise I could try to create a new pypi account and move all my repos there ... |
Hi @novitae, can you send me the token you're trying to use via email to |
@di |
I agree, that is confusing. I made #11260 to resolve it. |
I'm having this issue. I tried removing whitespace from my token, creating a new token, and even setting up my github action as a trusted publisher. Still getting error 403. Incredibly frustrating. |
@JWock82 Can you open a new issue with more details, like the name of your project, any example GitHub Actions runs, etc? |
Describe the bug
PyPI API Token not working for me
Expected behavior
GitHub action
Upload Python Package
authentication fails with the token I generates for it (403).To Reproduce
Create a repo with some python things. Upload it to PyPI with twine from your terminal with username and password. It should work. Put this repo on github, change few things, update the version in setup.py. In actions, add the
Upload Python Package
action. Create an api token for it. Add it in the secrets under the name ofPYPI_API_TOKEN
. Create a new tag, it should start upload this tag to PyPI, but for me it fails.Long story short, follow what's written here with the
Upload Python Package
GitHub action.Also something weird, even if I deleted all my tokens, when I create new one, it tells me
API token name already in use
, but when I go back to my profile I see it registered ...Additional context
I asked here pypi/support#1623 a 2FA recovery, now it is done. But could this be the source of the problem ? Right now I don't have 2FA activated, and since I saw we need a verified email to generate token (mine is verified), I'm asking myself if no having 2FA can influence this, like not generating valid tokens. Just supposition, I might be completely off-topic.
The text was updated successfully, but these errors were encountered: