Skip to content

Commit 516e29d

Browse files
Merge pull request #75 from step-security/feature-74
Add egress policy input
2 parents 3535a03 + 6ba6f6f commit 516e29d

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

.github/workflows/scorecard-analysis.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ permissions: read-all
1111

1212
jobs:
1313
analysis:
14+
permissions:
15+
actions: read # for ossf/scorecard-actions/analyze to check for publishing workflows
16+
checks: read # for ossf/scorecard-actions/analyze to check for SAST tool in check runs
17+
contents: read # for ossf/scorecard-actions/analyze to list releases
18+
issues: read # for ossf/scorecard-actions/analyze to check if repo is maintained
19+
pull-requests: read # for ossf/scorecard-actions/analyze to check if PRs are reviewed
20+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
21+
statuses: read # for ossf/scorecard-actions/analyze to check for CI tests in PRs
1422
name: Scorecard analysis
1523
runs-on: ubuntu-latest
16-
permissions:
17-
contents: read
18-
security-events: write
19-
2024
steps:
2125
- uses: step-security/harden-runner@917f7d59f22e82a5ddcaef409923426fd7aa6327
2226
- name: "Checkout code"
@@ -42,4 +46,4 @@ jobs:
4246
- name: "Upload SARIF results"
4347
uses: github/codeql-action/upload-sarif@e095058bfa09de8070f94e98f5dc059531bc6235
4448
with:
45-
sarif_file: results.sarif
49+
sarif_file: results.sarif

agent.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import (
1010
"github.com/florianl/go-nflog/v2"
1111
)
1212

13-
const StepSecurityLogCorrelationPrefix = "Step Security Job Correlation ID:"
13+
const (
14+
StepSecurityLogCorrelationPrefix = "Step Security Job Correlation ID:"
15+
EgressPolicyAudit = "audit"
16+
EgressPolicyBlock = "block"
17+
)
1418

1519
type DNSServer interface {
1620
ListenAndServe() error
@@ -104,7 +108,7 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer,
104108

105109
writeLog("set docker config")
106110

107-
if len(config.Endpoints) == 0 {
111+
if config.EgressPolicy == EgressPolicyAudit {
108112
netMonitor := NetworkMonitor{
109113
CorrelationId: config.CorrelationId,
110114
Repo: config.Repo,
@@ -125,10 +129,7 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer,
125129
}
126130

127131
writeLog("added audit rules")
128-
}
129-
130-
// If allowed endpoints set, resolve them, and add to firewall
131-
if len(config.Endpoints) > 0 {
132+
} else if config.EgressPolicy == EgressPolicyBlock {
132133
var ipAddressEndpoints []ipAddressEndpoint
133134

134135
writeLog(fmt.Sprintf("Allowed domains:%v", config.Endpoints))

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type config struct {
1616
WorkingDirectory string
1717
APIURL string
1818
Endpoints []Endpoint
19+
EgressPolicy string
1920
}
2021

2122
type Endpoint struct {
@@ -30,6 +31,7 @@ type configFile struct {
3031
WorkingDirectory string `json:"working_directory"`
3132
APIURL string `json:"api_url"`
3233
AllowedEndpoints string `json:"allowed_endpoints"`
34+
EgressPolicy string `json:"egress_policy"`
3335
}
3436

3537
// init reads the config file for the agent and initializes config settings
@@ -51,6 +53,7 @@ func (c *config) init(configFilePath string) error {
5153
c.WorkingDirectory = configFile.WorkingDirectory
5254
c.APIURL = configFile.APIURL
5355
c.Endpoints = parseEndpoints(configFile.AllowedEndpoints)
56+
c.EgressPolicy = configFile.EgressPolicy
5457
return nil
5558
}
5659

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"repo":"owner/repo","run_id":"1287185438","correlation_id":"d942cc6c-d349-49da-ad54-a1bf92538567", "api_url":"https://apiurl/v1", "allowed_endpoints":"github.com:443 www.google.com:443"
3-
}
2+
"repo": "owner/repo",
3+
"run_id": "1287185438",
4+
"correlation_id": "d942cc6c-d349-49da-ad54-a1bf92538567",
5+
"api_url": "https://apiurl/v1",
6+
"allowed_endpoints": "github.com:443 www.google.com:443",
7+
"egress_policy": "block"
8+
}

testfiles/agent.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"repo":"owner/repo","run_id":"1287185438","correlation_id":"d942cc6c-d349-49da-ad54-a1bf92538567", "api_url":"https://apiurl/v1", "allowed_endpoints":""
3-
}
2+
"repo": "owner/repo",
3+
"run_id": "1287185438",
4+
"correlation_id": "d942cc6c-d349-49da-ad54-a1bf92538567",
5+
"api_url": "https://apiurl/v1",
6+
"allowed_endpoints": "",
7+
"egress_policy": "audit"
8+
}

0 commit comments

Comments
 (0)