Skip to content

[Proposal] Support reusable Registration Token of runners #25041

Closed
@sillyguodong

Description

@sillyguodong

Background

Currently, the Registration Token obtained in the UI becomes invalid immediately after registering a runner, making it impossible to reuse. However, it is annoying that not having reusbale annoying in some auto-scaling environments.

Here are some related issues::

In fact, we already have related PRs that enable Gitea to provide the ability to generate Tokens via the command line or API:

But I believe it would be more convenient to have a reusable token. Of course, it would also be necessary to provide the ability to invalidate Tokens in real-time to prevent misuse.

Solution

  1. Add the following fields to the table:

       type ActionRunnerToken struct {
           ID       int64
           Token    string `xorm:"UNIQUE"`
           IsActive bool
           // Omitting other fields
           // The following are the added fields:
           Type          ActionRunnerTokenType
           ParentTokenID int64
           Desc          string
       }
    
       type ActionRunnerTokenType int
    
       const (
           NormalRunnerToken ActionRunnerTokenType = iota
    
           ReusableRunnerToken
       )
  2. In the UI, users can create reusable tokens and view them in a list. In the list, they can enable, disable, or delete tokens at any time.
    image

  3. When Gitea receives a runner registration request, it first checks if the token is a reusable token. If it is, a normal token is generated for the runner and returned. This normal token will be written to the .runner file. At the same time, the normal token inherits the owner_id and repo_id from the reusable token and is stored in the database.

  4. As mentioned in this comment,we should also provide the ability to deregister runners:

    It would also be great if there was a way to unregister act_runner as well, especially if you want them to be created and deleted dynamically, to avoid having unnecessary act_runner corpses in the database.

    To achieve this, we need to add the following to the protocol buffer:

       service RunnerService {
         // Deregister deregister new runner in server.
         rpc Deregister(DeregisterRequest) returns (DeregisterResponse) {}
       }
    
       message DeregisterRequest {
         int64 id = 1;
         string uuid = 2;
         string token = 3; // must be normal token in .runner file
       }
    
       message DeregisterResponse {
         Runner runner = 1;
       }

Benefits

  1. Creating a reusable token needs to be done in Site Administration, Repo Settings, or Org Settings, defining the scope of runners that use this reusable token. This is consistent with the previous token logic.
  2. The implementation is simple and does not affect the existing logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic/gitea-actionsrelated to the actions of Giteatype/enhancementAn improvement of existing functionalitytype/proposalThe new feature has not been accepted yet but needs to be discussed first.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions