afs domain development under the selinux kernel
Summary:
The Selinux kernel provides type enforcement via data labeling for all data, program and user objects on a server. This indludes persistent labels for filesystem-based data and kernel/policy derived labels for other data objects such as /proc/*, shared memory, sockets, device files etc.
(Open)AFS provides a robust network filesystem with directory-based ACLs authenticated against kerberos4 tickets, usually provided by a krb5 kdc. Many sites rely on AFS to distribute system binaries.
I've been working on OpenAFS client < selinux kernel for awhile now, and have got a first-draft policy working and currently under test. I'm not to sure of complete/correct-ness at this point but at least it seems to be working, and now I want to go in and make changes to either the kernel, the libafs kernel module or afsd to move the data in /afs/* into its own domain.
Openafs 1.2.8 introduced some structural changes in the afsd impelmentation (which complicate the policy requirements).
General notes:
afsd (afs client) & kernel/module
tmpfs_t:* allow statements are specific because for the moment the afs cache dir is being created in /tmp -- that's only a kludge because I hadn't created any other ext2fs and afsd won't run the cache on aything else. Longterm the cachedir should probably have it's own type.
userspace client access
/afs/* is labeled of course as unlabeled_t, currently I'm using a policy which allows user_r unrestricted access to this type. Better solutions could involve having type enforcemnt check for valid afs tickets and/or assigning a type to this data, however I'm not too sure what method might be appropriate for that.
Objective:
Presently allowing user_r access to files provided through afsd could be extended to other limited roles such as system_u:system_r:httpd_t with reasonable safety. Extending this to other roles would seem to be somewhat more probelmatic.
Questions:
Where can I consider generating / enforcing an afs_t type for data in /afs? This mostly is implemented over UDP port 7001. I think most things needed for the server parts are done, but I'm not certain how much implementation could to be done mostly in the policy config, and what things I need to modify to establish the type in either the kernel module or the afsd process.
Next steps:
I will also be working on running the afs database and fileserver functions under the selinux kernel. Because AFS volumes directly manipulate the inode structures in ext2fs there may be some significant problems with hosting an afs fileserver process under selinux.
SELinux will create a directory in every mounted filesystem named '...security' in the root of every filesystem which stores persistent SID:inode data. I'm not certain whether the creation of ...security will cause problems with a fs used as an afs partition.
Here's what I've changed so far (in /etc/security/selinux/src/policy/)
domains/program/initrc.te added:
allow run_init_t tmpfs_t:file { read write };
# however this is not sufficient to allow afsd to startup in enforcing mode # so for now I'm starting afsd before toggling into enforcing
domains/program/mount.te added:
allow mount_t kernel_t:process { sigkill };
# when /afs is unmounted I assume VFS is providing the magic for the kill to # be sent to afsd. Would it be better (possible?) to limit this to only killing # the afsd_t process?
file_contexts/program/afsd.fc:
# afsd /usr/sbin/afsd system_u:object_r:afsd_exec_t
Most of the work is in:
domains/program/afsd.te (also attached to this email)
# Domain for afsd executable
#
# make afsd_exec_t
type afsd_exec_t, file_type, sysadmfile,exec_type; type afsd_t, domain, privlog;
domain_auto_trans(initrc_t, afsd_exec_t, afsd_t)
allow afsd_t root_t:dir mounton;
allow kernel_t afsd_t:udp_socket { read write };
allow afsd_t afsd_t:capability { sys_admin sys_nice };
allow afsd_t afsd_t:process { fork setsched };
allow afsd_t afsd_t:udp_socket { create ioctl write };
allow afsd_t any_socket_t:udp_socket { sendto };
allow afsd_t etc_runtime_t:file { append getattr read }; allow afsd_t etc_t:dir { search };
allow afsd_t etc_t:file { getattr read write };
allow afsd_t fs_t:filesystem { getattr };
allow afsd_t ld_so_cache_t:file { getattr read };
allow afsd_t lib_t:dir { search };
allow afsd_t netif_eth0_t:netif { udp_send };
allow afsd_t netmsg_eth0_t:udp_socket { recvfrom };
allow afsd_t newrole_t:fd { use };
allow afsd_t node_t:node { udp_send };
allow afsd_t root_t:dir { search };
allow afsd_t shlib_t:file { execute getattr read };
allow afsd_t shlib_t:lnk_file { read };
allow afsd_t sysadm_tty_device_t:chr_file { getattr ioctl read write }; allow afsd_t sysadm_tmp_t:dir { create setattr getattr read search }; allow afsd_t sysadm_tmp_t:file { create };
allow afsd_t tmp_t:dir { search };
allow afsd_t unlabeled_t:filesystem { mount };
allow afsd_t usr_t:dir { search };
#
# required to give any access to users #
allow sysadm_t afsd_t:udp_socket { write };
allow user_t afsd_t:udp_socket { write };
#
# required for full client access #
allow kernel_t unlabeled_t:udp_socket { read write };
allow unlabeled_t any_socket_t:udp_socket { sendto }; allow unlabeled_t netif_eth0_t:netif { udp_send }; allow unlabeled_t node_t:node { udp_send }; allow unlabeled_t netmsg_eth0_t:udp_socket { recvfrom };
allow user_t unlabeled_t:dir { getattr search read write};
allow user_t unlabeled_t:file { read write setattr getattr execute execute_no_trans }; allow user_t unlabeled_t:lnk_file { read write setattr getattr };
allow user_t unlabeled_t:udp_socket { read write };
Quoted 6 lines · forrest whitcher
I've been working on OpenAFS client < selinux kernel for awhile now, and have got a first-draft policy working and currently under test. I'm not to sure of complete/correct-ness at this point but at least it seems to be working, and now I want to go in and make changes to either the kernel, the libafs kernel module or afsd to move the data in /afs/* into its own domain.
Doesn't genfs work with afs? If not how does it fail?
Quoted 4 lines
tmpfs_t:* allow statements are specific because for the moment the afs cache dir is being created in /tmp -- that's only a kludge because I hadn't created any other ext2fs and afsd won't run the cache on aything else. Longterm the cachedir should probably have it's own type.
I suspect that you have a mis-labelled startup script if you need to add any permissions for run_init_t.
Quoted 5 lines
/afs/* is labeled of course as
unlabeled_t, currently I'm using a policy which allowsuser_runrestricted access to this type. Better solutions could involve having type enforcemnt check for valid afs tickets and/or assigning a type to this data, however I'm not too sure what method might be appropriate for that.
Assigning a type to all of /afs or several types to different sub-directories should be easy enough with genfs.
However for full functionality it might be better to have the enforcement done on the server and to have the protocol support sending the SE security context for the client process over the network to allow the server to make SE Linux policy decisions on file access.
Quoted 6 lines
Where can I consider generating / enforcing an
afs_ttype for data in /afs? This mostly is implemented over UDP port 7001. I think most things needed for the server parts are done, but I'm not certain how much implementation could to be done mostly in the policy config, and what things I need to modify to establish the type in either the kernel module or the afsd process.
In genfs_contexts something like the following would be needed:
genfscon afs / system_u:object_r:afs_t
Quoted 4 lines
SELinux will create a directory in every mounted filesystem named '...security' in the root of every filesystem which stores persistent SID:inode data. I'm not certain whether the creation of ...security will cause problems with a fs used as an afs partition.
It can only be done at the server. The client can't create it on a network share and expect it to work. There are currently some problems if a machine crashes while files are being created and deleted whereby files can get the wrong security context. If SE Linux is changed to use xattr's for the PSID then this issue will be solved and some issues related to networking may be easier to address.
Quoted 3 lines
domains/program/initrc.te added:
allow
run_init_ttmpfs_t:file { read write };
I don't think that is right. I would like to see the dmesg logs that lead you to create that.
Quoted 2 lines
# however this is not sufficient to allow afsd to startup in enforcing mode # so for now I'm starting afsd before toggling into enforcing
Please show me some more logs and I'll make some suggestions.
Quoted 7 lines
domains/program/mount.te added:
allow
mount_tkernel_t:process { sigkill };# when /afs is unmounted I assume VFS is providing the magic for the kill to # be sent to afsd. Would it be better (possible?) to limit this to only killing # the afsd_t process?
I'm not sure what is happening here, please show some logs to make it clear.
Quoted 3 lines
Most of the work is in:
domains/program/afsd.te (also attached to this email)
I've made a few changes below. Using the daemon_domain() macro makes things a bit simpler and easier to read, and also makes sure that you get all the common things. EG the policy you had only appeared to support starting the daemon after running newrole, but not when logging in at the console directly into sysadm_r...
The unlabeled_t:tcp_socket is an indication of a problem too.
Quoted 5 lines
# Domain for afsd executable
#
# make afsd_exec_t
daemon_domain(afsd)
Quoted 9 lines
allow
afsd_troot_t:dir mounton;allow
kernel_tafsd_t:udp_socket { read write };allow
afsd_tafsd_t:capability {sys_adminsys_nice}; allowafsd_tafsd_t:process setsched;
allowafsd_tafsd_t:udp_socket { create ioctl write }; allowafsd_tany_socket_t:udp_socket { sendto }; allowafsd_tetc_runtime_t:file { append getattr read };
# do you REALLY want to allow it to write most files in /etc?
Quoted 8 lines
allow
afsd_tetc_t:file { getattr read write };
allowafsd_tnetif_eth0_t:netif {udp_send};
allowafsd_tnetmsg_eth0_t:udp_socket { recvfrom };
allowafsd_tnode_t:node {udp_send};
allowafsd_tsysadm_tty_device_t:chr_file { getattr ioctl read write }; allowafsd_tsysadm_tmp_t:dir { create setattr getattr read search }; allowafsd_tsysadm_tmp_t:file { create };
tmp_domain(afsd)
Quoted 18 lines
allow
afsd_tunlabeled_t:filesystem { mount };
allowafsd_tusr_t:dir { search };#
# required to give any access to users #allow
sysadm_tafsd_t:udp_socket { write };
allowuser_tafsd_t:udp_socket { write };#
# required for full client access #allow
kernel_tunlabeled_t:udp_socket { read write };
Quoted 7 lines
allow
unlabeled_tany_socket_t:udp_socket { sendto }; allowunlabeled_tnetif_eth0_t:netif {udp_send}; allowunlabeled_tnode_t:node {udp_send}; allowunlabeled_tnetmsg_eth0_t:udp_socket { recvfrom };allow
user_tunlabeled_t:dir { getattr search read write}; allowuser_tunlabeled_t:file { read write setattr getattr execute
execute_no_trans }; allow user_t unlabeled_t:lnk_file { read write setattr
Quoted 3 lines
getattr };
allow
user_tunlabeled_t:udp_socket { read write };
Signature · 10 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.