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

cmd/incusd: support for JWT authentication #613

Closed
wants to merge 2 commits into from

Conversation

mikerobski
Copy link
Contributor

Added support for JWT authentication of REST API requests.
To use the JWT authentication the client should send Authorization header with Bearer token.
The Bearer token contains the JWT signed with the client certificate.

The JWT token must have the following content:
{
"sub":"axxxxxxxx",
"exp":1710288000,
"nbf":1710201600,
"iat":1710201600
}

The sub parameter contains the client certificate fingerprint, calculated as the SHA256 checksum of the raw certificate.

The authentication of the API request checks for the presence of the Authorization header and if it is present and contains valid JWT token, uses the subject to find the trusted client certificate and verifies the JWT signature.

Copy link
Member

@stgraber stgraber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a couple small changes needed.

We'll also want to add a new API extension for this, let's call it auth_tls_jwt. For that you want an extra commit title api: auth_tls_jwt which adds the extension to both doc/api-extensions.md and internal/version/api.go.

And we should also ideally add a test for this. Probably introduce a small test tool in tests/ which you can feed a client.crt+client.key, a not-before and not-after timestamp and have it return you the JWT.

We can then use that in the testsuite to validate that:

  • An invalid token is rejected
  • A valid token is properly reported as the user that signed it
  • A token that's not valid yet is not accepted
  • A token that's no longer valid is not accepted

internal/server/util/http.go Show resolved Hide resolved
internal/server/util/http.go Show resolved Hide resolved
@stgraber
Copy link
Member

So per above, we'll likely end up with a PR containing:

  • api: auth_tls_jwt
  • incusd: Add support for JWT authentication
  • tests: Introduce tls2jwt tool
  • tests: Test JWT authentication

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

Successfully merging this pull request may close these issues.

2 participants