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

set up user namespace in builder, not in parent #2717

Closed
wants to merge 1 commit into from

Conversation

catern
Copy link
Contributor

@catern catern commented Mar 10, 2019

This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less
pipe when starting the builder.

As a niche benefit, this also replaces our access to /proc/builder_pid
in the parent with an access to /proc/self in the builder. The former
access could fail if /proc was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such
a misconfiguration.

This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less
pipe when starting the builder.

As a niche benefit, this also replaces our access to /proc/builder_pid
in the parent with an access to /proc/self in the builder. The former
access could fail if /proc was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such
a misconfiguration.
@catern
Copy link
Contributor Author

catern commented Jul 2, 2019

@edolstra ping?

@stale
Copy link

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 13, 2021
@catern
Copy link
Contributor Author

catern commented Mar 9, 2021

I still care about this change (and if someone approves it, I'll rebase it - it should still apply fine)

@stale stale bot removed the stale label Mar 9, 2021
@stale
Copy link

stale bot commented Sep 10, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Sep 10, 2021
@catern
Copy link
Contributor Author

catern commented Sep 11, 2021

Still important to me

@stale stale bot removed the stale label Sep 11, 2021
@tomberek
Copy link
Contributor

Does this potentially allow the child to make additional changes to its own namespace? I'm not super familiar with the origin of this, but I'd like to understand and it looks like it is intentional.

@stale stale bot added the stale label Aug 12, 2022
@stale stale bot removed the stale label Jan 20, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-01-20-nix-team-meeting-minutes-25/25432/1

@Ericson2314
Copy link
Member

@catern Are you still interested in this?

I am assigned to get it shepherded over the finish line if so, or closed otherwise.

@catern
Copy link
Contributor Author

catern commented Feb 19, 2023

I regret to say that I'm no longer interested in this

@tomberek
Copy link
Contributor

I regret to say that I'm no longer interested in this

Can we ask for an explanation of the intent and intended benefit? As above, I’m not quite sure of what all the consequences would be.

@Ericson2314
Copy link
Member

Yeah @catern if it is "just what it says on the tin" that is fine, but if there was a sharable use-case separate from the technical details that it isn't too much effort to remember on your part that would be good to know.

I might take a look at rebasing this anyways :).

@catern
Copy link
Contributor Author

catern commented Feb 20, 2023

It's just what it says on the tin. I made this change after writing some container code which made a new pid namespace but didn't remount /proc (which is buggy behavior) and then running Nix inside it. This change made Nix work but also my container code was buggy in the first place.

There's no actual use case for this change, except that it slightly simplifies the code.

@Ericson2314
Copy link
Member

After like 10 rebases :) I have master...obsidiansystems:userns

@Ericson2314
Copy link
Member

@edolstra Do you know why you had the parent not child set the user namespace originally? As @tomberek says, this is a good case of "Chesterton's Fence" --- we should ask that question before undoing this.

(Also, In the meeting I recall you saying you thought you had done this since, but the rebase I linked above demonstrates this is not the case.)

I had done a git log -G userNamespaceSync which led me to c68e591, which says:

Run builds in a user namespace

This way, all builds appear to have a uid/gid of 0 inside the
chroot. In the future, this may allow using programs like
systemd-nspawn inside builds, but that will require assigning a larger
UID/GID map to the build.

Issue #625.

And neither that nor issue #625 seem to shed any light on this implementation detail.

@edolstra
Copy link
Member

I don't remember why it's done this way. Maybe the kernel required it at the time?

@Ericson2314
Copy link
Member

Thanks @edolstra. Yes I too vaguely recall user namespace used to be very finicky. That is also my best guess.

@fricklerhandwerk fricklerhandwerk added contributor-experience Developer experience for Nix contributors performance labels Mar 3, 2023
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Mar 10, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson3214's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Mar 10, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson3214's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
@Ericson2314
Copy link
Member

Rebased as #8023

Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Mar 16, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson3214's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Mar 16, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson2314's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Mar 20, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson2314's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Apr 15, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson2314's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request May 8, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson2314's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Ericson2314 pushed a commit to Ericson2314/nix that referenced this pull request Jun 21, 2023
This is a minor simplification; there's now slightly less handshaking
required between the builder and the parent, and we create one less pipe
when starting the builder.

As a niche benefit, this also replaces our access to `/proc/builder_pid`
in the parent with an access to `/proc/self` in the builder. The former
access could fail if `/proc` was mounted in a different pid namespace
from the one we are running in; now we will work even if there is such a
misconfiguration.

----

Rebaser's (@Ericson2314's) notes:

A good questions why it was ever done the old way, since this is simpler
and easier to write. The original commit doing this was
c68e591, adding user namespae support
for the first time, and referencing issue NixOS#625. But neither mention this
design decision.

In NixOS#2717 (comment) Eelco
said:

> I don't remember why it's done this way. Maybe the kernel required it
> at the time?

That seems to me like a likely explanation. User namespaces were
famously fiddly for many years.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor-experience Developer experience for Nix contributors performance
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants