rssh pass two - secure GNU arch committers
Hi,
I've extended my previous rssh.te to support multiple archives. My ultimate goal here is to have a role for people committing to a GNU arch archive, which just requires the ability to write files over sftp. I don't want to give out full shell accounts for this.
There are two files attached, intended to be domains/program/unused/rssh.te and macros/program/rssh_macros.te.
Here's a full explanation of how to use it. Say you have an area that you want several people to be able to write to over SFTP. First, you have to install rssh: http://rssh.sf.net/
Next, in a local .te policy file (I use domains/misc/local.te), do something like:
rssh_domain(rhythmbox)
This creates a role: rssh_rhythmbox_r, as well as some important types:rssh_rhythmbox_ro_t and rssh_rhythmbox_rw_t.
Next, create a new user account:
suseradd -s /usr/bin/rssh rhythmbox
mkdir /home/rhythmbox
chcon system_u:object_r:rssh_rhythmbox_ro_t /home/rhythmbox
Now, edit /etc/selinux/users, and add a line that looks like this:
user rhythmbox roles { rssh_rhythmbox_r };
Next, gather public ssh keys (usually ~/.ssh/id_rsa.pub) for all the people you want to have the ability to write to the archive. Concatenate them all into /home/rhythmbox/.ssh/authorized_keys.
Double-check that the type on .ssh and .authorized_keys is rssh_rhythmbox_ro_t. The user should *not* be able to write to these files.
At this point, double-check that you can log in successfully:
sftp [email protected]
And finally, just create the directory you want people to be able to write to (in my case, /home/rhythmbox/arch), and ensure it has the rssh_rhythmbox_rw_t type.
In my case, I also wanted the webserver to be able to read these files, so in my local.te, I do:
define(monk_rssh_domain', r_dir_file(httpd_t,rssh_$1_ro_t) r_dir_file(httpd_t,rssh_$1_rw_t)
dontaudit httpd_t rssh_$1_ro_t:sock_file r_file_perms; ')monk_rssh_domain(rhythmbox)
The sock_file bits are for another program we use (mini-dinstall).
#DESC Rssh - Restricted (scp/sftp) only shell
#
# Authors: Colin Walters <[email protected]>
# X-Debian-Package: rssh
#
type rssh_exec_t, file_type, sysadmfile, exec_type;
ifdef(ssh.te',
allow sshd_t rssh_exec_t:file r_file_perms;
')
# See rssh_macros.te for the rest.
#
# Macros for Rssh domains
#
# Author: Colin Walters <[email protected]>
#
#
# rssh_domain(domain_prefix)
#
# Define a specific rssh domain.
#
# The type declaration for the executable type for this program is
# provided separately in domains/program/rssh.te. # undefine(`rssh_domain') ifdef(`rssh.te', ` define(`rssh_domain',` type rssh_$1_t, domain, privlog, privfd; role rssh_$1_r types rssh_$1_t; allow system_r rssh_$1_r;
type rssh_$1_rw_t, file_type, sysadmfile;
type rssh_$1_ro_t, file_type, sysadmfile;
general_domain_access(rssh_$1_t);uses_shlib(rssh_$1_t);base_file_read_access(rssh_$1_t);
allow rssh_$1_t var_t:dir r_dir_perms;r_dir_file(rssh_$1_t, etc_t);r_dir_file(rssh_$1_t, etc_runtime_t);r_dir_file(rssh_$1_t, locale_t);can_exec(rssh_$1_t, bin_t);can_exec(rssh_$1_t, sshd_sftp_exec_t);
r_dir_file(rssh_$1_t, rssh_$1_ro_t);create_dir_file(rssh_$1_t, rssh_$1_rw_t);
ifdef(ssh.te',
allow rssh_$1_t sshd_t:fd use;
allow rssh_$1_t sshd_t:tcp_socket rw_stream_socket_perms; allow rssh_$1_t sshd_t:unix_stream_socket rw_stream_socket_perms; # For reading /home/user/.sshr_dir_file(sshd_t, rssh_$1_ro_t);domain_trans(sshd_t, rssh_exec_t, rssh_$1_t);
')
')
', `
define(rssh_domain',')
')