Skip to content

fix(landjail): allow TCP bind under Landlock#210

Open
openmarmot wants to merge 1 commit into
coder:mainfrom
openmarmot:fix/landjail-bind-tcp
Open

fix(landjail): allow TCP bind under Landlock#210
openmarmot wants to merge 1 commit into
coder:mainfrom
openmarmot:fix/landjail-bind-tcp

Conversation

@openmarmot

Copy link
Copy Markdown

fix(landjail): allow TCP bind under Landlock

Problem

With --jail-type landjail, processes that listen on a local TCP port fail immediately (e.g. opencode webServeError / bind permission denied).

Landlock ABI V4 covers both bind_tcp and connect_tcp. Landjail used landlock.V4.RestrictNet(...) with only ConnectTCP(proxyPort) rules. Because bind was handled but never allowed, all binds were denied (EACCES), while connect to the proxy still worked.

Change

In landjail/child.go, restrict connect only:

  • Handled rights: AccessNetConnectTCP
  • Allowed: connect to the Boundary proxy port
  • Bind/listen: unrestricted (not handled by Landlock)

Egress remains proxy-only. Local servers inside the jail can bind normally.

Docs updated in docs/architecture.md.

How to test

make build

# 1) Bind was broken before; should succeed now
./boundary --jail-type landjail --proxy-port 18080 --allow "domain=*" -- \
  python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 4096)); print("BIND_OK")'

# 2) Direct egress still blocked
./boundary --jail-type landjail --proxy-port 18080 --allow "domain=*" -- \
  python3 -c 'import socket; s=socket.socket(); s.connect(("1.1.1.1", 443))'
# expect: PermissionError / errno 13

# 3) Real workload that needs a listen port
./boundary --jail-type landjail --proxy-port 18080 --allow "domain=*" -- \
  opencode web --port 4096
# expect: opencode web works

Landlock V4 handles both bind_tcp and connect_tcp. Restricting with
only connect rules denied all binds, breaking local servers like
opencode web. Handle connect only so egress stays proxy-only while
bind/listen remains unrestricted.
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