Some of the capabilities(7) which affect system wide resources, are ineffective
inside user namespaces. This restriction applies even to root user( uid 0)
from init namespace mapped into the user namespace. One such capability
is CAP_SYS_NICE which is required to change process priority. As a result of
which the root user cannot perform operations like increase a process priority
using -ve nice value or set RT priority on processes inside the user namespace.
A workaround to deal with this restriction is to use the help of a process /
daemon running outside the user namespace to change process priority, which is
a an inconvenience.
We could allow these restricted capabilities to take effect only for the root
user from init namespace mapped inside a user namespace and limit the effect
with use of cgroups. It would seem reasonable to deal with each of these
restricted capabilities on a case by case basis and address them. This patch
is concerning CAP_SYS_NICE capability. The proposal here is to selectively
allow CAP_SYS_NICE to take effect inside user namespace only for a root user
mapped from init name space.
Which user id gets to map the root user(uid 0) from init namespace inside its
user namespaces is authorized thru /etc/subuid & /etc/subgid entries. Only
system admin / root user on the system can add these entries.
Therefore any ordinary user cannot simply map the root user(uid 0) into
user namespaces created. Necessary cgroup bandwidth control can be used
to limit cpu usage for such user namespaces.
The capabilities(7) manpage lists all the operations / system calls that are
subject to CAP_SYS_NICE capability check. This patch currently allows
CAP_SYS_NICE to take effect inside a user namespace only for system calls
affecting process priority. For completeness sake should memory
operations(migrate_pages(2), move_pages(2), mbind(2)) mentioned in the
manpage, also be permitted? There are no cgroup controls to limit the effect
of these memory operations.
Looking for feedback on this approach.
Prakash Sangappa (1):
Selectively allow CAP_SYS_NICE capability inside user namespaces
kernel/sched/core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--
2.7.4
Allow CAP_SYS_NICE to take effect for processes having effective uid of a
root user from init namespace.
Signed-off-by: Prakash Sangappa <redacted>
---
kernel/sched/core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
On Mon, Nov 18, 2019 at 6:04 PM Prakash Sangappa
[off-list ref] wrote:
Allow CAP_SYS_NICE to take effect for processes having effective uid of a
root user from init namespace.
[...]
quoted hunk
@@ -4548,6 +4548,8 @@ int can_nice(const struct task_struct *p, const int nice) int nice_rlim = nice_to_rlimit(nice); return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||+ (ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE) &&+ uid_eq(current_euid(), GLOBAL_ROOT_UID)) || capable(CAP_SYS_NICE));
I very strongly dislike tying such a feature to GLOBAL_ROOT_UID.
Wouldn't it be better to control this through procfs, similar to
uid_map and gid_map? If you really need an escape hatch to become
privileged outside a user namespace, then I'd much prefer a file
"cap_map" that lets someone with appropriate capabilities in the outer
namespace write a bitmask of capabilities that should have effect
outside the container, or something like that. And limit that to bits
where that's sane, like CAP_SYS_NICE.
If we tie features like this to GLOBAL_ROOT_UID, more people are going
to run their containers with GLOBAL_ROOT_UID. Which is a terrible,
terrible idea. GLOBAL_ROOT_UID gives you privilege over all sorts of
files that you shouldn't be able to access, and only things like mount
namespaces and possibly LSMs prevent you from exercising that
privilege. GLOBAL_ROOT_UID should only ever be given to processes that
you trust completely.
On Mon, Nov 18, 2019 at 6:04 PM Prakash Sangappa
[off-list ref] wrote:
Some of the capabilities(7) which affect system wide resources, are ineffective
inside user namespaces. This restriction applies even to root user( uid 0)
from init namespace mapped into the user namespace. One such capability
is CAP_SYS_NICE which is required to change process priority. As a result of
which the root user cannot perform operations like increase a process priority
using -ve nice value or set RT priority on processes inside the user namespace.
A workaround to deal with this restriction is to use the help of a process /
daemon running outside the user namespace to change process priority, which is
a an inconvenience.
What is the goal here, in the big picture? Is your goal to allow
container admins to control the priorities of their tasks *relative to
each other*, or do you actually explicitly want container A to be able
to decide that its current workload is more timing-sensitive than
container B's?
On Mon, Nov 18, 2019 at 6:04 PM Prakash Sangappa
[off-list ref] wrote:
quoted
Some of the capabilities(7) which affect system wide resources, are ineffective
inside user namespaces. This restriction applies even to root user( uid 0)
from init namespace mapped into the user namespace. One such capability
is CAP_SYS_NICE which is required to change process priority. As a result of
which the root user cannot perform operations like increase a process priority
using -ve nice value or set RT priority on processes inside the user namespace.
A workaround to deal with this restriction is to use the help of a process /
daemon running outside the user namespace to change process priority, which is
a an inconvenience.
What is the goal here, in the big picture? Is your goal to allow
container admins to control the priorities of their tasks *relative to
each other*, or do you actually explicitly want container A to be able
to decide that its current workload is more timing-sensitive than
container B's?
It is more the latter. Admin should be able to explicitly decide that container A
workload is to be given priority over other containers.
On Mon, Nov 18, 2019 at 6:04 PM Prakash Sangappa
[off-list ref] wrote:
quoted
Allow CAP_SYS_NICE to take effect for processes having effective uid of a
root user from init namespace.
[...]
quoted
@@ -4548,6 +4548,8 @@ int can_nice(const struct task_struct *p, const int nice) int nice_rlim = nice_to_rlimit(nice); return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||+ (ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE) &&+ uid_eq(current_euid(), GLOBAL_ROOT_UID)) || capable(CAP_SYS_NICE));
I very strongly dislike tying such a feature to GLOBAL_ROOT_UID.
Wouldn't it be better to control this through procfs, similar to
uid_map and gid_map? If you really need an escape hatch to become
privileged outside a user namespace, then I'd much prefer a file
"cap_map" that lets someone with appropriate capabilities in the outer
namespace write a bitmask of capabilities that should have effect
outside the container, or something like that. And limit that to bits
where that's sane, like CAP_SYS_NICE.
Sounds reasonable. Adding a 'cap_map' file to user namespace, would give more control. We could allow the capability in 'cap_map' to take effect only if corresponding capability is enabled for the user inside the user namespace Ex uid 0. Start with support for CAP_SYS_NICE?
If we tie features like this to GLOBAL_ROOT_UID, more people are going
to run their containers with GLOBAL_ROOT_UID. Which is a terrible,
terrible idea. GLOBAL_ROOT_UID gives you privilege over all sorts of
files that you shouldn't be able to access, and only things like mount
namespaces and possibly LSMs prevent you from exercising that
privilege. GLOBAL_ROOT_UID should only ever be given to processes that
you trust completely.
From: Enrico Weigelt, metux IT consult <hidden> Date: 2019-11-21 18:34:28
On 18.11.19 21:34, Prakash Sangappa wrote:
It is more the latter. Admin should be able to explicitly decide that
container A
workload is to be given priority over other containers.
I guess, you're talking about the host's admin, correct ?
Shouldn't this already be possibly by tweaking the container's cgroups ?
--mtx
--
Dringender Hinweis: aufgrund existenzieller Bedrohung durch "Emotet"
sollten Sie *niemals* MS-Office-Dokumente via E-Mail annehmen/öffenen,
selbst wenn diese von vermeintlich vertrauenswürdigen Absendern zu
stammen scheinen. Andernfalls droht Totalschaden.
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
info@metux.net -- +49-151-27565287
On 11/21/19 10:33 AM, Enrico Weigelt, metux IT consult wrote:
On 18.11.19 21:34, Prakash Sangappa wrote:
quoted
It is more the latter. Admin should be able to explicitly decide that container A
workload is to be given priority over other containers.
I guess, you're talking about the host's admin, correct ?
Yes, Specifically host's admin decides which container gets the privilege to increase priority of processes inside that container.
Shouldn't this already be possibly by tweaking the container's cgroups ?
Don't think so. The use case is that admin/user inside the container needs to be able to increase the priority of some the critical processes running in the container.