Handle creation/deletion of workspace tokens and create token docs
MR: Handle creation/deletion of workspace tokens an... (!194097 - merged) • Chad Woolley • 18.2
Description
SUMMARY: Handle creation/deletion of workspace tokens according to workspace lifecycle.
The WorkspaceToken model was created as part of Add workspace tokens table (#545068 - closed) • Chad Woolley • 18.1, by MR Add WorkspaceTokens model and table (!193071 - merged) • Chad Woolley • 18.1
We now need to manage the lifecycle of WorkspaceToken creation/deletion according to rules specified in the Implementation Plan section below.
This MR should also introduce appropriate docs for the new token to the page at https://docs.gitlab.com/security/tokens, and add to list at https://docs.gitlab.com/security/tokens/#available-scopes
Acceptance criteria
-
Workspace Tokens are created and deleted according to criteria in Implementation Plan below -
Introduce appropriate docs for the new token to the page at https://docs.gitlab.com/security/tokens, and add to list at https://docs.gitlab.com/security/tokens/#available-scopes
Implementation plan
We need to manage the lifecycle of WorkspaceToken creation/deletion according to these rules:
- Create an associated WorkspaceToken record when a Workspace transitions to
desired_stateofRunning. This should happen both on initial creation, and after a workspace is Stopped and Restarted. In-memoryworkspace.workspace_tokenattribute should be updated to the new record. - Delete the associated WorkspaceToken record when a Workspace transitions to
desired_stateofRestartRequested,StoppedORTerminated(i.e. anything other thanRunning). In-memoryworkspace.workspace_tokenattribute should be updated tonil. - Gracefully handle inconsistent DB states - these should never happen normally, but should not cause errors:
- If token already exists when transitioning TO
Running, then rotate it (delete and recreate) - If token does not exist when transitioning FROM
Running, do not raise an error.
- If token already exists when transitioning TO
Related
- Epic: Simplify Workspaces setup by removing GitLab Wo... (&16785) • Chad Woolley, Vishal Tak
- WorkspaceTokens model/table creation: Add workspace tokens table (#545068 - closed) • Chad Woolley • 18.1
- Duplicate closed issue: Create/delete workspace tokens when workspace i... (#547111 - closed) • Unassigned • Backlog