feat: add deploy tokens (#37306)

Deploy keys only work over SSH. A deploy token is their counterpart for HTTPS: a repository scoped credential, used as the password of a Git request, with read or read and write access. It covers Git operations and LFS, and can be regenerated in place.

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: Claude Mythos <noreply@anthropic.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: bircni <bircni@icloud.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
ToastyTheBot
2026-08-27 03:32:44 +08:00
committed by GitHub
parent 3c4d5a6a5c
commit 646ea0f253
76 changed files with 1594 additions and 831 deletions
+1
View File
@@ -425,6 +425,7 @@ func prepareMigrationTasks() []*migration {
newMigration(349, "Expand action_schedule content column", v28.ExpandActionScheduleContent),
newMigration(350, "Add published_unix column to release", v28.AddPublishedUnixToRelease),
newMigration(351, "Track transfer recipient access grants", v28.AddRecipientAccessGrantedToRepoTransfer),
newMigration(352, "Add token columns to deploy_key", v28.AddTokenToDeployKey),
}
return preparedMigrations
}
+38
View File
@@ -0,0 +1,38 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v28
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
func AddTokenToDeployKey(ctx context.Context, x base.EngineMigration) error {
// Drop the old UNIQUE(s) index on (key_id, repo_id). Every token row carries key
// id 0, so the pair can no longer be unique. AddDeployKey still checks it in code.
indexes, err := x.Dialect().GetIndexes(x.DB(), ctx, "deploy_key")
if err != nil {
return err
}
if idx, ok := indexes["s"]; ok {
if _, err := x.Exec(x.Dialect().DropIndexSQL("deploy_key", idx)); err != nil {
return err
}
}
type DeployKey struct {
KeyID int64 `xorm:"INDEX"`
RepoID int64 `xorm:"INDEX"`
KeyType int `xorm:"NOT NULL DEFAULT 1"` // every existing row is an SSH key
TokenHash string `xorm:"INDEX"`
}
_, err = x.SyncWithOptions(xorm.SyncOptions{
IgnoreConstrains: true,
IgnoreDropIndices: true, // the bean only describes the new columns
}, new(DeployKey))
return err
}