Skip to content

Commit

Permalink
Add ac claim for old docker/build-push-actions@v3
Browse files Browse the repository at this point in the history
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]
```
  • Loading branch information
ChristopherHX committed Mar 4, 2024
1 parent e917334 commit d6251f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions services/actions/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type actionsClaims struct {
TaskID int64
RunID int64
JobID int64
Ac string `json:"ac"`
}

func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error) {
Expand All @@ -32,6 +33,7 @@ func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error) {
NotBefore: jwt.NewNumericDate(now),
},
Scp: fmt.Sprintf("Actions.Results:%d:%d", runID, jobID),
Ac: "[]",
TaskID: taskID,
RunID: runID,
JobID: jobID,
Expand Down
7 changes: 7 additions & 0 deletions services/actions/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package actions

import (
"encoding/json"

Check failure on line 7 in services/actions/auth_test.go

View workflow job for this annotation

GitHub Actions / lint-backend

import 'encoding/json' is not allowed from list 'main': use gitea's modules/json instead of encoding/json (depguard)

Check failure on line 7 in services/actions/auth_test.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

import 'encoding/json' is not allowed from list 'main': use gitea's modules/json instead of encoding/json (depguard)

Check failure on line 7 in services/actions/auth_test.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

import 'encoding/json' is not allowed from list 'main': use gitea's modules/json instead of encoding/json (depguard)
"net/http"
"testing"

Expand All @@ -29,6 +30,12 @@ func TestCreateAuthorizationToken(t *testing.T) {
taskIDClaim, ok := claims["TaskID"]
assert.True(t, ok, "Has TaskID claim in jwt token")
assert.Equal(t, float64(taskID), taskIDClaim, "Supplied taskid must match stored one")
acClaim, ok := claims["ac"]
assert.True(t, ok, "Has ac claim in jwt token")
ac, ok := acClaim.(string)
assert.True(t, ok, "ac claim is a string")
err = json.Unmarshal([]byte(ac), &[]struct{}{})
assert.NoError(t, err, "ac claim is a json list")
}

func TestParseAuthorizationToken(t *testing.T) {
Expand Down

0 comments on commit d6251f0

Please sign in to comment.