Skip to content

Commit

Permalink
don't validate unsandboxed workloads (#162)
Browse files Browse the repository at this point in the history
* don't validate unsandboxed workloads

* tweaking logic for validate disable

* Add sandbox conditional to statically-linked ELF binary spec

* Fix linter

---------

Co-authored-by: kt <[email protected]>
  • Loading branch information
autodidaddict and kthomas authored Apr 11, 2024
1 parent f7f6b18 commit f9c2c6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
23 changes: 15 additions & 8 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewAgent(ctx context.Context, cancelF context.CancelFunc) (*Agent, error) {
var metadata *agentapi.MachineMetadata
var err error

if strings.ToLower(os.Getenv(nexEnvSandbox)) == "false" {
if !isSandboxed() {
metadata, err = GetMachineMetadataFromEnv()
} else {
metadata, err = GetMachineMetadata()
Expand Down Expand Up @@ -293,12 +293,19 @@ func (a *Agent) handleDeploy(m *nats.Msg) {
}
a.provider = provider

err = a.provider.Validate()
if err != nil {
msg := fmt.Sprintf("Failed to validate workload: %s", err)
a.LogError(msg)
_ = a.workAck(m, false, msg)
return
shouldValidate := true
if !a.sandboxed && strings.EqualFold(*request.WorkloadType, agentapi.NexExecutionProviderELF) {
shouldValidate = false
}

if shouldValidate {
err = a.provider.Validate()
if err != nil {
msg := fmt.Sprintf("Failed to validate workload: %s", err)
a.LogError(msg)
_ = a.workAck(m, false, msg)
return
}
}

err = a.provider.Deploy()
Expand Down Expand Up @@ -484,5 +491,5 @@ func (a *Agent) workAck(m *nats.Msg, accepted bool, msg string) error {
}

func isSandboxed() bool {
return strings.ToLower(os.Getenv("NEX_SANDBOX")) != "false"
return !strings.EqualFold(strings.ToLower(os.Getenv(nexEnvSandbox)), "false")
}
2 changes: 1 addition & 1 deletion internal/node/processmanager/process_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type ProcessManager interface {
StopProcess(id string) error
}

// Initialie an appropriate agent process manager instance based on the sandbox config value
// Initialize an appropriate agent process manager instance based on the sandbox config value
func NewProcessManager(
log *slog.Logger,
config *models.NodeConfiguration,
Expand Down
8 changes: 6 additions & 2 deletions spec/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,12 @@ var _ = Describe("nex node", func() {
_ = cmd.Wait()
})

It("should fail to deploy the ELF workload", func(ctx SpecContext) {
Expect(err.Error()).To(ContainSubstring("elf binary contains at least one dynamically linked dependency"))
It("should [fail to] deploy the ELF workload", func(ctx SpecContext) {
if sandbox {
Expect(err.Error()).To(ContainSubstring("elf binary contains at least one dynamically linked dependency"))
} else {
Expect(err).To(BeNil())
}
})

// It("should keep a reference to all running agent processes", func(ctx SpecContext) {
Expand Down

0 comments on commit f9c2c6b

Please sign in to comment.