Skip to content

Commit 6e23078

Browse files
committed
feat(actions_permissions): sha_pinning_required
Fix #2869. Signed-off-by: Leonard Sheng Sheng Lee <leonard.sheng.sheng.lee@gmail.com>
1 parent f9b0678 commit 6e23078

7 files changed

+47
-2
lines changed

github/resource_github_actions_organization_permissions.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func resourceGithubActionsOrganizationPermissions() *schema.Resource {
5757
Optional: true,
5858
Description: "Whether actions in GitHub Marketplace from verified creators are allowed. Set to 'true' to allow all GitHub Marketplace actions by verified creators.",
5959
},
60+
"sha_pinning_required": {
61+
Type: schema.TypeBool,
62+
Optional: true,
63+
Description: "Whether pinning to a specific SHA is required for all actions and reusable workflows in an organization.",
64+
},
6065
},
6166
},
6267
},
@@ -96,6 +101,10 @@ func resourceGithubActionsOrganizationAllowedObject(d *schema.ResourceData) *git
96101
allowed.VerifiedAllowed = &x
97102
}
98103

104+
if v, ok := data["sha_pinning_required"]; ok {
105+
allowed.SHAPinningRequired = github.Bool(v.(bool))
106+
}
107+
99108
patternsAllowed := []string{}
100109

101110
switch t := data["patterns_allowed"].(type) {
@@ -226,6 +235,7 @@ func resourceGithubActionsOrganizationPermissionsRead(d *schema.ResourceData, me
226235
"github_owned_allowed": actionsAllowed.GetGithubOwnedAllowed(),
227236
"patterns_allowed": actionsAllowed.PatternsAllowed,
228237
"verified_allowed": actionsAllowed.GetVerifiedAllowed(),
238+
"sha_pinning_required": actionsAllowed.GetShaPinningRequired(),
229239
},
230240
}); err != nil {
231241
return err
@@ -306,3 +316,19 @@ func resourceGithubActionsOrganizationPermissionsDelete(d *schema.ResourceData,
306316

307317
return nil
308318
}
319+
320+
func flattenActionsAllowed(d *schema.ResourceData, actionsAllowed *github.ActionsAllowed) error {
321+
if actionsAllowed != nil {
322+
config := make(map[string]interface{})
323+
config["github_owned_allowed"] = actionsAllowed.GetGithubOwnedAllowed()
324+
config["verified_allowed"] = actionsAllowed.GetVerifiedAllowed()
325+
config["patterns_allowed"] = schema.NewSet(schema.HashString, interfaceSlice(actionsAllowed.GetPatternsAllowed()))
326+
config["sha_pinning_required"] = actionsAllowed.GetShaPinningRequired()
327+
328+
if err := d.Set("allowed_actions_config", []interface{}{config}); err != nil {
329+
return err
330+
}
331+
}
332+
333+
return nil
334+
}

github/resource_github_actions_organization_permissions_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) {
5252
enabledRepositories := "selected"
5353
githubOwnedAllowed := true
5454
verifiedAllowed := true
55+
shaPinningRequired := true
5556
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
5657

5758
config := fmt.Sprintf(`
@@ -68,12 +69,13 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) {
6869
github_owned_allowed = %t
6970
patterns_allowed = ["actions/cache@*", "actions/checkout@*"]
7071
verified_allowed = %t
72+
sha_pinning_required = %t
7173
}
7274
enabled_repositories_config {
7375
repository_ids = [github_repository.test.repo_id]
7476
}
7577
}
76-
`, randomID, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed)
78+
`, randomID, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed, shaPinningRequired)
7779

7880
check := resource.ComposeTestCheckFunc(
7981
resource.TestCheckResourceAttr(

github/resource_github_actions_repository_permissions.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func resourceGithubActionsRepositoryPermissions() *schema.Resource {
5050
Optional: true,
5151
Description: "Whether actions in GitHub Marketplace from verified creators are allowed. Set to 'true' to allow all GitHub Marketplace actions by verified creators.",
5252
},
53+
"sha_pinning_required": {
54+
Type: schema.TypeBool,
55+
Optional: true,
56+
Description: "Whether pinning to a specific SHA is required for all actions and reusable workflows in a repository.",
57+
},
5358
},
5459
},
5560
},
@@ -85,6 +90,10 @@ func resourceGithubActionsRepositoryAllowedObject(d *schema.ResourceData) *githu
8590
allowed.VerifiedAllowed = &x
8691
}
8792

93+
if v, ok := data["sha_pinning_required"]; ok {
94+
allowed.SHAPinningRequired = github.Bool(v.(bool))
95+
}
96+
8897
patternsAllowed := []string{}
8998

9099
switch t := data["patterns_allowed"].(type) {
@@ -189,6 +198,7 @@ func resourceGithubActionsRepositoryPermissionsRead(d *schema.ResourceData, meta
189198
"github_owned_allowed": actionsAllowed.GetGithubOwnedAllowed(),
190199
"patterns_allowed": actionsAllowed.PatternsAllowed,
191200
"verified_allowed": actionsAllowed.GetVerifiedAllowed(),
201+
"sha_pinning_required": actionsAllowed.GetShaPinningRequired(),
192202
},
193203
}); err != nil {
194204
return err

github/resource_github_actions_repository_permissions_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) {
6262
allowedActions := "selected"
6363
githubOwnedAllowed := true
6464
verifiedAllowed := true
65+
shaPinningRequired := true
6566
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
6667

6768
config := fmt.Sprintf(`
@@ -77,10 +78,11 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) {
7778
github_owned_allowed = %t
7879
patterns_allowed = ["actions/cache@*", "actions/checkout@*"]
7980
verified_allowed = %t
81+
sha_pinning_required = %t
8082
}
8183
repository = github_repository.test.name
8284
}
83-
`, randomID, allowedActions, githubOwnedAllowed, verifiedAllowed)
85+
`, randomID, allowedActions, githubOwnedAllowed, verifiedAllowed, shaPinningRequired)
8486

8587
check := resource.ComposeTestCheckFunc(
8688
resource.TestCheckResourceAttr(

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ require (
105105
github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e // indirect
106106
github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect
107107
github.com/google/go-cmp v0.7.0 // indirect
108+
github.com/google/go-github/v79 v79.0.0 // indirect
108109
github.com/google/go-querystring v1.1.0 // indirect
109110
github.com/gordonklaus/ineffassign v0.2.0 // indirect
110111
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
334334
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
335335
github.com/google/go-github/v67 v67.0.0 h1:g11NDAmfaBaCO8qYdI9fsmbaRipHNWRIU/2YGvlh4rg=
336336
github.com/google/go-github/v67 v67.0.0/go.mod h1:zH3K7BxjFndr9QSeFibx4lTKkYS3K9nDanoI1NjaOtY=
337+
github.com/google/go-github/v79 v79.0.0 h1:MdodQojuFPBhmtwHiBcIGLw/e/wei2PvFX9ndxK0X4Y=
338+
github.com/google/go-github/v79 v79.0.0/go.mod h1:OAFbNhq7fQwohojb06iIIQAB9CBGYLq999myfUFnrS4=
337339
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
338340
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
339341
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=

vendor/modules.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ github.com/google/go-cmp/cmp/internal/value
564564
# github.com/google/go-github/v67 v67.0.0
565565
## explicit; go 1.21
566566
github.com/google/go-github/v67/github
567+
# github.com/google/go-github/v79 v79.0.0
568+
## explicit; go 1.24.0
567569
# github.com/google/go-querystring v1.1.0
568570
## explicit; go 1.10
569571
github.com/google/go-querystring/query

0 commit comments

Comments
 (0)