-
Notifications
You must be signed in to change notification settings - Fork 311
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
Getting "Invalid JWT Signature" after upgrading to rsa==4.7 #667
Comments
Hi, Thanks for the report! I've marked this as external for now since I see you also opened sybrenstuvel/python-rsa#173. Please let me know if something needs to be fixed in this library. |
Hi @busunkim96 , I've added a stacktrace for what I think is causing the error above to the ticket on python-rsa here: sybrenstuvel/python-rsa#173 (comment) EDIT: the original issue on python-rsa contains new info that shows that this library's call to initialise the key is working fine. No need to read the below.
|
jumping in.
we are using google service account to access google cloud storage on the python service. is this the same issue? |
Hi @lechen26, The root cause is still up in the air. See sybrenstuvel/python-rsa#173. Can you try explicitly pinning to |
I am experiencing the same problem.. i hotfixed pip installed rsa==4.6 and the problem went away. |
i'm trying to pin this rsa version. |
I'm the author of the RSA package. As you can see in sybrenstuvel/python-rsa#173, there is a problem where attributes on the key objects are missing:
Is Google Auth creating the keys in some non-standard way? The |
After looking at the RSA code and @sybrenstuvel 's patch, I would like to reinstate my original comment: Is there any chance that the Running the updated |
@jamescooke @sybrenstuvel Thank you both for the analyses. 🙏 I'm not very familiar with this bit of the codebase so I will have to take a closer look. I will provide an update tomorrow. |
For anyone who's seeing this, could you try installing google-auth-library-python/google/auth/crypt/rsa.py Lines 18 to 30 in d4d7f38
I'm wondering if the library does something incorrect with keys that only manifests in a multithreaded or multiprocess environment |
Hi @busunkim96 , after installing
Some context - It looks like the
Hope that's helpful. |
Thanks @jamescooke! It looks like that creates some other problems we'll have to look into separately. I haven't tracked down what the cause is, but here is how a service account credential gets initialized, starting from google-auth-library-python/google/oauth2/service_account.py Lines 221 to 236 in 65074d3
google-auth-library-python/google/auth/_service_account_info.py Lines 60 to 74 in 65074d3
google-auth-library-python/google/auth/_service_account_info.py Lines 25 to 57 in 65074d3
google-auth-library-python/google/auth/crypt/base.py Lines 94 to 115 in 65074d3
google-auth-library-python/google/auth/crypt/_python_rsa.py Lines 138 to 173 in 65074d3
As far as I can tell
google-auth-library-python/google/auth/crypt/_python_rsa.py Lines 167 to 168 in 65074d3
Continuing on to the RSA library:
Will update once I have a repro of sybrenstuvel/python-rsa#173 (comment) |
PSA:Anyone who was seeing "Invalid JWT Signature" with For the multiprocessing error, I've managed to recreate the This is a contrived example that repeatedly calls requirements.txt
from multiprocessing import Pool
from contextlib import closing
import google.auth
from google.auth.transport import requests
from googleapiclient import discovery
def refresh_credentials(client):
client._http.credentials.refresh(requests.Request())
def with_multiprocessing():
# Set GOOGLE_APPLICATION_CREDENTIALS to a service account file
creds, _ = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
client = discovery.build("storage", "v1", credentials=creds)
num_process = 5
with closing(Pool(num_process)) as p:
return p.map(refresh_credentials, [client])
def no_multiprocessing():
# Set GOOGLE_APPLICATION_CREDENTIALS to a service account file
creds, _ = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
client = discovery.build("storage", "v1", credentials=creds)
refresh_credentials(client)
if __name__ == "__main__":
no_multiprocessing()
with_multiprocessing()
|
def __setstate__(self, state: typing.Tuple[int, int, int, int, int, int, int, int]) -> None:
"""Sets the key from tuple."""
self.n, self.e, self.d, self.p, self.q, self.exp1, self.exp2, self.coef = state
AbstractKey.__init__(self, self.n, self.e) |
Opened sybrenstuvel/python-rsa#178 |
@busunkim96 Thanks for the PR above. |
Hooray! It looks like this is resolved now. Anyone who was pinning to an older version, please upgrade to |
Thanks for collaborating on this, people! 🥳 🎈 |
Environment details
google-auth
version: 1.22.1Steps to reproduce
We found this bug while using dvc and using Google Cloud Storage as a backend. Authentication with google is done via a service key file. When running dvc with
rsa==4.6
everything works fine, but when upgrading torsa==4.7
, we encounter the following error:The text was updated successfully, but these errors were encountered: