Skip to content

Commit d6a2170

Browse files
Merge pull request #302 from step-security/rc-2
Add annotation if allowed endpoint cannot be resolved
2 parents 664b526 + c35ba5b commit d6a2170

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
"fmt"
66
"net/http"
77
"os"
8+
"strings"
89
"time"
910

1011
"github.com/florianl/go-nflog/v2"
1112
)
1213

1314
const (
1415
StepSecurityLogCorrelationPrefix = "Step Security Job Correlation ID:"
16+
StepSecurityAnnotationPrefix = "StepSecurity Harden Runner:"
1517
EgressPolicyAudit = "audit"
1618
EgressPolicyBlock = "block"
1719
)
@@ -109,6 +111,7 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer,
109111
ipAddress, err := dnsProxy.getIPByDomain(domainName)
110112
if err != nil {
111113
WriteLog(fmt.Sprintf("Error resolving allowed domain %v", err))
114+
WriteAnnotation(fmt.Sprintf("%s Reverting agent since allowed endpoint %s could not be resolved", StepSecurityAnnotationPrefix, strings.Trim(domainName, ".")))
112115
RevertChanges(iptables, nflog, cmd, resolvdConfigPath, dockerDaemonConfigPath, dnsConfig)
113116
return err
114117
}

eventhandler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ func (eventHandler *EventHandler) handleFileEvent(event *Event) {
4949
writeDone()
5050
}
5151

52+
if strings.Contains(event.FileName, "daemon.json") {
53+
WriteAnnotation(fmt.Sprintf("%s Overwrite detected for %s", StepSecurityAnnotationPrefix, dockerDaemonConfigPath))
54+
}
55+
56+
if strings.Contains(event.FileName, "resolved.conf") {
57+
WriteAnnotation(fmt.Sprintf("%s Overwrite detected for %s", StepSecurityAnnotationPrefix, resolvedConfigPath))
58+
}
59+
5260
// Uncomment to log file writes (only uncomment in INT env)
5361
// WriteLog(fmt.Sprintf("file write %s, syscall %s", event.FileName, event.Syscall))
5462

main.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ func main() {
1717
ctx, cancel := context.WithCancel(ctx)
1818

1919
signalChan := make(chan os.Signal, 1)
20-
signal.Notify(signalChan, os.Kill, syscall.SIGHUP)
21-
22-
c := &config{}
20+
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
2321

2422
defer func() {
2523
signal.Stop(signalChan)
@@ -29,15 +27,8 @@ func main() {
2927
go func() {
3028
for {
3129
select {
32-
case s := <-signalChan:
33-
switch s {
34-
case syscall.SIGHUP:
35-
c.init(agentConfigFilePath)
36-
case os.Interrupt:
37-
WriteLog("got os.kill")
38-
cancel()
39-
os.Exit(1)
40-
}
30+
case <-signalChan:
31+
WriteAnnotation(fmt.Sprintf("%s Received SIGTERM signal", StepSecurityAnnotationPrefix))
4132
case <-ctx.Done():
4233
WriteLog("called ctx.Done()")
4334
os.Exit(1)

procmon_linux.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ package main
66
import (
77
"fmt"
88

9+
"io/ioutil"
10+
"os"
11+
"strings"
12+
913
"github.com/elastic/go-libaudit/v2"
1014
"github.com/elastic/go-libaudit/v2/auparse"
1115
"github.com/elastic/go-libaudit/v2/rule"
1216
"github.com/elastic/go-libaudit/v2/rule/flags"
1317
"github.com/pkg/errors"
14-
"io/ioutil"
15-
"os"
16-
"strings"
1718
)
1819

1920
func (p *ProcessMonitor) MonitorProcesses(errc chan error) {
@@ -69,6 +70,26 @@ func (p *ProcessMonitor) MonitorProcesses(errc chan error) {
6970

7071
WriteLog("Agent file monitor added")
7172

73+
r, _ = flags.Parse(fmt.Sprintf("-w %s -p w -k %s", dockerDaemonConfigPath, fileMonitorTag))
74+
actualBytes, _ = rule.Build(r)
75+
76+
if err = client.AddRule(actualBytes); err != nil {
77+
WriteLog(fmt.Sprintf("failed to add audit rule for dockerDaemonConfigPath %v", err))
78+
errc <- errors.Wrap(err, "failed to add audit rule")
79+
}
80+
81+
WriteLog("Docker's daemon.json file monitor added")
82+
83+
r, _ = flags.Parse(fmt.Sprintf("-w %s -p w -k %s", resolvedConfigPath, fileMonitorTag))
84+
actualBytes, _ = rule.Build(r)
85+
86+
if err = client.AddRule(actualBytes); err != nil {
87+
WriteLog(fmt.Sprintf("failed to add audit rule for resolvedConfigPath %v", err))
88+
errc <- errors.Wrap(err, "failed to add audit rule")
89+
}
90+
91+
WriteLog("Systemd's resolved.conf file monitor added")
92+
7293
// syscall connect
7394
r, _ = flags.Parse(fmt.Sprintf("-a exit,always -S connect -k %s", netMonitorTag))
7495

release-monitor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ release-process:
77
- artifact: agent_{{.Version}}_linux_amd64.tar.gz
88
binary: agent
99
build-command: go build -trimpath -ldflags="-s -w -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date=123"
10-
go-version: 1.17.12
10+
go-version: 1.17.13
1111
pipeline:
1212
github-action:
1313
repo: step-security/agent

0 commit comments

Comments
 (0)