Skip to content

Add support for setting sysctls - #16632

Closed
rhatdan wants to merge 1 commit into
moby:masterfrom
rhatdan:netsysctl
Closed

rhatdan wants to merge 1 commit into
moby:masterfrom
rhatdan:netsysctl

Conversation

@rhatdan

@rhatdan rhatdan commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

This patch will allow users to specify namespace specific "kernel parameters"
for running inside of a container.

Dan Walsh [email protected]

Signed-off-by: Dan Walsh [email protected]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two things. This test doesn't compile, and seems it should be net.ipv4.ip_forward=1

@LK4D4

LK4D4 commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

design ok for me
ping @docker/core-maintainers

Comment thread daemon/config_unix.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This field in the daemon configuration is not necessary, is it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No removed. Patch built off of Ulimits patch and don't think we need options for the daemon. Left this by mistake.

@rhatdan

rhatdan commented Sep 28, 2015

Copy link
Copy Markdown
Contributor Author

Tests should be fixed.

@rhatdan

rhatdan commented Sep 28, 2015

Copy link
Copy Markdown
Contributor Author

net.ipv4.ip_forward=1 makes more sense but the other form worked also.

@LK4D4

LK4D4 commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

@rhatdan Yup, you're right. It's bug though.

Comment thread runconfig/hostconfig.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be strongly typed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This I would still prefer to see at least as a map[string]string rather than splitting on = to hand off to the exec driver.
Thoughts from anyone else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have no problem changing it to this, if others agree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 to making this a map.

@cpuguy83

Copy link
Copy Markdown
Member

Is there a list somewhere of namespaced sysctl's?

@mrunalp

mrunalp commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

@cpuguy83

Copy link
Copy Markdown
Member

@mrunalp Cool, thanks!
Ideally docker should throw an error on an invalid opt before it tries to start the container.

@mrunalp

mrunalp commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

@cpuguy83 Yeah, we could expose a list of valid sysctls via a utility function that could be used both here and in runc/libcontainer.

@LK4D4

LK4D4 commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

@mrunalp Also, I think that sysctls with / shouldn't be accepted :)

@rhatdan

rhatdan commented Sep 29, 2015

Copy link
Copy Markdown
Contributor Author

Once we have a libcontainer function for docker to call to verify the validity of the syscall, I will add it to this code. One problem with the validation, is that the list is likely to change depending on the kernel you are using. We could end up blocking valid sysctl's, and eventually allowing some that will not work on the kernel. Most cases the kernel will probably reject the sysctl.

@rhatdan

rhatdan commented Sep 29, 2015

Copy link
Copy Markdown
Contributor Author

@jeremyeder do syscalls take anything other then integers? Do they ever take strings?

@rhatdan

rhatdan commented Sep 29, 2015

Copy link
Copy Markdown
Contributor Author

@cpuguy83 Seems like sysctl can pass strings. So not sure we can strongly type the values. But we can check if the syscall is supported.

man sysctl
...
       variable=value
              To  set a key, use the form variable=value where variable is the
              key and value is the value to set it to.  If the value  contains
              quotes or characters which are parsed by the shell, you may need
              to enclose the value in double quotes.   This  requires  the  -w
              parameter to use.

@jeremyeder

Copy link
Copy Markdown

oh yes they take strings. for example modify kernel.core_pattern in RHEL.

@mrunalp

mrunalp commented Sep 29, 2015

Copy link
Copy Markdown
Contributor

@cpuguy83 IMO, having a string to string hash makes the most sense. If there is an invalid value, then we get back invalid argument error trying to write it under /proc/sys

@cpuguy83

cpuguy83 commented Oct 1, 2015

Copy link
Copy Markdown
Member

This makes sense.

@rhatdan

rhatdan commented Oct 1, 2015

Copy link
Copy Markdown
Contributor Author

@cpuguy83 @mrunalp @LK4D4 PTAL

Now just passes around the map[string]string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use dockrCmd here?

@rhatdan

rhatdan commented Oct 15, 2015

Copy link
Copy Markdown
Contributor Author

#4717 has other examples.

@cpuguy83

Copy link
Copy Markdown
Member

See #4717

@rhatdan

rhatdan commented Oct 15, 2015

Copy link
Copy Markdown
Contributor Author

We have another customer requesting
All IPC related settings:

  •    msgmni
    
  •    msgmnb
    
  •    msgmax
    
  •    shmmni
    
  •    shmmax
    
  •    shmall
    

File descriptor settings, both via ulimit settings and fs.file-max parameter.

Network parameters as well, at least:

net.ipv4.tcp_rmem
net.ipv4.tcp_wmem

@pmoust

pmoust commented Oct 26, 2015

Copy link
Copy Markdown

We also need shmmax / shmall.
Needs rebase

@rhatdan

rhatdan commented Oct 26, 2015

Copy link
Copy Markdown
Contributor Author

@crosbymichael Any word on this?

This patch will allow users to specify namespace specific "kernel parameters"
for running inside of a container.

Dan Walsh <[email protected]>

Signed-off-by: Dan Walsh <[email protected]>
@crosbymichael

Copy link
Copy Markdown
Contributor

I'm -1 on this. There is currently too much room for user error to mess things up. If you know what settings to make on these then you can exec into your container and set them yourself.

@cpuguy83

cpuguy83 commented Nov 9, 2015

Copy link
Copy Markdown
Member

That's true, now that we have --privileged on exec especially.

@mrunalp

mrunalp commented Nov 9, 2015

Copy link
Copy Markdown
Contributor

Using exec is racy though as the container process could fail due to not having the right ipc sysctls set for e.g. before the exec is even called.

@rhatdan

rhatdan commented Nov 9, 2015

Copy link
Copy Markdown
Contributor Author

So is there no road forward on this? There is potential race conditions, where you could not get in, on time to set the sysctl, if pid 1 needed the access.

@rhatdan

rhatdan commented Nov 9, 2015

Copy link
Copy Markdown
Contributor Author

Seems to lots of ways for users to screw up their system, if they do not know what they are doing. Not sure why I would block just this way.

@thaJeztah thaJeztah added the status/needs-attention Calls for a collective discussion during a review session label Nov 10, 2015
@calavera

Copy link
Copy Markdown
Contributor

I think there is a general agreement that this is potentially dangerous for users. It looks like other maintainers also agree with that feeling. Sorry, but I'm going to close this PR and we won't move it forward.

@calavera calavera closed this Nov 11, 2015
@rhatdan

rhatdan commented Jan 5, 2016

Copy link
Copy Markdown
Contributor Author

We are hearing a lot from customers about the need for this. If we add validation would the pull request be reconsidered? @calavera @crosbymichael

Reopen opencontainers/runc#303 for runc and then add validation on the cli side also.

@mrunalp

mrunalp commented Jan 5, 2016

Copy link
Copy Markdown
Contributor

I think opencontainers/runc#303 is a good list and should open up setting many sysctls that are useful in a container.

@gordillo-ramon

Copy link
Copy Markdown

Hi. This is one customer that thinks that this is an absolutely needed feature. Otherwise, some technologies like redis are at risk of DoS when running in a container.

@jessfraz

Copy link
Copy Markdown
Contributor

I still believe this is going to be a cause for user confusion when they realize sysctls are not namespaced

@mrunalp

mrunalp commented Jan 12, 2016

Copy link
Copy Markdown
Contributor

@jfrazelle We are proposing that there be a whitelist like in the runc PR and then we can return a nice error message to the user when they try to set something that isn't namespaced. A lot of container applications need to tune the network sysctls (which are namespaced) and not allowing this feature is an adherent to containerizing such applications.

@jessfraz

Copy link
Copy Markdown
Contributor

ok that seems more reasonable :)

On Mon, Jan 11, 2016 at 4:45 PM, Mrunal Patel [email protected]
wrote:

@jfrazelle https://github.com/jfrazelle We are proposing that there be
a whitelist like in the runc PR and then we can return a nice error message
to the user when they try to set something that isn't namespaces. A lot of
container applications need to tune the network sysctls (which are
namespaced) and not allowing this feature is an adherent to containerizing
such applications.

—
Reply to this email directly or view it on GitHub
#16632 (comment).

@rhatdan

rhatdan commented Jan 12, 2016

Copy link
Copy Markdown
Contributor Author

Right we can document the sysctls that are currently available and then expand the list as the kernel evolves. Can we get this pull request reopened, or should I open a new one?

@thaJeztah

Copy link
Copy Markdown
Member

@rhatdan looks like the branch was updated/force-pushed while it was closed, so GitHub doesn't allow me to reopen the PR

@rhatdan

rhatdan commented Jan 12, 2016

Copy link
Copy Markdown
Contributor Author

Ok I will open a new pull request

@mnp

mnp commented Jul 15, 2016

Copy link
Copy Markdown

Is there an issue to support the fs.* tree as well? At least obvious things like fs.file-max and fs.nr_open? It doesn't look like those are in the 7dff8cc merge. Thanks.

@cpuguy83

Copy link
Copy Markdown
Member

@mnp If you test these out and find that they are namespaced (which I doubt they are, but maybe), then you can create an issue.
If they are not namespaced, we cannot support them.

@mnp

mnp commented Jul 19, 2016

Copy link
Copy Markdown

@cpuguy83 Yes, by testing only, it does not seem that fs.* are namespaced in our 3.10 centos kernel at least. Containers inherit the host settings. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.