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