Skip to content

Personal access token #4540

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

Merged
merged 1 commit into from
Apr 28, 2025
Merged

Personal access token #4540

merged 1 commit into from
Apr 28, 2025

Conversation

bruntib
Copy link
Contributor

@bruntib bruntib commented Apr 17, 2025

[feat] Personal access token

A separate table is created for personal access tokens in the database.
This table contains a unique name per user that identifies the token.

The token is visible only once at generation. No access is allowed later.
For this reason the old token handler API functions (getTokens(),
newToken(), removeToken()) are deprecated.
Other API functions are introduced instead: getPersonalAccessTokens(),
newPersonalAccessToken() and removePersonalAccessToken(). The old clients
are using the old API functions, but an empty string returns instead of
the token.

Personal access tokens can be created in the web GUI, too.

@bruntib bruntib added enhancement 🌟 web 🌍 Related to the web app labels Apr 17, 2025
@bruntib bruntib added this to the release 6.26.0 milestone Apr 17, 2025
@bruntib bruntib requested review from dkrupp and vodorok as code owners April 17, 2025 13:07
@bruntib
Copy link
Contributor Author

bruntib commented Apr 17, 2025

I'm still planning to redesign the old API functions for token handling, because they return the token, and can't handle the unique name of a token.
I'll also write a proper commit message.

@bruntib bruntib force-pushed the access_tokens branch 2 times, most recently from dc90bc4 to 01a6b3e Compare April 22, 2025 08:59
@@ -38,7 +38,7 @@ def handle_add_token(args):
client = init_auth_client(protocol, host, port)

description = args.description if 'description' in args else None
session = client.newToken(description)
session = client.newPersonalAccessToken(args.name, description)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this variable be called token since function name suggests it returns a new personal access token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I fixed it!

Copy link
Contributor

@Discookie Discookie left a comment

Choose a reason for hiding this comment

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

Couple usability snags I found skimming over it:

  • The no-permission error when creating tokens is always The server must be start by using privilaged access to execute this action., even when the user is not logged in.
  • You can log in with a PAT from the web interface via the username/password login flow. This causes the browser to stay logged in until the PAT expires. This is existing behavior, but I'm not sure if it's a good idea.

self.description = description
self.auth_session_id = auth_session_id
self.last_access = datetime.now()
self.expiration = self.last_access + timedelta(days=365)
Copy link
Contributor

Choose a reason for hiding this comment

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

This default expiration should be configurable, and ideally, user-selectable (with a configurable upper limit).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be done later.

after closing this window.
</p>
</template>
</confirm-dialog>
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if instead of a Cancel button here, there was a Copy to clipboard button, or something similar.

@bruntib bruntib force-pushed the access_tokens branch 3 times, most recently from 0e97090 to 3ddfad2 Compare April 23, 2025 12:01
Copy link
Member

@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

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

When LDAP and Oauth authentication is allowed, the personal access token based login does not work from the CLI. The reason is likely that authentication is tried through LDAP first and then when it fails because the personal access token does not match the LDAP password. So personal access based authentication should always be tried first and successful, the user should be let in, otherwise the other password based authentication methods can be tried.

@bruntib bruntib force-pushed the access_tokens branch 2 times, most recently from 0b2c756 to 4d5318f Compare April 24, 2025 22:22
Copy link
Member

@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

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

The PA login with LDAP users is now fine, thanks for the fix.

I noticed that with older clients (6.25.1), the CodeChecker cmd token list returns the session tokens instead of the PA tokens.

A separate table is created for personal access tokens in the database.
This table contains a unique name per user that identifies the token.

The token is visible only once at generation. No access is allowed later.
For this reason the old token handler API functions (getTokens(),
newToken(), removeToken()) are deprecated.
Other API functions are introduced instead: getPersonalAccessTokens(),
newPersonalAccessToken() and removePersonalAccessToken(). The old clients
are using the old API functions, but an empty string returns instead of
the token.

Personal access tokens can be created in the web GUI, too.
Copy link
Member

@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

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

LGTM

@dkrupp dkrupp merged commit 6272d91 into Ericsson:master Apr 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 web 🌍 Related to the web app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants