Skip to content

Commit a9f2ba0

Browse files
Release v1.3.2 (#2095)
1 parent d8f79f0 commit a9f2ba0

22 files changed

+169
-13
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Harden Runner
4444
uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5
4545
with:
46-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
46+
egress-policy: audit
4747

4848
- name: Checkout repository
4949
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b

.github/workflows/kbanalysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Harden Runner
2525
uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5
2626
with:
27-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
27+
egress-policy: audit
2828

2929
- uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28
3030
with:

remediation/workflow/hardenrunner/addaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func addAction(inputYaml, jobName, action string) (string, error) {
8383
output = append(output, spaces+fmt.Sprintf("- name: %s", HardenRunnerActionName))
8484
output = append(output, spaces+fmt.Sprintf(" uses: %s", action))
8585
output = append(output, spaces+" with:")
86-
output = append(output, spaces+" egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs")
86+
output = append(output, spaces+" egress-policy: audit")
8787
output = append(output, "")
8888

8989
for i := jobNode.Line - 1; i < len(inputLines); i++ {

remediation/workflow/permissions/permissions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func AddWorkflowLevelPermissions(inputYaml string, addProjectComment bool) (stri
101101
line := 0
102102
column := 0
103103
topNode := t.Content
104+
if len(topNode) == 0 {
105+
return inputYaml, fmt.Errorf("Workflow file provided is Empty")
106+
}
104107
for _, n := range topNode[0].Content {
105108
if n.Value == "jobs" && n.Tag == "!!str" {
106109
line = n.Line

remediation/workflow/pin/pinactions.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,34 @@ func PinAction(action, inputYaml string) (string, bool) {
7676
pinnedAction := fmt.Sprintf("%s@%s # %s", leftOfAt[0], commitSHA, tagOrBranch)
7777
updated = !strings.EqualFold(action, pinnedAction)
7878
inputYaml = strings.ReplaceAll(inputYaml, action, pinnedAction)
79+
yamlWithPreviousActionCommentsRemoved, wasModified := removePreviousActionComments(pinnedAction, inputYaml)
80+
if wasModified {
81+
return yamlWithPreviousActionCommentsRemoved, updated
82+
}
83+
return inputYaml, updated
84+
}
85+
86+
// It may be that there was already a comment next to the action
87+
// In this case we want to remove the earlier comment
88+
// we add a comment with the Action version so dependabot/ renovatebot can update it
89+
// if there was no comment next to any action, updated will be false
90+
func removePreviousActionComments(pinnedAction, inputYaml string) (string, bool) {
91+
updated := false
92+
stringParts := strings.Split(inputYaml, pinnedAction)
93+
if len(stringParts) > 1 {
94+
inputYaml = ""
95+
inputYaml = stringParts[0]
96+
for idx := 1; idx < len(stringParts); idx++ {
97+
trimmedString := strings.SplitN(stringParts[idx], "\n", 2)
98+
if len(trimmedString) > 1 {
99+
if strings.Contains(trimmedString[0], "#") {
100+
updated = true
101+
}
102+
inputYaml = inputYaml + pinnedAction + "\n" + trimmedString[1]
103+
}
104+
}
105+
}
106+
79107
return inputYaml, updated
80108
}
81109

remediation/workflow/pin/pinactions_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ func TestPinActions(t *testing.T) {
182182
{fileName: "basic.yml", wantUpdated: true},
183183
{fileName: "dockeraction.yml", wantUpdated: true},
184184
{fileName: "multipleactions.yml", wantUpdated: true},
185+
{fileName: "actionwithcomment.yml", wantUpdated: true},
186+
{fileName: "repeatedactionwithcomment.yml", wantUpdated: true},
185187
}
186188
for _, tt := range tests {
187189
input, err := ioutil.ReadFile(path.Join(inputDirectory, tt.fileName))

remediation/workflow/secureworkflow_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestSecureWorkflow(t *testing.T) {
120120
{fileName: "nopin.yml", wantPinnedActions: false, wantAddedHardenRunner: true, wantAddedPermissions: true},
121121
{fileName: "allperms.yml", wantPinnedActions: false, wantAddedHardenRunner: false, wantAddedPermissions: true},
122122
{fileName: "multiplejobperms.yml", wantPinnedActions: false, wantAddedHardenRunner: false, wantAddedPermissions: true},
123+
{fileName: "error.yml", wantPinnedActions: false, wantAddedHardenRunner: false, wantAddedPermissions: false},
123124
}
124125
for _, test := range tests {
125126
input, err := ioutil.ReadFile(path.Join(inputDirectory, test.fileName))

testfiles/addaction/input/alreadypresent_2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
- name: Harden Runner
1414
uses: step-security/harden-runner@v2
1515
with:
16-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
16+
egress-policy: audit
1717

1818
- run: ls -R

testfiles/addaction/output/2jobs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- name: Harden Runner
99
uses: step-security/harden-runner@v2
1010
with:
11-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
11+
egress-policy: audit
1212

1313
- run: ls -R
1414
list-directory1:
@@ -17,6 +17,6 @@ jobs:
1717
- name: Harden Runner
1818
uses: step-security/harden-runner@v2
1919
with:
20-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
20+
egress-policy: audit
2121

2222
- run: ls -R

testfiles/addaction/output/action-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Harden Runner
1313
uses: step-security/harden-runner@v2
1414
with:
15-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
15+
egress-policy: audit
1616

1717
- name: Close Issue
1818
uses: peter-evans/close-issue@v1

0 commit comments

Comments
 (0)