[feat] add API token management functionality#4080
Open
Duansg wants to merge 10 commits intoapache:masterfrom
Open
[feat] add API token management functionality#4080Duansg wants to merge 10 commits intoapache:masterfrom
Duansg wants to merge 10 commits intoapache:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Previously, there was no way to manage HertzBeat API tokens once they were generated, which led to the following issues:
Tokenis shared with a third party for alert integration or log ingestion, the access permissions for that Token cannot be revoked, which poses a security risk.Tokengeneration button is scattered across various integration pages (alert integration, log integration), giving the impression that it is a feature specific to each integration rather than a global setting, which can easily confuse users.Tokens; it is unclear how manyTokensare in use within the system, who created them, or whether they are still actively in use.Modification Details
Persistent Storage of API Tokens: Do not store plaintext; display masked versions; record the creator, creation time, expiration time, and last access time.
API Token Revocation Validation Filter: Runs after
Surenessauthentication to check whether the authenticatedTokenhas been revoked. (ExistingTokensare not affected; backward compatibility is maintained.)API Token Expiration Time: When generating the token, you can select an expiration time (7, 30, 90, 180, or 365 days, or never expire). The expiration time is written to the JWT
expclaim and is natively validated by theSurenessframework.Permissions Configuration Update (sureness.yml): The /api/account/token endpoints remain admin-only, and the controller layer keeps the same restriction. Only administrators can generate, list, and revoke API tokens; administrators can revoke any token.
Managed Token Identification: Newly generated API tokens carry a dedicated managed=true JWT claim. Only these managed tokens are subject to database-backed lifecycle checks; legacy tokens without this claim continue to work for backward compatibility.
Runtime Account and Role Revalidation: For managed tokens, each authenticated request revalidates the token owner’s current account status and role set. If the account is disabled, removed, or no longer has the required roles, the token is rejected even if the JWT itself has not yet expired.
Fail-Closed Revocation Checking: Revocation and account-state validation no longer fail open. If token status validation cannot be completed because of a runtime/storage error, the request is denied instead of being silently allowed. lastUsedTime updates remain best-effort and do not block requests.
Managed Token Lifecycle Tracking: Managed tokens now support full lifecycle operations, including generation, listing, revocation, last-access updates, and expiration-based invalidation, while keeping legacy token behavior unchanged.
Frontend and E2E Alignment: The frontend token management flow and E2E tests were updated to match the new semantics, including explicit “never expire” handling and end-to-end coverage for token generation, usage, listing, and revocation.
Checklist
Add or update API