Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Chroot in OpenSSH

Posted by ScuttleMonkey on Wednesday February 20, @01:48PM
from the making-life-easier-always-my-goal dept.
bsdphx writes "OpenSSH developers Damien Miller and Markus Friedl have recently added a nifty feature to make life easier for admins. Now you can easily lock an SSH session into a chroot directory, restrict them to a built-in sftp server and apply these settings per user. And it's dead simple to do. If you need to allow semi-trusted people on your computers, then you want this bad!"

Related Stories

[+] When Not to Use chroot 407 comments
Hyena writes "Linux guru Alan Cox is quoted as saying 'chroot is not and never has been a security tool' in a KernelTrap article summarizing a lengthy thread on the Linux Kernel mailing list. The discussion began with a patch attempting to 'fix a security hole' in the Unix chroot command, trying to improve the ability of chroot to contain a process. When it was pointed out that people have been using chroot as a security tool for years, another kernel hacker retorted, 'incompetent people implementing security solutions are a real problem.' A quick search on the terms 'chroot+security' quickly reveals that many people have long thought (wrongly) that chroot's purpose was for improving security."
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.

Chroot in OpenSSH 25 Comments More | Login | Reply /

 Full
 Abbreviated
 Hidden
More | Login | Reply
Keybindings Beta
Q W E
A S D
Loading ... Please wait.
  • Why bother? (Score:3, Insightful)

    by whoever57 (658626) on Wednesday February 20, @01:53PM (#22491700) Journal
    Didn't we just read that chroot "jails" are not secure?
    • Re:Why bother? (Score:4, Interesting)

      by Wesley Felter (138342) <wesley@felter.org> on Wednesday February 20, @02:02PM (#22491884) Homepage

      Didn't we just read that chroot "jails" are not secure?
      I've read those arguments and find them confusing. Sure, root can break out of a chroot, but what about non-root users?
      • Re: (Score:2)

        I don't really know anything about chroot security either, but the first thing that occurs to me is that there's way too much code running/setuid'd as root or in kernel/driver space to just change the filesystem interface and expect that to be secure. Yo
    • Re:Why bother? (Score:5, Informative)

      by illegibledotorg (1123239) on Wednesday February 20, @02:06PM (#22491946)
      Giving someone a shell and putting them in a chroot crafted to look and function like a full system is one thing.

      Giving someone an SFTP session and chrooting them into a subdirectory is another thing.

      The feature added in this commit was arguably intended for the latter purpose given the additional changes to the SFTP subsystem that were included. There are countless tutorials and patches and scripts that are available to achieve chrooted SFTP-only access, but now it's been implemented in the core of OpenSSH. In my eyes, this solution is not only a "cleaner" solution to the problem, but it's probably more secure too.
    • Re:Why bother? (Score:5, Informative)

      by jandrese (485) <kensama@vt.edu> on Wednesday February 20, @02:07PM (#22491960) Homepage Journal
      They are probably better than giving semi-trusted users full filesystem access, even if they aren't perfect security. It's not even that chroot is inherently broken, it's just that people were using it incorrectly (setting it suid or letting the user become root inside of their jail). Most of the complaints seem to be "the user managed to get root and broke out of the jail", which is a problem with whatever allowed your user to become root in the first place, not the jail itself.

      Basically, to break out of a chroot you need to be root. If you're root, then you've already defeated the security on the box anyway. Don't let untrusted users become root.
        • I'd like to hear more about methods of breaking out of a chroot jail without becoming root during the process.
          • Re: (Score:3, Informative)

            Yeah, every method I've seen starts with:

            Step 1: Become root

            Once you are root, there are dozens of ways to break out of a jail (all the way from modifying kernel memory structures directly to rewriting inodes to installing a kernel module that grants
          • Re:Tell us more. (Score:5, Informative)

            by sjames (1099) on Wednesday February 20, @09:08PM (#22497530) Homepage

            In the right circumstances, 2 non-root users can conspire to break out of jail if one is chrooted below the other.

            Let's say A is chrooted to /home/sorta-trusted and B to /home/sorta-trusted/not-so-much.

            A diropens his / and creates a unix socket in /not-so-much. B opens the socket in his /. Now, A passes his fd to his / to B. B then does fdchdir on the fd and he's out of jail. Now B can break A out.

            The moral is, never use nested chroot jails!

              • Re: (Score:3, Informative)

                It's far worse, at least in the Linux kernel (and quite probably other Unix as well but I haven't studied them). The linux kernel assumes that the PWD is at or below the chroot. When a system call parses a pathname, it substitutes the chroot for a leading

    • Re:Why bother? (Score:5, Informative)

      by parcel (145162) on Wednesday February 20, @02:19PM (#22492130)

      Didn't we just read that chroot "jails" are not secure?
      You may want to take a look at http://www.openbsd.org/faq/faq10.html#httpdchroot [openbsd.org], especially the section titled "Should I use the chroot feature?".

      I imagine something similar would be forthcoming regarding OpenSSH specifically.
    • Re:Why bother? (Score:4, Informative)

      by jjohnson (62583) on Wednesday February 20, @02:21PM (#22492178)
      They're not secure for root users. That was the issue identified in the recent "read" you mention--someone was pointing out that root can break out in a particular way, and the kernel devs responded that 1) that was by design, and 2) locking that down left an infinite number of other ways to break out if you're root.

      For regular user accounts, a properly configured chroot jail is still a very useful security tool.
    • Re: (Score:2)

      Didn't we just read that chroot "jails" are not secure?

      Only when you have full shell access. This patch is just about confining sftp file transfers via chroot(2) for some users without the burden of setting up a full chrooted environment. Sounds really s

    • by caseih (160668) on Wednesday February 20, @02:58PM (#22492632)
      The purpose of this feature doesn't seem to be to restrict what a shell user can do. Rather, if I read this correctly, it restricts what files a user can access via sftp. Without this feature, a user can sftp in, and then cd to / or any other folder that he has rights too. This chroot feature lets the admin limit the root to, say, his home directory, or some other folder such as a virtual web root or something.

      It's only natural that this same chroot feature would be added to sftp.
      • Re:Why bother? (Score:5, Insightful)

        by bsdphx (987649) on Wednesday February 20, @02:02PM (#22491882) Homepage
        Understanding the issues is better than parroting what you've heard from random sources. Given the OpenBSD and OpenSSH track record for security it's obvious they have some serious clues about security.
  • Oh thank god (Score:3, Interesting)

    by Just Some Guy (3352) <kirk+slashdot@strauser.com> on Wednesday February 20, @02:20PM (#22492144) Homepage Journal

    Now I can finally switch some customers from FTP to SFTP. Thanks for making this hugely useful change!

    Anyone know if SFTP logging will be added any time soon? That's the last missing feature i always have to manually patch in.

    • Re: (Score:3, Insightful)

      All we need now is some form of virtual user system that can be mapped to a real, unprivileged user, preferably with a flexible auth system.
    • Re: (Score:2)

      That's the last missing feature i always have to manually patch in.

      I'm still hankering for tab completion in SFTP myself... maybe someday.

      • Re: (Score:3, Informative)

        Use lftp

        It will let you connect to sftp servers, and have a sane command line experience. It also has many nifty mirroring commands.
  • Nothing New (Score:2, Informative)

    This isn't really anything new. This functionality has existed as a patch for a while. It's still nice to see that it's finally being integrated into the main tree, though.
  • Does This Mean (Score:3, Interesting)

    by ajs318 (655362) <sd_resp2NO@SPAMearthshod.co.uk> on Wednesday February 20, @03:03PM (#22492700)
    Does this mean that I can give users shell access, by placing (hard links to) a stripped-down busybox and ash in $HOME/bin, and they won't be able to access anything outside the chroot environment? That could be sweet.
  • all that for sftp? (Score:4, Interesting)

    by sgt scrub (869860) <saintiumNO@SPAMyahoo.com> on Wednesday February 20, @03:06PM (#22492746) Homepage
    It is cool tech but not the way I would do things. WebDav with ApacheSSL properly installed is lots safer. IMHO there should never be user accounts on a machine, other than root and the person administrating the box.
    • Re:all that for sftp? (Score:4, Insightful)

      by evilviper (135110) on Wednesday February 20, @06:07PM (#22495562) Journal

      WebDav with ApacheSSL properly installed is lots safer.

      Why? No privilege separation. A MUCH bigger code base.

      Not to mention fewer standalone programs.

      IMHO there should never be user accounts on a machine,

      Why not? The user security model is reliable and time tested. It does not require reinventing the "user". It does not depend on one program handling it's own system of virtual permissions correctly. It does not depend on the security of a large program that users directly interact with.

      I can see ample reasons sftp is safer.
    • Re: (Score:3, Informative)

      This is news because the chroot and sftp server are now built in to the openssh binaries, so you don't have to manually set up the chroot. While there's no GUI, it is in fact now easier to set up such a thing.