Chris PeBenito 31b7c0
#DESC SSH - SSH daemon
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Authors:  Anthony Colatrella (NSA) <amcolat@epoch.ncsc.mil>
Chris PeBenito 31b7c0
#           Stephen Smalley <sds@epoch.ncsc.mil>
Chris PeBenito 31b7c0
#           Russell Coker <russell@coker.com.au>
Chris PeBenito 31b7c0
# X-Debian-Packages: ssh
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow ssh logins as sysadm_r:sysadm_t
Chris PeBenito 31b7c0
bool ssh_sysadm_login false;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# allow host key based authentication
Chris PeBenito 31b7c0
bool allow_ssh_keysign false;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`inetd.te', `
Chris PeBenito 31b7c0
# Allow ssh to run from inetd instead of as a daemon.
Chris PeBenito 31b7c0
bool run_ssh_inetd false;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# sshd_exec_t is the type of the sshd executable.
Chris PeBenito 31b7c0
# sshd_key_t is the type of the ssh private key files
Chris PeBenito 31b7c0
type sshd_exec_t, file_type, exec_type, sysadmfile;
Chris PeBenito 31b7c0
type sshd_key_t, file_type, sysadmfile;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
define(`sshd_program_domain', `
Chris PeBenito 31b7c0
# privowner is for changing the identity on the terminal device
Chris PeBenito 31b7c0
# privfd is for passing the terminal file handle to the user process
Chris PeBenito 31b7c0
# auth_chkpwd is for running unix_chkpwd and unix_verify.
Chris PeBenito 31b7c0
type $1_t, domain, privuser, privrole, privlog, privowner, privfd, auth_chkpwd, nscd_client_domain, mlsfileread, mlsfilewrite, mlsfileupgrade, mlsfiledowngrade, mlsprocsetsl;
Chris PeBenito 31b7c0
can_exec($1_t, sshd_exec_t)
Chris PeBenito 31b7c0
r_dir_file($1_t, self)
Chris PeBenito 31b7c0
role system_r types $1_t;
Chris PeBenito 31b7c0
dontaudit $1_t shadow_t:file { getattr read };
Chris PeBenito 31b7c0
uses_shlib($1_t)
Chris PeBenito 31b7c0
allow $1_t self:unix_dgram_socket create_socket_perms;
Chris PeBenito 31b7c0
allow $1_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 31b7c0
allow $1_t self:fifo_file rw_file_perms;
Chris PeBenito 31b7c0
allow $1_t self:process { fork sigchld signal setsched setrlimit };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
dontaudit $1_t self:lnk_file read;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# do not allow statfs()
Chris PeBenito 31b7c0
dontaudit $1_t fs_type:filesystem getattr;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t bin_t:dir search;
Chris PeBenito 31b7c0
allow $1_t bin_t:lnk_file read;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for sshd subsystems, such as sftp-server.
Chris PeBenito 31b7c0
allow $1_t bin_t:file getattr;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /var.
Chris PeBenito 31b7c0
allow $1_t var_t:dir { getattr search };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /var/log.
Chris PeBenito 31b7c0
allow $1_t var_log_t:dir search;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /etc.
Chris PeBenito 31b7c0
allow $1_t etc_t:dir search;
Chris PeBenito 31b7c0
# ioctl is for pam_console
Chris PeBenito 31b7c0
dontaudit $1_t etc_t:file ioctl;
Chris PeBenito 31b7c0
allow $1_t etc_t:file { getattr read };
Chris PeBenito 31b7c0
allow $1_t etc_t:lnk_file { getattr read };
Chris PeBenito 31b7c0
allow $1_t etc_runtime_t:file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read and write /dev/tty and /dev/null.
Chris PeBenito 31b7c0
allow $1_t devtty_t:chr_file rw_file_perms;
Chris PeBenito 31b7c0
allow $1_t { null_device_t zero_device_t }:chr_file rw_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /dev/urandom
Chris PeBenito 31b7c0
allow $1_t urandom_device_t:chr_file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
can_network($1_t)
Chris PeBenito 31b7c0
allow $1_t port_type:tcp_socket name_connect;
Chris PeBenito 31b7c0
can_kerberos($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t self:capability { kill sys_chroot sys_resource chown dac_override fowner fsetid setgid setuid sys_tty_config };
Chris PeBenito 31b7c0
allow $1_t { home_root_t home_dir_type }:dir { search getattr };
Chris PeBenito 31b7c0
if (use_nfs_home_dirs) {
Chris PeBenito 31b7c0
allow $1_t autofs_t:dir { search getattr };
Chris PeBenito 31b7c0
allow $1_t nfs_t:dir { search getattr };
Chris PeBenito 31b7c0
allow $1_t nfs_t:file { getattr read };
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
if (use_samba_home_dirs) {
Chris PeBenito 31b7c0
allow $1_t cifs_t:dir { search getattr };
Chris PeBenito 31b7c0
allow $1_t cifs_t:file { getattr read };
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Set exec context.
Chris PeBenito 31b7c0
can_setexec($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Update utmp.
Chris PeBenito 31b7c0
allow $1_t initrc_var_run_t:file rw_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Update wtmp.
Chris PeBenito 31b7c0
allow $1_t wtmp_t:file rw_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Get security policy decisions.
Chris PeBenito 31b7c0
can_getsecurity($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow read access to login context
Chris PeBenito 31b7c0
r_dir_file( $1_t, default_context_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Access key files
Chris PeBenito 31b7c0
allow $1_t sshd_key_t:file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Update /var/log/lastlog.
Chris PeBenito 31b7c0
allow $1_t lastlog_t:file rw_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
read_locale($1_t)
Chris PeBenito 31b7c0
read_sysctl($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Can create ptys
Chris PeBenito 31b7c0
can_create_pty($1, `, server_pty')
Chris PeBenito 31b7c0
allow $1_t $1_devpts_t:chr_file { setattr getattr relabelfrom };
Chris PeBenito 31b7c0
dontaudit sshd_t userpty_type:chr_file relabelfrom;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t faillog_t:file { append getattr };
Chris PeBenito 31b7c0
allow $1_t sbin_t:file getattr;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow checking users mail at login
Chris PeBenito 31b7c0
allow $1_t { var_spool_t mail_spool_t }:dir search;
Chris PeBenito 31b7c0
allow $1_t mail_spool_t:lnk_file read;
Chris PeBenito 31b7c0
allow $1_t mail_spool_t:file getattr;
Chris PeBenito 31b7c0
')dnl end sshd_program_domain
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# macro for defining which domains a sshd can spawn
Chris PeBenito 31b7c0
# $1_t is the domain of the sshd, $2 is the domain to be spawned, $3 is the
Chris PeBenito 31b7c0
# type of the pty for the child
Chris PeBenito 31b7c0
define(`sshd_spawn_domain', `
Chris PeBenito 31b7c0
login_spawn_domain($1, $2)
Chris PeBenito 31b7c0
ifdef(`xauth.te', `
Chris PeBenito 31b7c0
domain_trans($1_t, xauth_exec_t, $2)
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Relabel and access ptys created by sshd
Chris PeBenito 31b7c0
# ioctl is necessary for logout() processing for utmp entry and for w to
Chris PeBenito 31b7c0
# display the tty.
Chris PeBenito 31b7c0
# some versions of sshd on the new SE Linux require setattr
Chris PeBenito 31b7c0
allow $1_t $3:chr_file { relabelto read write getattr ioctl setattr };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# inheriting stream sockets is needed for "ssh host command" as no pty
Chris PeBenito 31b7c0
# is allocated
Chris PeBenito 31b7c0
allow $2 $1_t:unix_stream_socket rw_stream_socket_perms;
Chris PeBenito 31b7c0
')dnl end sshd_spawn_domain definition
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#################################
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Rules for the sshd_t domain, et al.
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# sshd_t is the domain for the sshd program.
Chris PeBenito 31b7c0
# sshd_extern_t is the domain for ssh from outside our network
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
sshd_program_domain(sshd)
Chris PeBenito 31b7c0
if (ssh_sysadm_login) {
Chris PeBenito 31b7c0
allow sshd_t devpts_t:dir r_dir_perms;
Chris PeBenito 31b7c0
sshd_spawn_domain(sshd, userdomain, { sysadm_devpts_t userpty_type })
Chris PeBenito 31b7c0
} else {
Chris PeBenito 31b7c0
sshd_spawn_domain(sshd, unpriv_userdomain, userpty_type)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for X forwarding
Chris PeBenito 31b7c0
allow sshd_t xserver_port_t:tcp_socket name_bind;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
r_dir_file(sshd_t, selinux_config_t)
Chris PeBenito 31b7c0
sshd_program_domain(sshd_extern)
Chris PeBenito 31b7c0
sshd_spawn_domain(sshd_extern, user_mini_domain, mini_pty_type)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for when the network connection breaks after running newrole -r sysadm_r
Chris PeBenito 31b7c0
dontaudit sshd_t sysadm_devpts_t:chr_file setattr;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`inetd.te', `
Chris PeBenito 31b7c0
if (run_ssh_inetd) {
Chris PeBenito 31b7c0
allow inetd_t ssh_port_t:tcp_socket name_bind;
Chris PeBenito 31b7c0
domain_auto_trans(inetd_t, sshd_exec_t, sshd_t)
Chris PeBenito 31b7c0
domain_trans(inetd_t, sshd_exec_t, sshd_extern_t)
Chris PeBenito 31b7c0
allow { sshd_t sshd_extern_t } inetd_t:tcp_socket rw_socket_perms;
Chris PeBenito 31b7c0
allow { sshd_t sshd_extern_t } var_run_t:dir { getattr search };
Chris PeBenito 31b7c0
allow { sshd_t sshd_extern_t } self:process signal;
Chris PeBenito 31b7c0
} else {
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
can_access_pty({ sshd_t sshd_extern_t }, initrc)
Chris PeBenito 31b7c0
allow { sshd_t sshd_extern_t } self:capability net_bind_service;
Chris PeBenito 31b7c0
allow { sshd_t sshd_extern_t } ssh_port_t:tcp_socket name_bind;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for port forwarding
Chris PeBenito 31b7c0
can_tcp_connect(userdomain, sshd_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
domain_auto_trans(initrc_t, sshd_exec_t, sshd_t)
Chris PeBenito 31b7c0
domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
Chris PeBenito 31b7c0
dontaudit initrc_t sshd_key_t:file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Inherit and use descriptors from init.
Chris PeBenito 31b7c0
allow { sshd_t sshd_extern_t } init_t:fd use;
Chris PeBenito 31b7c0
ifdef(`inetd.te', `
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Create /var/run/sshd.pid
Chris PeBenito 31b7c0
var_run_domain(sshd)
Chris PeBenito 31b7c0
var_run_domain(sshd_extern)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`direct_sysadm_daemon', `
Chris PeBenito 31b7c0
# Direct execution by sysadm_r.
Chris PeBenito 31b7c0
domain_auto_trans(sysadm_t, sshd_exec_t, sshd_t)
Chris PeBenito 31b7c0
role_transition sysadm_r sshd_exec_t system_r;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
undefine(`sshd_program_domain')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# so a tunnel can point to another ssh tunnel...
Chris PeBenito 31b7c0
can_tcp_connect(sshd_t, sshd_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
tmp_domain(sshd, `', { dir file sock_file })
Chris PeBenito 31b7c0
ifdef(`pam.te', `
Chris PeBenito 31b7c0
can_exec(sshd_t, pam_exec_t)
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# ssh_keygen_t is the type of the ssh-keygen program when run at install time
Chris PeBenito 31b7c0
# and by sysadm_t
Chris PeBenito 31b7c0
daemon_base_domain(ssh_keygen)
Chris PeBenito 31b7c0
allow ssh_keygen_t etc_t:file { getattr read };
Chris PeBenito 31b7c0
file_type_auto_trans(ssh_keygen_t, etc_t, sshd_key_t, file)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Type for the ssh executable.
Chris PeBenito 31b7c0
type ssh_exec_t, file_type, exec_type, sysadmfile;
Chris PeBenito 31b7c0
type ssh_keysign_exec_t, file_type, exec_type, sysadmfile;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Everything else is in the ssh_domain macro in
Chris PeBenito 31b7c0
# macros/program/ssh_macros.te.
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 31b7c0
allow ssh_keygen_t sysadm_tty_device_t:chr_file { read write };
Chris PeBenito 31b7c0
allow ssh_keygen_t urandom_device_t:chr_file { getattr read };
Chris PeBenito 31b7c0
ifdef(`use_mcs', `
Chris PeBenito 31b7c0
range_transition initrc_t sshd_exec_t s0 - s0:c0.c255;
Chris PeBenito 31b7c0
')