Skip to content
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

Merged
merged 2 commits into from
Dec 9, 2015

Conversation

dqminh
Copy link
Contributor

@dqminh dqminh commented Oct 18, 2015

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.

@dqminh
Copy link
Contributor Author

dqminh commented Oct 18, 2015

ping @crosbymichael @LK4D4 @avagin for review

@mrunalp
Copy link
Contributor

mrunalp commented Oct 19, 2015

👍 to taking out runc from the names.

@dqminh dqminh force-pushed the replace-env-netlink branch from 46eaf29 to 9c45132 Compare October 20, 2015 00:20
@dqminh
Copy link
Contributor Author

dqminh commented Oct 20, 2015

@avagin @hqhq @mrunalp updated.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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>
len = NLMSG_PAYLOAD(nh, 0);
char data[len];
len = read(pipenum, data, len);
if (len <= 0) {
Copy link
Contributor

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

@avagin
Copy link
Contributor

avagin commented Nov 23, 2015

LGTM. Thanks!

@dqminh
Copy link
Contributor Author

dqminh commented Nov 24, 2015

@mrunalp @crosbymichael @LK4D4 PTAL :D

@@ -1021,3 +1025,75 @@ func (c *linuxContainer) currentState() (*State, error) {
}
return state, nil
}

const (
Copy link
Member

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.

@mrunalp
Copy link
Contributor

mrunalp commented Nov 24, 2015

Nevermind the last comment. I see that it got removed in a later commit.

@dqminh
Copy link
Contributor Author

dqminh commented Nov 26, 2015

@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>
@crosbymichael
Copy link
Member

LGTM

1 similar comment
@mrunalp
Copy link
Contributor

mrunalp commented Dec 9, 2015

LGTM

mrunalp pushed a commit that referenced this pull request Dec 9, 2015
nsexec: replace usage of environment variable with netlink message
@mrunalp mrunalp merged commit 0267ad0 into opencontainers:master Dec 9, 2015
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants