Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Issues with openssh ebuild restarting sshd inside chroot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
kloepfer
n00b
n00b


Joined: 01 Feb 2025
Posts: 3

PostPosted: Sat Feb 01, 2025 10:48 pm    Post subject: Issues with openssh ebuild restarting sshd inside chroot Reply with quote

Background: On my server system, I created several chroot'd areas that I use to build Gentoo packages for other systems I maintain that use different make.conf parameters (yes, I share my distfiles cache to lessen the load on the upstream servers).

Issue: Because the net-misc/openssh ebuild now restarts openssh through rc-service, rc-service sees sshd outside the chroot environment, kills sshd in the server environment, and starts the sshd inside the chroot build environment. I understand the reason for doing this (Gentoo bug 709748), but the method in the ebuild has caused unintended consequences for me. I am also concerned about this being done in other ebuilds in the future (currently this only happens automatically for openssh).

Discussion: Right now, I handle this by stopping sshd on the server before updating the build inside the chroot environment. Looking at the ebuild, it looks like setting ROOT to "/" in my chroot build environment may resolve this, but I was wondering if anyone could suggest a better solution for hiding the process list from rc-service inside that chroot area to prevent this from being a problem in the future.

I considered reporting this as a bug (is the bug openssh or openrc?), but I wanted to throw this out to the forum before I approached it from that direction.

I realize that my build process could be done differently by treating the other build environments like a cross-compile, and setting ROOT to those areas, but I don't like this approach because a mistake could easily damage the server environment, and I also have a nice workflow doing this with chroot and some scripts. My other thought would be to create lxc containers rather than chroot environments, but that's a lot more complicated to maintain and comes with its own set of challenges.

Thanks in advance for any feedback on this.

[Administrator edit: fixed [bug] tag. When the target is the tag's text, the tag should not use =. -Hu]
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1487
Location: Richmond Hill, Canada

PostPosted: Sat Feb 01, 2025 11:08 pm    Post subject: Reply with quote

Welcome to Gentoo

So, what is you want to discuss? change openssh ebuild behavior?
Or prevent chroot environment kill openssh outside?
Found a way to work the chroot from remote?

I don't see how it is a bug, It is design by Gentoo openssh maintainer. it just does not work your way. Doing chroot then world rebuild I would think it is not common, therefor it does not fall in to openssh ebuild covered use case.

Have you consider setup your chroot with unshare --pid, so the process namespace is separated from outside?
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3497

PostPosted: Sun Feb 02, 2025 12:22 am    Post subject: Reply with quote

Quote:
rc-service sees sshd outside the chroot environment, kills sshd in the server environment, and starts the sshd inside the chroot build environment

Quote:
I don't see how it is a bug

I do. And since installation by Gentoo Manual happens largely in chroot (and since chroot isolates build host from build target on a binhost), I disagree that rebuilding things inside a chroot is a weird use case, even if it's relatively rare.


Now, openrc terminates services using their PIDs rather than names. Invoked inside chroot it should not do anything at all about ssh started on the host.
The question is: Is it a bug, or did kloepfer screw up preparations?
So, kloepfer, what filesystems from the host do you mount --bind inside your chroots?
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
kloepfer
n00b
n00b


Joined: 01 Feb 2025
Posts: 3

PostPosted: Sun Feb 02, 2025 3:31 am    Post subject: Reply with quote

szatox wrote:
since installation by Gentoo Manual happens largely in chroot (and since chroot isolates build host from build target on a binhost), I disagree that rebuilding things inside a chroot is a weird use case, even if it's relatively rare.

This is pretty much what I'm doing - essentially, I maintain a build environment for slower systems and pre-build packages with a specific set of USE flags and make.conf parameters that would not be appropriate for the server. I would agree with pingtoo that it may not be the typical use case, but I suspect that there are probably a lot more people doing this than just me.
szatox wrote:
Now, openrc terminates services using their PIDs rather than names. Invoked inside chroot it should not do anything at all about ssh started on the host.
The question is: Is it a bug, or did kloepfer screw up preparations?
So, kloepfer, what filesystems from the host do you mount --bind inside your chroots?

/proc, /sys, /dev are rbind-mounted, and /run is mounted as bind. After reading your comment, I believe /run is why I am having issues. I thought that rc-service was using /proc (via ps) to figure out what was running, but it's almost certainly using /run/openrc/started to determine this.

I will go ahead and see whether having a dummy (empty) /run in the chroot build area causes any problems and keeps rc-service from affecting the server. If that works, then it is the correct fix.

Thank you for the quick response, and I will report back here after making sure this doesn't have any adverse effects.
Back to top
View user's profile Send private message
kloepfer
n00b
n00b


Joined: 01 Feb 2025
Posts: 3

PostPosted: Sun Feb 02, 2025 3:54 am    Post subject: Reply with quote

kloepfer wrote:
I will go ahead and see whether having a dummy (empty) /run in the chroot build area causes any problems and keeps rc-service from affecting the server. If that works, then it is the correct fix.

:oops: This is exactly the fix, and I'm surprised that I haven't had any issues prior to this. Thank you for the suggestion to look at the bind mounts. I think I originally did things this way because I assumed that some ebuild would want to see portions of the system's active state in order to function, but in retrospect that was probably a bad assumption.

What I decided to do is replace the bind mount for /run with a tmpfs mount in the chroot area, so anything that inadvertently gets created there just goes away when the build environment is shut down. I use the same options in the chroot build area that is used for the running server:
Code:
mount -t tmpfs -o nosuid,nodev,relatime,mode=755,inode64 dummy `pwd`/run

The original behavior of umount'ing the build area's /run when the script terminates will still apply, and anything done in the build area with respect to /run will be removed.

I am glad I asked here first rather than report this as a bug. It was definitely my problem.

-- Gil Kloepfer
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1487
Location: Richmond Hill, Canada

PostPosted: Sun Feb 02, 2025 4:45 am    Post subject: Reply with quote

That is the reason I ask about namespace and/or use unshare.

because most of us it is not intuitively (common sense) think bind mount what does it mean what is doing for our host environment.

I know originally the chroot concept was do bind mound proc, sys and dev than it progress to everything else. but that was done without thinking. I am pretty sure it was learn that just bind mind is not right, then it develop to use make-salve and realize it is still not right so it come up with arch-chroot.

All in all is you must understand chroot, is not isolation. it just simply for the "session" the use call chroot, It is complete different mean for then entire host.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3497

PostPosted: Sun Feb 02, 2025 4:08 pm    Post subject: Reply with quote

Yeah, I though sharing /run would have explained this abnormal behavior. I'm glad the hint worked and you figured it out.

You don't have to fully replicate your host's mounts inside your chroot, you only need to provide things which are necessary for the task at hand. My "maintenance set" of mountpoints is /proc /sys /dev /dev/pts. It is enough for running an administrator's interactive session and it keeps emerge from complaining... And since those are kernel interfaces, it doesn't matter whether thay are mounted with --bind or not.
Anyway, adding anything to a chroot should always be a deliberate decision, since it essentially makes cracks in the wall, and when you have a crack, things might leak.
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum