Skip to content

runsc: add --restrict-bind-to-loopback flag#13611

Open
sfc-gh-mkeralapura wants to merge 1 commit into
google:masterfrom
sfc-gh-mkeralapura:restrict-bind-to-loopback
Open

runsc: add --restrict-bind-to-loopback flag#13611
sfc-gh-mkeralapura wants to merge 1 commit into
google:masterfrom
sfc-gh-mkeralapura:restrict-bind-to-loopback

Conversation

@sfc-gh-mkeralapura

@sfc-gh-mkeralapura sfc-gh-mkeralapura commented Jul 2, 2026

Copy link
Copy Markdown

Sandboxed workloads often have no legitimate reason to accept connections on external network interfaces, yet nothing prevents them from calling bind(2) with INADDR_ANY. This flag enforces the principle of least privilege at the kernel level: a process that should only be reachable on loopback cannot accidentally expose itself on a routable interface, even if it attempts to.

It is particularly useful in environments where a sidecar proxy (rather than the application itself) owns the external-facing port and the application should be invisible outside the sandbox.

When enabled, bind(2) returns EACCES for any address that is not a loopback address, including INADDR_ANY (0.0.0.0) and IN6ADDR_ANY (::). Loopback classification is delegated to net.IP.IsLoopback() from the Go standard library. AF_UNIX and other address families are unaffected.

Thread safety: RestrictBindToLoopback is written once during sandbox boot (loader.go:New) before any task goroutines are created, and is read-only thereafter — the same pattern used by AllowSUID and IOUringEnabled.

The flag is only meaningful with sandbox networking (--network=sandbox). With host networking the sentry syscall handlers are not invoked for socket calls, so the check is a no-op.

Tests:

  • runsc/config: TestRestrictBindToLoopback verifies flag round-trips
    through RegisterFlags/NewFromFlags/ToFlags.
  • test/syscalls/linux/restrict_bind_loopback_test: eight cases covering
    IPv4 INADDR_ANY (rejected), non-loopback unicast (rejected),
    127.0.0.1 / 127.x.x.x (allowed), IPv6 IN6ADDR_ANY (rejected), ::1
    (allowed), ::ffff:127.0.0.1 (allowed), and ::ffff:0.0.0.0 (rejected).
    Tests skip automatically when the flag is not active, so they are safe
    to run on plain Linux or gVisor without the flag.

Assisted-by: Claude Sonnet 4.6

@google-cla

google-cla Bot commented Jul 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@sfc-gh-mkeralapura sfc-gh-mkeralapura force-pushed the restrict-bind-to-loopback branch from 177ec9e to 3b5a22a Compare July 2, 2026 22:09
When enabled, bind(2) returns EACCES for any address that is not a
loopback address, including INADDR_ANY (0.0.0.0) and IN6ADDR_ANY (::).
Loopback classification is delegated to net.IP.IsLoopback() from the
Go standard library. AF_UNIX and other address families are unaffected.

Thread safety: RestrictBindToLoopback is written once during sandbox
boot (loader.go:New) before any task goroutines are created, and is
read-only thereafter — the same pattern used by AllowSUID and
IOUringEnabled.

The flag is only meaningful with sandbox networking (--network=sandbox).
With host networking the sentry syscall handlers are not invoked for
socket calls, so the check is a no-op.

Tests:
- runsc/config: TestRestrictBindToLoopback verifies flag round-trips
  through RegisterFlags/NewFromFlags/ToFlags.
- test/syscalls/linux/restrict_bind_loopback_test: eight cases covering
  IPv4 INADDR_ANY (rejected), non-loopback unicast (rejected),
  127.0.0.1 / 127.x.x.x (allowed), IPv6 IN6ADDR_ANY (rejected), ::1
  (allowed), ::ffff:127.0.0.1 (allowed), and ::ffff:0.0.0.0 (rejected).
  Tests skip automatically when the flag is not active, so they are safe
  to run on plain Linux or gVisor without the flag.

Assisted-by: Claude Sonnet 4.6
@sfc-gh-mkeralapura sfc-gh-mkeralapura force-pushed the restrict-bind-to-loopback branch from 3b5a22a to 3d4d9e7 Compare July 2, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant