golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.09k stars 17.68k forks source link

syscall: add Jail int32 to SysProcAttr on FreeBSD #46259

Closed gizahNL closed 1 year ago

gizahNL commented 3 years ago

Adding an int32 jail param to SysProcAttr on FreeBSD and calling the JAIL_ATTACH syscall inside the forked child would allow cleanly running a command inside a FreeBSD jail.

rsc commented 3 years ago

This proposal has been added to the active column of the proposals project and will now be reviewed at the weekly proposal review meetings. — rsc for the proposal review group

rsc commented 3 years ago

Does anyone object to this?

gizahNL commented 3 years ago

An implementation detail I did not think about before: jail attach chroots into the jail, and changes the working directory of the program to the root of the jail. If it's feasible to change the working directory in the forked child it must be done after calling the attach syscall, if it's unfeasible I guess an error could be returned when both Cmd.Dir and SysProcAttr.Jail is set as to indicate that such a combination of options is unsupported.

ianlancetaylor commented 3 years ago

@gizahNL That doesn't seem like a problem. The relevant code is in syscall/exec_bsd.go.

rsc commented 3 years ago

/cc @samuelkarp to see if this would have helped https://github.com/samuelkarp/runj.

rsc commented 3 years ago

Based on the discussion above, this proposal seems like a likely accept. — rsc for the proposal review group

samuelkarp commented 3 years ago

/cc @samuelkarp to see if this would have helped samuelkarp/runj.

Yes, this will likely help runj in some scenarios, while runj will likely invoke JAIL_ATTACH directly in others.

rsc commented 3 years ago

No change in consensus, so accepted. 🎉 This issue now tracks the work of implementing the proposal. — rsc for the proposal review group

gopherbot commented 3 years ago

Change https://golang.org/cl/355569 mentions this issue: syscall: separate ProcSysAttr and forkAndExecInChild for FreeBSD

gopherbot commented 1 year ago

Change https://go.dev/cl/458335 mentions this issue: syscall: add jail support to ForkExec on FreeBSD

gopherbot commented 1 year ago

Change https://go.dev/cl/498376 mentions this issue: doc/go1.21: mention syscall package changes