|
9 | 9 | "time" |
10 | 10 |
|
11 | 11 | "github.com/florianl/go-nflog/v2" |
| 12 | + "github.com/step-security/agent/lockfile" |
| 13 | + "github.com/step-security/armour/armour" |
12 | 14 | ) |
13 | 15 |
|
14 | 16 | const ( |
@@ -75,12 +77,25 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer, |
75 | 77 | WriteLog(fmt.Sprintf("%s %s", StepSecurityLogCorrelationPrefix, config.CorrelationId)) |
76 | 78 | WriteLog("\n") |
77 | 79 |
|
| 80 | + InitGlobalFeatureFlags(config.APIURL, apiclient) |
| 81 | + WriteLog("initialized global feature flags") |
| 82 | + WriteLog("\n") |
| 83 | + if IsArmourEnabled() { |
| 84 | + lf := lockfile.New(agentLockFile) |
| 85 | + if err := lf.TryLock(); err != nil { |
| 86 | + WriteLog("[agent] instance is already running") |
| 87 | + os.Exit(0) |
| 88 | + } |
| 89 | + defer lf.MustUnlock() |
| 90 | + } |
| 91 | + |
78 | 92 | // if this is a private repo |
79 | 93 | if config.Private { |
80 | 94 | isActive := apiclient.getSubscriptionStatus(config.Repo) |
81 | 95 | if !isActive { |
82 | 96 | config.EgressPolicy = EgressPolicyAudit |
83 | 97 | config.DisableSudo = false |
| 98 | + config.DisableSudoAndContainers = false |
84 | 99 | apiclient.DisableTelemetry = true |
85 | 100 | config.DisableFileMonitoring = true |
86 | 101 | WriteAnnotation("StepSecurity Harden Runner is disabled. A subscription is required for private repositories. Please start a free trial at https://www.stepsecurity.io") |
@@ -119,6 +134,10 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer, |
119 | 134 | sudo := Sudo{} |
120 | 135 | var ipAddressEndpoints []ipAddressEndpoint |
121 | 136 |
|
| 137 | + if config.DisableSudoAndContainers { |
| 138 | + go sudo.uninstallDocker() |
| 139 | + } |
| 140 | + |
122 | 141 | // hydrate dns cache |
123 | 142 | if config.EgressPolicy == EgressPolicyBlock { |
124 | 143 | for domainName, endpoints := range allowedEndpoints { |
@@ -204,6 +223,44 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer, |
204 | 223 | go refreshDNSEntries(ctx, iptables, allowedEndpoints, &dnsProxy) |
205 | 224 | } |
206 | 225 |
|
| 226 | + if IsArmourEnabled() { |
| 227 | + WriteLog("Armour is enabled") |
| 228 | + conf := &armour.Config{ |
| 229 | + Pids: getPidsOfInterest(), |
| 230 | + Files: []string{}, |
| 231 | + EnforceReadBlock: false, |
| 232 | + ApiConf: &armour.ApiConf{ |
| 233 | + APIURL: config.APIURL, |
| 234 | + Repo: config.Repo, |
| 235 | + CorrelationID: config.CorrelationId, |
| 236 | + OneTimeKey: config.OneTimeKey, |
| 237 | + DisableTelemetry: config.DisableTelemetry, |
| 238 | + }, |
| 239 | + } |
| 240 | + |
| 241 | + conf.Files = append(conf.Files, getProcFilesOfInterest()...) |
| 242 | + |
| 243 | + conf.Files = append(conf.Files, getFilesOfInterest()...) |
| 244 | + |
| 245 | + mArmour := armour.NewArmour(ctx, conf) |
| 246 | + err := mArmour.Attach() |
| 247 | + if err != nil { |
| 248 | + WriteLog("Armour attachment failed") |
| 249 | + } else { |
| 250 | + defer mArmour.Detach() |
| 251 | + WriteLog("Armour attached") |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + if config.DisableSudoAndContainers { |
| 256 | + err := sudo.disableSudoAndContainers(tempDir) |
| 257 | + if err != nil { |
| 258 | + WriteLog(fmt.Sprintf("%s Unable to disable sudo and docker %v", StepSecurityAnnotationPrefix, err)) |
| 259 | + } else { |
| 260 | + WriteLog("disabled sudo and docker") |
| 261 | + } |
| 262 | + } |
| 263 | + |
207 | 264 | if config.DisableSudo { |
208 | 265 | err := sudo.disableSudo(tempDir) |
209 | 266 | if err != nil { |
|
0 commit comments