1

I've built a simple File Server with Samba and Netatalk running on CentOS 7.2. Everything is working as expected except for SELinux that's denying Samba to authenticate due to a policy of denying writes on /var/tmp for the Kerberos Ticket.

This is cleary a SELinux problem since everything works as expected if SELinux is disabled and those entries appeared on audit.log when trying to mount the SMB with SELinux on permissive mode:

type=AVC msg=audit(1466917992.944:493): avc: denied { write } for pid=3902 comm="smbd" name="DALARAN-044_0" dev="dm-0" ino=50452330 scontext=system_u:system_r:smbd_t:s0 tcontext=system_u:object_r:tmp_t:s0 tclass=file
type=AVC msg=audit(1466917992.944:493): avc: denied { open } for pid=3902 comm="smbd" path="/var/tmp/DALARAN-044_0" dev="dm-0" ino=50452330 scontext=system_u:system_r:smbd_t:s0 tcontext=system_u:object_r:tmp_t:s0 tclass=file
type=SYSCALL msg=audit(1466917992.944:493): arch=c000003e syscall=2 success=yes exit=39 a0=7fa840d08290 a1=2 a2=180 a3=7ffc93307cb0 items=0 ppid=3578 pid=3902 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="smbd" exe="/usr/sbin/smbd" subj=system_u:system_r:smbd_t:s0 key=(null)

I checked online but I was unable to find a solution. Already have some SELinux bits set like those:

getsebool -a | grep -iP "samba|smb|nmb|kerberos|krb|tmp"
gssd_read_tmp --> on
httpd_tmp_exec --> off
kerberos_enabled --> on
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> on
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
smbd_anon_write --> off
tmpreaper_use_nfs --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off

So something is missing, and I would like to keep SELinux enabled.

Thanks,

Additional info:

File: /etc/krb5.conf

[logging]
 default = FILE:/var/log/krb5libs.log
 kdc = FILE:/var/log/krb5kdc.log
 admin_server = FILE:/var/log/kadmind.log

[libdefaults]
 dns_lookup_realm = false
 ticket_lifetime = 24h
 renew_lifetime = 7d
 forwardable = true
 rdns = false
# default_realm = EXAMPLE.COM
 default_ccache_name = KEYRING:persistent:%{uid}

[realms]
# EXAMPLE.COM = {
#  kdc = kerberos.example.com
#  admin_server = kerberos.example.com
# }

[domain_realm]
# .example.com = EXAMPLE.COM
# example.com = EXAMPLE.COM

File: /etc/sssd/sssd.conf

[sssd]
domains = if.ufrj.br
config_file_version = 2
services = nss, pam

[domain/if.ufrj.br]
ad_domain = if.ufrj.br
krb5_realm = IF.UFRJ.BR
realmd_tags = manages-system joined-with-samba 
cache_credentials = True
id_provider = ad
krb5_store_password_if_offline = True
default_shell = /bin/bash
ldap_id_mapping = True
#use_fully_qualified_names = True
fallback_homedir = /home/%u
access_provider = ad

File: /etc/samba/smb.conf

[global]
    server string = Samba Server Version %v
    workgroup = IF

    log file = /var/log/samba/log.%m
    max log size = 50
    log level = 3

    security = ads
    realm = IF.UFRJ.BR
    kerberos method = system keytab 

    load printers = no
    cups options = raw
    printing = bsd
    printcap name = /dev/null

[homes]
    comment = Home Directories
    browseable = no
    writable = yes
    vfs objects = catia fruit streams_xattr
    fruit:resource = file
    fruit:metadata = netatalk
    fruit:locking = netatalk
    fruit:encoding = native

1 Answer 1

2

Running your messages through audit2allow we find

#============= smbd_t ==============

#!!!! This avc can be allowed using the boolean 'samba_export_all_rw'
allow smbd_t tmp_t:file { write open };

This tells us that samba isn't allowed to write or open files with a context tmp_t 1.

You could put SELinux in Permissive mode and let the system run for a while to gather a full set of denial messages, then use audit2allow to create a custom module but you may be able to use exiting policy. The selinux_samba(8) man page lists all the booleans and file contexts that are associate with samba.

Of interest may be smbd_tmp_t and samba_var_t and searching policy ( sesearch --allow -s smbd_t ... we find

allow smbd_t smbd_tmp_t : file { ioctl read write create getattr setattr lock append unlink link rename open } ;
allow smbd_t samba_var_t : file { ioctl read write create getattr setattr lock append unlink link rename open } ;

So files labelled as either would do what you want. My preference here would be to use a directory and/or files labelled smbd_tmp_t.

Searching the SELinux regex database semange fcontext -l | grep smbd_tmp_t we find that there are no entries. So we'll need to add one. I don't know about samba and kerberos. If you can configure it so that it puts the tickets in a specific directory (for example /var/tmp/samba) then this should work

semanage fcontext -a -t smbd_tmp_t "/var/tmp/samba(/.*)?"
mkdir /var/tmp/samba #(and set the file ownership and perms appropriately)
restorecon -r /var/tmp/samba

If you have to use the file /var/tmp/DALARAN-044_0 then

 semanage fcontext -a -t smbd_tmp_t "/var/tmp/DALARAN-044_0" 
 restorecon -r /var/tmp/DALARAN-044_0

Restart samba/kerberos/whatevever

1 Note: you almost certainly don't want to set that boolean as a compromised samba will have full read/write access to all files on the system.

it's Sunday, late and the bottle of Rioja has been very nice :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .