mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
* client: sandbox go-getter subprocess with landlock This PR re-implements the getter package for artifact downloads as a subprocess. Key changes include On all platforms, run getter as a child process of the Nomad agent. On Linux platforms running as root, run the child process as the nobody user. On supporting Linux kernels, uses landlock for filesystem isolation (via go-landlock). On all platforms, restrict environment variables of the child process to a static set. notably TMP/TEMP now points within the allocation's task directory kernel.landlock attribute is fingerprinted (version number or unavailable) These changes make Nomad client more resilient against a faulty go-getter implementation that may panic, and more secure against bad actors attempting to use artifact downloads as a privilege escalation vector. Adds new e2e/artifact suite for ensuring artifact downloading works. TODO: Windows git test (need to modify the image, etc... followup PR) * landlock: fixup items from cr * cr: fixup tests and go.mod file
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package getter
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
cconfig "github.com/hashicorp/nomad/client/config"
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
|
sconfig "github.com/hashicorp/nomad/nomad/structs/config"
|
|
"github.com/shoenig/test/must"
|
|
)
|
|
|
|
// TestSandbox creates a real artifact downloader configured via the default
|
|
// artifact config. It is good enough for tests so no mock implementation exists.
|
|
func TestSandbox(t *testing.T) *Sandbox {
|
|
ac, err := cconfig.ArtifactConfigFromAgent(sconfig.DefaultArtifactConfig())
|
|
must.NoError(t, err)
|
|
return New(ac, testlog.HCLogger(t))
|
|
}
|
|
|
|
// SetupDir creates a directory suitable for testing artifact - i.e. it is
|
|
// owned by the nobody user as would be the case in a normal client operation.
|
|
//
|
|
// returns alloc_dir, task_dir
|
|
func SetupDir(t *testing.T) (string, string) {
|
|
uid, gid := credentials()
|
|
|
|
allocDir := t.TempDir()
|
|
taskDir := filepath.Join(allocDir, "local")
|
|
topDir := filepath.Dir(allocDir)
|
|
|
|
must.NoError(t, os.Chown(topDir, int(uid), int(gid)))
|
|
must.NoError(t, os.Chmod(topDir, 0o755))
|
|
|
|
must.NoError(t, os.Chown(allocDir, int(uid), int(gid)))
|
|
must.NoError(t, os.Chmod(allocDir, 0o755))
|
|
|
|
must.NoError(t, os.Mkdir(taskDir, 0o755))
|
|
must.NoError(t, os.Chown(taskDir, int(uid), int(gid)))
|
|
must.NoError(t, os.Chmod(taskDir, 0o755))
|
|
return allocDir, taskDir
|
|
}
|