-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add namespace isolation support for proxy processes #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b56d626
Create proxy in the correct namespace defined by specs
Luke-Parkin c8f0026
Use OK rather than err
Luke-Parkin 670e0a4
Add a test for inheriting the correct namespace
Luke-Parkin d57170c
If running without root, do not do namespace isolation
Luke-Parkin 3736da6
Add tests rootless run
Luke-Parkin aad47da
lowercase error messages
Luke-Parkin 9649e44
Remove unneeded arg and use correct terminology
Luke-Parkin f46b9d3
Don't use root-requiring tests, add a unit test.
Luke-Parkin 9c568d3
Unit testing
Luke-Parkin bb81f30
oops
Luke-Parkin e6e1e51
Merge branch 'main' into network-namespaces
Luke-Parkin b1cc94f
Rework tests, improve logging
Luke-Parkin 6fb1977
Address review comments, allow nil linux namespace
Luke-Parkin 8f01ce8
Ensure logger is added, add alpine img for tests. move tests into cen…
Luke-Parkin f534a7f
Safety third
Luke-Parkin 827a7ac
DRY!
Luke-Parkin 654d472
use a universal bin path
Luke-Parkin 34c5ff1
arch?
Luke-Parkin a4bf97d
Seems unlikely..
Luke-Parkin bee0dcf
Revert vm changes
Luke-Parkin 6663003
Merge branch 'main' into network-namespaces
Luke-Parkin 959ee9e
Merge branch 'main' into network-namespaces
Luke-Parkin 4b743a2
Update to match new test method
Luke-Parkin e0838bb
ProcessPID fix
Luke-Parkin b39e1ea
Remove rebase failures, remove --network=host from e2e tests, add rat…
Luke-Parkin 3800ba8
Merge branch 'main' into network-namespaces
Luke-Parkin 379ef50
Collapse tests into a nested t.run()
Luke-Parkin 2974a96
Fix formatting
Luke-Parkin 913f822
Change test names
Luke-Parkin f7bb9d7
Reuse `Runnable` abstraction for `sudo`
muchzill4 3429464
Merge pull request #1 from muchzill4/sudo-abstraction
Luke-Parkin fe5a97d
Linting
Luke-Parkin f96f1ad
Add string return for InstalledBin
Luke-Parkin a31f40c
Merge branch 'main' into network-namespaces
Luke-Parkin 5d5b162
Remove no longer needed podman arg
muchzill4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Luke-Parkin marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package proxy | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log/slog" | ||
|
|
||
| "github.com/opencontainers/runtime-spec/specs-go" | ||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| var specNamespacesToUnixCloneFlags = map[specs.LinuxNamespaceType]uintptr{ | ||
| specs.CgroupNamespace: unix.CLONE_NEWCGROUP, | ||
| specs.IPCNamespace: unix.CLONE_NEWIPC, | ||
| specs.MountNamespace: unix.CLONE_NEWNS, | ||
| specs.NetworkNamespace: unix.CLONE_NEWNET, | ||
| specs.PIDNamespace: unix.CLONE_NEWPID, | ||
| specs.TimeNamespace: unix.CLONE_NEWTIME, | ||
| specs.UserNamespace: unix.CLONE_NEWUSER, | ||
| specs.UTSNamespace: unix.CLONE_NEWUTS, | ||
| } | ||
|
|
||
| func ParseNamespaceFlags(namespaces []specs.LinuxNamespace) (uintptr, error) { | ||
| if namespaces == nil { | ||
| return 0, nil | ||
| } | ||
|
|
||
| var flags uintptr | ||
| for _, ns := range namespaces { | ||
| if ns.Path != "" { | ||
| continue | ||
| } | ||
| flag, ok := specNamespacesToUnixCloneFlags[ns.Type] | ||
| if !ok { | ||
| err := fmt.Errorf("unknown namespace type %q", ns.Type) | ||
| return 0, err | ||
| } | ||
| flags |= flag | ||
| } | ||
| return flags, nil | ||
| } | ||
|
|
||
| /* We mimic runc here - if not root, we ignore namespace isolation due to insufficient permissions | ||
| * https://github.com/opencontainers/runc/blob/a75076b4a413f628c4b6aa4c5568b159aa128a56/libcontainer/specconv/example.go */ | ||
| func LinuxCloneFlags(logger *slog.Logger, isRoot bool, namespaces []specs.LinuxNamespace) (uintptr, error) { | ||
| flags, err := ParseNamespaceFlags(namespaces) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
||
| if !isRoot && flags != 0 { | ||
|
Luke-Parkin marked this conversation as resolved.
|
||
| logger.Warn("running non-root; namespace isolation disabled") | ||
|
yejseo01 marked this conversation as resolved.
|
||
| return 0, nil | ||
| } | ||
|
|
||
| return flags, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package proxy_test | ||
|
muchzill4 marked this conversation as resolved.
|
||
|
|
||
| import ( | ||
| "io" | ||
| "log/slog" | ||
| "testing" | ||
|
|
||
| proxy "github.com/arm/remoteproc-runtime/internal/proxy" | ||
| "github.com/opencontainers/runtime-spec/specs-go" | ||
| "github.com/stretchr/testify/require" | ||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| func TestLinuxCloneFlags(t *testing.T) { | ||
| t.Run("converts known linux namespace flags to unix", func(t *testing.T) { | ||
| isRoot := true | ||
| namespaces := []specs.LinuxNamespace{ | ||
| {Type: specs.CgroupNamespace}, | ||
| {Type: specs.UserNamespace}, | ||
| } | ||
| logger := slog.New(slog.NewTextHandler(io.Discard, nil)) | ||
|
|
||
| got, err := proxy.LinuxCloneFlags(logger, isRoot, namespaces) | ||
|
|
||
| require.NoError(t, err) | ||
| want := uintptr(unix.CLONE_NEWCGROUP | unix.CLONE_NEWUSER) | ||
| require.Equal(t, want, got) | ||
| }) | ||
|
|
||
| t.Run("non-root disables cloning", func(t *testing.T) { | ||
| isRoot := false | ||
| namespaces := []specs.LinuxNamespace{ | ||
| {Type: specs.CgroupNamespace}, | ||
| {Type: specs.UserNamespace}, | ||
| } | ||
| logger := slog.New(slog.NewTextHandler(io.Discard, nil)) | ||
|
|
||
| got, err := proxy.LinuxCloneFlags(logger, isRoot, namespaces) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Equal(t, uintptr(0), got) | ||
| }) | ||
|
|
||
| t.Run("errors given unknown namespace", func(t *testing.T) { | ||
| isRoot := true | ||
| namespaces := []specs.LinuxNamespace{ | ||
| {Type: specs.LinuxNamespaceType("weird-name")}, | ||
| } | ||
| logger := slog.New(slog.NewTextHandler(io.Discard, nil)) | ||
|
|
||
| _, err := proxy.LinuxCloneFlags(logger, isRoot, namespaces) | ||
|
|
||
| require.Error(t, err) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.