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

token-vendor rejects token if clock is slightly fast #351

Open
drigz opened this issue Mar 15, 2024 · 2 comments
Open

token-vendor rejects token if clock is slightly fast #351

drigz opened this issue Mar 15, 2024 · 2 comments

Comments

@drigz
Copy link
Contributor

drigz commented Mar 15, 2024

I don't have a good repro for this as I've only seen it on systems that were offline for a while. The token-vendor rejects the request with:

{
  "timestamp": "2024-03-15T10:50:25.236896019Z",
  "severity": "ERROR",
  "source": {
    "function": "github.com/googlecloudrobotics/core/src/go/cmd/token-vendor/api/v1.(*HandlerContext).tokenOAuth2Handler",
    "file": "src/go/cmd/token-vendor/api/v1/v1.go",
    "line": 245
  },
  "message": "unable to retrieve cloud access token with given JWT",
  "Error": "failed to verify signature for device \"robot-my-robot\": failed to parse and verify signature: Token used before issued"
}

I don't know how far the clocks were out-of-sync at this point, but it fixed itself within a few minutes. I guess it could be tested with a local cluster, disabling NTP and setting the time a few seconds into the future, then restarting gcr-credential-refresher to trigger a token exchange - but haven't tried this.

We are using github.com/form3tech-oss/jwt-go to verify without any special options:

_, err = jwt.Parse(jwtk, func(t *jwt.Token) (interface{}, error) {

This repo was archived on Aug 10, 2021 - @csieber do you know if there's a reason we didn't use https://github.com/golang-jwt/jwt from the start? The new library has an option for specifying leeway for clock sync when parsing/validating tokens: https://pkg.go.dev/github.com/golang-jwt/jwt/v5#WithLeeway https://github.com/golang-jwt/jwt/blob/80dccb9209ebe7b503c067dc830fcbd4aa2e74eb/validator.go#L37

@drigz
Copy link
Contributor Author

drigz commented Mar 15, 2024

FYI @Ongy

@csieber
Copy link
Contributor

csieber commented Mar 15, 2024

This repo was archived on Aug 10, 2021 - @csieber do you know if there's a reason we didn't use https://github.com/golang-jwt/jwt from the start?

That's a very good question. Sadly I cannot remember why this one. Maybe it was already used in some other code and I did not want to add another dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants