google-cloud-go: auth: Sporadic errors refreshing token with workload identity federation

Client

aiplatform.NewPredictionClient

Environment

Linux on AWS EKS go 1.2.4

Code and Dependencies

package main

func main() {
  	return aiplatform.NewPredictionClient(ctx,
		option.WithCredentialsFile(clientConfigPath),
}
go.mod
module modname

go 1.24.0

require (
        cloud.google.com/go/aiplatform v1.69.0
        cloud.google.com/go/vertexai v0.13.3
...
        cloud.google.com/go v0.116.0 // indirect
        cloud.google.com/go/auth v0.12.1 // indirect
...
        google.golang.org/api v0.211.0
        google.golang.org/grpc v1.70.0
)

Expected behavior

We are using the vertexai client library from AWS, authenticating using workload identity federation via the option.WithCredentialsFile. This works great 99% of the time.

Actual behavior

Sporadically, we get errors like:

Google Vertex Error, reason=: transport: per-RPC creds failed due to error: credentials: status code 400: {"error":"invalid_grant","error_description":"ID Token issued at 1749625771 is stale to sign-in."}

We’ll see one or more such errors all referring to the same timestamp, a little more than an hour after the indicated timestamp, but sometimes as much as 80 minutes after the timestamp.

We understand there is a refresh mechanism in place, so it shouldn’t be an issue to re-use a given client over a long interval, but it seems like there are some scenarios where this refresh mechanism doesn’t work.

Additional context

I found a few related issues: One, Two Searching for this error message turns up a lot of results about Firebase auth. Given that there are two auth libraries in play (cloud.google.com/go/auth and golang.org/x/oauth2 it’s pretty hard to trace the code and figure out what might be going on. It doesn’t seem related to workload identity federation in particular, more so the general token exchange/refresh mechanism in the client library.

On the GCP side, it’s also hard to find any log info about these errors (if the requests are even making it to GCP?) Unclear whether to look in the project that houses the Vertex API or the project that houses the workload identity pool.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

I’m adding logging of the projected token payload when we run into this error, so we’ll hopefully be able to isolate it to that part of the system.

I will open a support ticket and link to this issue. Thanks for the quick follow-up/feedback!