Debian Codegraph @

debian/README.Debian

raw
1 libpam-chroot for Debian
2 ------------------------
3
4 This package has not been thoroughly tested by Debian (security wise),
5 however, it is provided in the hope that it will be useful for some
6 environments.
7
8 RedHat distributes a pam_chroot.so module along with its PAM modules
9 (last I looked version 0.74) however the source code is not the same
10 (but might be derived from the same base).
11
12 To use this module you need to:
13
14 a) modify a PAM-aware application by editing it's file in /etc/pam.d/
15 For local access this application could be login, xdm, kdm, su or
16 sudo. For remote access this application could be ssh, ftp.. Try
17 adding (as the last line):
18
19 # Test Chroot features
20 session required pam_chroot.so debug
21
22 (the debug option will printout progress of the module to syslog. Debug
23 messages go to authpriv.notice)
24
25 b) Set the proper chroot environment for each user.
26 (this is quite tricky if you ask me :) For an example of how
27 to setup an environment for 'login' take a look at the files under
28 /usr/share/doc/libpam-chroot/examples/.
29
30 Other applications might be more difficult to setup (the more complex
31 the application the worst).
32
33 If you find it difficult to setup a complex chroot you might want to
34 setup a minimal version of a Debian installation (using 'debootstrap')
35 and then removing those applications unneded for your environment
36 (specifically, remove _all_ setuid applications). You might even want
37 to use some automatic systems to setup chroots like 'makejail'.
38
39 c) Configure /etc/security/chroot.conf
40
41 Detailed info:
42 --------------
43 (based on the RedHat's README for Linux-PAM 0.74)
44
45 Operation:
46 When the calling application attempts to open a session, pam_chroot
47 opens /etc/security/chroot.conf and searches for a line of the form:
48
49 user directory
50
51 where the "user" listed can be either a real username or a
52 regular expression (if you are using the 'use_regex' option). If the
53 PAM_USER for whom the session is being opened matches,
54 the module will attempt to chroot() to the given directory.
55
56 Optional arguments:
57 "debug" Log debug messages to syslog.
58 "onerr=" Values can be "succeed" or "fail". The action to take if
59 the configuration file cannot be opened, the chroot()
60 fails, or the user does not match any of the expressions
61 listed in the configuration file. Default is "succeed".
62
63 (for more options see /usr/share/doc/libpam-chroot/options)
64
65 Other Notes: The calling application must be executing with root
66 privileges in order to be able to chroot() at all (see the chroot(2)
67 manpage).
68
69 Warning: If configured incorrectly, this module may potentially render
70 the service unusable and, under some circumstances, pose a security
71 risk.
72
73 Setting up OpenSSH with libpam-chroot
74 -------------------------------------
75
76 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 NOTE: OpenSSH supports, since the 4.9 release, the definition of
78 chrooted enviroments. For more information see the 'ChrootDirectory'
79 directive in sshd_config (5).
80
81 Setting up OpenSSH libpam-chroot is *not* recommended and most likely will not
82 work. The following information is provided for those users that want to tinker
83 with pam-chroot and SSH.
84
85 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
86
87
88 Many systems want to setup a restricted remote access to a system in
89 which users are confined to their user directories, but are unable to
90 "see" the whole system. If you want to develop this using OpenSSH
91 and libpam-chroot you will need to:
92
93 0) Setup a chroot environment for your users. Make sure that
94 environment includes the standard tools they will need (like their
95 shell) and that it also includes a /dev directory with the /dev/ptmx
96 and /dev/pty* devices and the /dev/pts/ subdirectory (runnig MAKEDEV
97 in the /dev directory of the chrooted environment should be
98 sufficient).
99
100 Note: This environment is similar to the 'login' environment detailed
101 under /usr/share/doc/libpam-chroot/examples
102
103 1) Add this line to /etc/pam.d/ssh (should be the last line)
104 session required pam_chroot.so debug
105
106 2) Configure /etc/security/chroot.conf so that the users you determine
107 are chrooted to the directory you setup previously. You might want to have
108 independent directories for different users so that they will not be
109 able to see neither the whole system nor each other's.
110
111 3) Depending on your OpenSSH version it might work or not. Since 3.6.1p2
112 the do_pam_session() function is called after sshd has dropped privs,
113 since chroot() needs root priviledges it will not work with
114 Privilege separation on. In newer OpenSSH versions, however, the
115 PAM code has been modified and do_pam_session is called before
116 dropping priviledges so it will work even with Privilege separation.
117
118 If you don't need to disable Privilege Separation you will need an /etc/passwd
119 with the user's UID inside the chroot for Privilege Separation to work
120 properly.
121
122 If you have Privilege Separation set to on and your OpenSSH version
123 does not behave properly you will need to disable it. If you don't,
124 users that try to connect to your server and would be chrooted by
125 this module will see this:
126
127 $ ssh -l user server
128 user@server's password:
129 Connection to server closed by remote host.
130 Connection to server closed.
131
132 This is because the ssh daemon, which is running as 'sshd', is not
133 be able to make the chroot() system call. To disable Privilege separation
134 you have to modify the /etc/ssh/sshd_config configuration file.
135 Change the (default) line:
136
137 UsePrivilegeSeparation yes
138
139 to
140
141 UsePrivilegeSeparation no
142
143 Notice that this will lower the security of your system since the
144 OpenSSH server will run as 'root' user. This means that if a remote
145 attack is found against OpenSSH an attacker will get 'root'
146 priviledges instead of 'sshd', thus compromising the whole system.
147
148 If you are using a kernel that implements Mandatory Access Control
149 (RSBAC/SElinux) you can avoid changing this configuration just by
150 granting the 'sshd' user priviledges to make the chroot() system call.
151
152 Of course, you could just chroot() the daemon in the init.d script to
153 the chroot environment you have setup, but then you wouldn't need
154 pam-chroot at all.
155
156 4) In order for chroots to work with newer OpenSSH versions the chroot
157 directory of a user needs to include both the /proc filesystem and
158 the /dev/pts
159
160 - If /proc is not mounted in the chroot, SSH access will be interrupted
161 with the message:
162
163 Connection reset by peer
164 Connection to <server-ip> closed.
165
166 To mount /proc do the following:
167 mount -t proc /proc <chroot_directory>/proc
168
169 - If /dev/pts is not mounted, the SSH login will freeze after
170 authentication with the message:
171
172 PTY allocation request failed on channel 0
173
174 To mount /dev do the following:
175 mount --rbind /dev <chroot_directory>/dev
176
177
178 --
179 Javier Fernandez-Sanguino <[email protected]>
180 Thu, 03 Jun 2021 13:26:58 +0200
181
182