fix: 从后端恢复 Runner claim
This commit is contained in:
@@ -23,6 +23,21 @@ type Identity struct {
|
||||
SPIFFEID string
|
||||
}
|
||||
|
||||
// FromMetadata validates identity fields recovered from backend-owned state.
|
||||
func FromMetadata(repository, task, spiffeID, trustDomain string) (Identity, error) {
|
||||
parts := strings.Split(repository, "/")
|
||||
if len(parts) != 2 || parts[0] == "" || parts[1] == "" || !safeTaskKey.MatchString(task) {
|
||||
return Identity{}, errors.New("invalid recovered repository or task identity")
|
||||
}
|
||||
expected := "spiffe://" + trustDomain + "/ci/" + strings.Join([]string{
|
||||
sanitize(parts[0]), sanitize(parts[1]), task,
|
||||
}, "/")
|
||||
if spiffeID != expected {
|
||||
return Identity{}, fmt.Errorf("recovered SPIFFE ID %q does not match %q", spiffeID, expected)
|
||||
}
|
||||
return Identity{Repository: repository, Task: task, SPIFFEID: spiffeID}, nil
|
||||
}
|
||||
|
||||
// FromTask derives the repository/task SPIFFE ID from Gitea's trusted task
|
||||
// context. Workflow input never supplies or overrides the resulting ID.
|
||||
func FromTask(task *runnerv1.Task, trustDomain string) (Identity, error) {
|
||||
|
||||
Reference in New Issue
Block a user