You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a recent PR [1] a lot of internals for the AuthTokenMiddleware were refactored. This includes a change to prefer fetcher->updateMetadata() over fetcher->fetchAuthToken() to retrieve the required credentials when the credentials fetcher supports UpdateMetadataInterface [2].
This change seems to have broken the ability to cache OIDC identity tokens. See the reproduction case.
When using a FetchAuthTokenCache credentials fetcher (with GCECredentials as underlying fetcher), the old method used to always cache the result of the underlying fetcher [3]. The method that is now called to get the credentials from the underlying fetcher, has an additional check to ensure the token was not a null-value [4]. For OIDC identity tokens, this will always return NULL, due to never reaching the code to set the lastReceivedToken when dealing with OIDC identity tokens in the underlying credentials fetcher [5].
My proposal is to update the code of the GCECredentials to also store lastReceivedToken when dealing with an id_token type. If this change is acceptable, I am willing to open a PR for it.
Essentially adjust the following to also set the lastReceivedToken value:
@Daniel-I-Am Thank you for taking the time to hunt this down (it's a tricky one).
My proposal is to update the code of the GCECredentials to also store lastReceivedToken when dealing with an id_token type. If this change is acceptable, I am willing to open a PR for it.
This seems great, I agree this is the best course of action
And make the updateMetadata call compatible with the id_token credential type:
This also seems like the right approach.
If you'd like to submit the fix, please do so, as that would be a huge help to us! However, if you would rather us handle it (because of the complicated nature) that's understandable as well.
We will also want to add tests once we fix this, since it's such a tricky regression and we want to make sure it doesn't happen again. If you submit the fix, we can add the tests later. We'll defer to you since you found the bug, and we would of course love your contribution!
In a recent PR [1] a lot of internals for the
AuthTokenMiddleware
were refactored. This includes a change to preferfetcher->updateMetadata()
overfetcher->fetchAuthToken()
to retrieve the required credentials when the credentials fetcher supportsUpdateMetadataInterface
[2].This change seems to have broken the ability to cache OIDC identity tokens. See the reproduction case.
When using a
FetchAuthTokenCache
credentials fetcher (withGCECredentials
as underlying fetcher), the old method used to always cache the result of the underlying fetcher [3]. The method that is now called to get the credentials from the underlying fetcher, has an additional check to ensure the token was not a null-value [4]. For OIDC identity tokens, this will always return NULL, due to never reaching the code to set thelastReceivedToken
when dealing with OIDC identity tokens in the underlying credentials fetcher [5].References:
google-auth-library-php/src/Middleware/AuthTokenMiddleware.php
Lines 129 to 140 in 682dc6c
google-auth-library-php/src/FetchAuthTokenCache.php
Lines 88 to 90 in 682dc6c
google-auth-library-php/src/FetchAuthTokenCache.php
Lines 249 to 251 in 682dc6c
google-auth-library-php/src/Credentials/GCECredentials.php
Lines 400 to 411 in 682dc6c
Environment details
Steps to reproduce
AuthTokenMiddleware
with aFetchAuthTokenCache
.Code example
This is run on a GCE VM instance, where the metadata server is available
Install dependencies for convenience:
composer require guzzlehttp/guzzle symfony/cache google/auth:1.33.0
The output of this script is the contents of the cache. When running this code on a GCE instance, the outputs are as follows:
Version 1.33.0
Version 1.32.1
Downgrade this library:
composer require google/auth:1.32.1
My proposal is to update the code of the
GCECredentials
to also storelastReceivedToken
when dealing with anid_token
type. If this change is acceptable, I am willing to open a PR for it.Essentially adjust the following to also set the
lastReceivedToken
value:google-auth-library-php/src/Credentials/GCECredentials.php
Lines 400 to 402 in 682dc6c
And make the
updateMetadata
call compatible with theid_token
credential type:google-auth-library-php/src/FetchAuthTokenCache.php
Lines 233 to 240 in 682dc6c
The text was updated successfully, but these errors were encountered: