Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

New setting to specify the maximum number of active access tokens a user is allowed#59731

Merged
chwarwick merged 4 commits into
mainfrom
cw/max-access-tokens
Jan 23, 2024
Merged

New setting to specify the maximum number of active access tokens a user is allowed#59731
chwarwick merged 4 commits into
mainfrom
cw/max-access-tokens

Conversation

@chwarwick

@chwarwick chwarwick commented Jan 21, 2024

Copy link
Copy Markdown
Contributor

Add a setting to limit the number of active access tokens a user can have at a one time, the default value is 25 tokens. Internal access tokens do not count towards the active limit. Override of this default is available using the maxTokensPerUser setting in the auth.AccessTokens section of the site config.

This change does not effect existing tokens, if a user is over the limit no tokens are invalidated however they will not be able to create new tokens without first removing enough to get below the limit.

closes https://github.com/sourcegraph/sourcegraph/issues/59544

Test plan

tests add
manual test of access token page and call back page
Screenshot 2024-01-21 at 3 04 46 PM
Screenshot 2024-01-21 at 3 05 09 PM

@chwarwick chwarwick requested a review from eseliger January 23, 2024 13:10

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for tests as well!

Comment thread internal/conf/computed.go
Comment thread internal/database/access_tokens.go Outdated
subjectUserID, pq.Array(scopes), hashutil.ToSHA256Bytes(b[:]), note, creatorUserID, dbutil.NullTimeColumn(expiresAt), internal, conf.AccessTokensMaxPerUser(),
).Scan(&id); err != nil {
// if creation failed check to see if it was because too many tokens already
count, countErr := s.Count(ctx, AccessTokensListOptions{SubjectUserID: subjectUserID})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess technically we should be doing those two DB calls in a transaction for maximum correctness, but not sure it's worth the extra work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I debated that but figured since it's already failed and the likely reason is that it's too many tokens it's just a matter of this supplying a nicer error.

Comment thread schema/site.schema.json
@github-advanced-security

Copy link
Copy Markdown

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@chwarwick chwarwick merged commit 7340339 into main Jan 23, 2024
@chwarwick chwarwick deleted the cw/max-access-tokens branch January 23, 2024 18:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P0: Max number of tokens per user

3 participants