-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
nsexec: replace usage of environment variable with netlink message #340
Conversation
ping @crosbymichael @LK4D4 @avagin for review |
👍 to taking out runc from the names. |
46eaf29
to
9c45132
Compare
native := nl.NativeEndian() | ||
native.PutUint16(buf[0:2], uint16(msg.Len())) | ||
native.PutUint16(buf[2:4], msg.Type) | ||
native.PutUint32(buf[4:8], msg.Value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we can't do something like this https://github.com/vishvananda/netlink/blob/master/nl/tc_linux.go#L99 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we should do that. It depends on an undocumented feature of the runtime i.e the struct fields' memory layout is in order (golang/go#10014). Doing this is much safer and future-proof imo.
add bootstrap data to setns process. If we have any bootstrap data then copy it to the bootstrap process (i.e. nsexec) using the sync pipe. This will allow us to eventually replace environment variable usage with more structured data to setup namespaces, write pid/gid map, setgroup etc. Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
9c45132
to
b4c14ba
Compare
b4c14ba
to
c416a8d
Compare
c416a8d
to
5bc6526
Compare
len = NLMSG_PAYLOAD(nh, 0); | ||
char data[len]; | ||
len = read(pipenum, data, len); | ||
if (len <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to check that we get all data here
LGTM. Thanks! |
@mrunalp @crosbymichael @LK4D4 PTAL :D |
@@ -1021,3 +1025,75 @@ func (c *linuxContainer) currentState() (*State, error) { | |||
} | |||
return state, nil | |||
} | |||
|
|||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this message code outside of this file and into maybe a message.go
file? This file is already pretty large.
Nevermind the last comment. I see that it got removed in a later commit. |
d46e0ca
to
d7fcd15
Compare
d7fcd15
to
7f7dff4
Compare
@crosbymichael @mrunalp moved the messages to message_linux.go and rebased. |
replace passing of pid and console path via environment variable with passing them with netlink message via an established pipe. this change requires us to set _LIBCONTAINER_INITTYPE and _LIBCONTAINER_INITPIPE as the env environment of the bootstrap process as we only send the bootstrap data for setns process right now. When init and setns bootstrap process are unified (i.e., init use nsexec instead of Go to clone new process), we can remove _LIBCONTAINER_INITTYPE. Note: - we read nlmsghdr first before reading the content so we can get the total length of the payload and allocate buffer properly instead of allocating one large buffer. - check read bytes vs the wanted number. It's an error if we failed to read the desired number of bytes from the pipe into the buffer. Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
7f7dff4
to
7d423cb
Compare
LGTM |
1 similar comment
LGTM |
nsexec: replace usage of environment variable with netlink message
add omitempty to 'Devices
To match the omitempty which the Go property has had since 28cc423 (add omitempty to 'Device' and 'Namespace', 2016-03-10, opencontainers#340). Signed-off-by: W. Trevor King <wking@tremily.us>
replace passing of pid and console path via environment variable with passing them with netlink message via an established pipe.
This is the first step in the process to unify the setup process between init and setns. We can use the netlink message to pass more structured data into the nsexec bootstrap process to eventually setup custom namespaces, setgroup, uid/gid map etc.