Skip to content

Commit 368743b

Browse files
Add ac claim for old docker/build-push-action@v3 / current buildx gha cache (#29584)
Also resolves a warning for current releases ``` | ##[group]GitHub Actions runtime token ACs | ##[warning]Cannot parse GitHub Actions Runtime Token ACs: "undefined" is not valid JSON | ##[endgroup] ====> | ##[group]GitHub Actions runtime token ACs | ##[endgroup] ``` \* this is an error in v3 References in the docker org: - https://github.com/docker/build-push-action/blob/831ca179d3cf91cf0c90ca465a408fa61e2129a2/src/main.ts#L24 - https://github.com/docker/actions-toolkit/blob/7d8b4dc6694df35a06fae786427672ce27a8c18d/src/github.ts#L61 No known official action of GitHub makes use of this claim. Current releases throw an error when configure to use actions cache ``` | ERROR: failed to solve: failed to configure gha cache exporter: invalid token without access controls | ##[error]buildx failed with: ERROR: failed to solve: failed to configure gha cache exporter: invalid token without access controls ```
1 parent 136dd99 commit 368743b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

services/actions/auth.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"code.gitea.io/gitea/modules/json"
1213
"code.gitea.io/gitea/modules/log"
1314
"code.gitea.io/gitea/modules/setting"
1415

@@ -21,17 +22,41 @@ type actionsClaims struct {
2122
TaskID int64
2223
RunID int64
2324
JobID int64
25+
Ac string `json:"ac"`
2426
}
2527

28+
type actionsCacheScope struct {
29+
Scope string
30+
Permission actionsCachePermission
31+
}
32+
33+
type actionsCachePermission int
34+
35+
const (
36+
actionsCachePermissionRead = 1 << iota
37+
actionsCachePermissionWrite
38+
)
39+
2640
func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error) {
2741
now := time.Now()
2842

43+
ac, err := json.Marshal(&[]actionsCacheScope{
44+
{
45+
Scope: "",
46+
Permission: actionsCachePermissionWrite,
47+
},
48+
})
49+
if err != nil {
50+
return "", err
51+
}
52+
2953
claims := actionsClaims{
3054
RegisteredClaims: jwt.RegisteredClaims{
3155
ExpiresAt: jwt.NewNumericDate(now.Add(24 * time.Hour)),
3256
NotBefore: jwt.NewNumericDate(now),
3357
},
3458
Scp: fmt.Sprintf("Actions.Results:%d:%d", runID, jobID),
59+
Ac: string(ac),
3560
TaskID: taskID,
3661
RunID: runID,
3762
JobID: jobID,

services/actions/auth_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"testing"
99

10+
"code.gitea.io/gitea/modules/json"
1011
"code.gitea.io/gitea/modules/setting"
1112

1213
"github.com/golang-jwt/jwt/v5"
@@ -29,6 +30,14 @@ func TestCreateAuthorizationToken(t *testing.T) {
2930
taskIDClaim, ok := claims["TaskID"]
3031
assert.True(t, ok, "Has TaskID claim in jwt token")
3132
assert.Equal(t, float64(taskID), taskIDClaim, "Supplied taskid must match stored one")
33+
acClaim, ok := claims["ac"]
34+
assert.True(t, ok, "Has ac claim in jwt token")
35+
ac, ok := acClaim.(string)
36+
assert.True(t, ok, "ac claim is a string for buildx gha cache")
37+
scopes := []actionsCacheScope{}
38+
err = json.Unmarshal([]byte(ac), &scopes)
39+
assert.NoError(t, err, "ac claim is a json list for buildx gha cache")
40+
assert.GreaterOrEqual(t, len(scopes), 1, "Expected at least one action cache scope for buildx gha cache")
3241
}
3342

3443
func TestParseAuthorizationToken(t *testing.T) {

0 commit comments

Comments
 (0)