|
| 1 | + |
| 2 | +## <summary>policy for pam_zfs_key</summary> |
| 3 | + |
| 4 | +######################################## |
| 5 | +## <summary> |
| 6 | +## Allow domain to query datasets on ZFS. |
| 7 | +## </summary> |
| 8 | +## <param name="domain"> |
| 9 | +## <summary> |
| 10 | +## Domain allowed access. |
| 11 | +## </summary> |
| 12 | +## </param> |
| 13 | +# |
| 14 | +interface(`pam_zfs_key_query',` |
| 15 | + gen_require(` |
| 16 | + type device_t; |
| 17 | + ') |
| 18 | + |
| 19 | + dnl Using ifdef() keeps `sepolgen-ifgen' from complaining |
| 20 | + define(`ZFS_IOC') |
| 21 | + ifdef(`ZFS_IOC', ` |
| 22 | + define(`ZFS_IOC_POOL_STATS', `0x5a05') |
| 23 | + define(`ZFS_IOC_OBJSET_STATS', `0x5a12') |
| 24 | + define(`ZFS_IOC_POOL_GET_PROPS', `0x5a27') |
| 25 | + define(`ZFS_IOC_LOAD_KEY', `0x5a49') |
| 26 | + define(`ZFS_IOC_UNLOAD_KEY', `0x5a4a') |
| 27 | + define(`ZFS_IOC_CHANGE_KEY', `0x5a4b') |
| 28 | + ') |
| 29 | + |
| 30 | + allow $1 device_t:chr_file { open ioctl }; |
| 31 | + allowxperm $1 device_t:chr_file ioctl ZFS_IOC_OBJSET_STATS; |
| 32 | + |
| 33 | + # While /dev/zfs does not support read() or write(), libzfs opens it with |
| 34 | + # O_RDWR, meaning we need these permissions. Remove these if ZFS changes |
| 35 | + # to using the Linux specialization O_PATH (or O_EXEC). |
| 36 | + allow $1 device_t:chr_file { read write }; |
| 37 | +') |
| 38 | + |
| 39 | +######################################## |
| 40 | +## <summary> |
| 41 | +## Allow domain to open and close a session on the pam_zfs_key PAM module. |
| 42 | +## </summary> |
| 43 | +## <param name="domain"> |
| 44 | +## <summary> |
| 45 | +## Domain allowed access. |
| 46 | +## </summary> |
| 47 | +## </param> |
| 48 | +# |
| 49 | +interface(`pam_zfs_key_session',` |
| 50 | + gen_require(` |
| 51 | + type device_t; |
| 52 | + type fs_t; |
| 53 | + type pam_var_run_t; |
| 54 | + type user_home_dir_t; |
| 55 | + ') |
| 56 | + |
| 57 | + files_pid_filetrans($1, pam_var_run_t, dir, "pam_zfs_key") |
| 58 | + |
| 59 | + pam_zfs_key_query($1) |
| 60 | + allowxperm $1 device_t:chr_file ioctl { ZFS_IOC_LOAD_KEY ZFS_IOC_UNLOAD_KEY }; |
| 61 | + |
| 62 | + # The zfs_open() function returns both a zfs handle and a zpool handle for |
| 63 | + # its containing pool; as part of the zpool fetching, the function grabs |
| 64 | + # the pool stats. Despite marking the pool as unavailable, the library |
| 65 | + # will still query the pool properties to check for read-only status. |
| 66 | + dontauditxperm $1 device_t:chr_file ioctl ZFS_IOC_POOL_STATS; |
| 67 | + |
| 68 | + # Needed to determine if the zpool is read-only (if so, the dataset must be |
| 69 | + # mounted read-only too). |
| 70 | + allowxperm $1 device_t:chr_file ioctl ZFS_IOC_POOL_GET_PROPS; |
| 71 | + |
| 72 | + allow $1 fs_t:filesystem { mount unmount }; |
| 73 | + allow $1 user_home_dir_t:dir mounton; |
| 74 | +') |
| 75 | + |
| 76 | +######################################## |
| 77 | +## <summary> |
| 78 | +## Allow domain to change password on the pam_zfs_key PAM module. |
| 79 | +## </summary> |
| 80 | +## <param name="domain"> |
| 81 | +## <summary> |
| 82 | +## Domain allowed access. |
| 83 | +## </summary> |
| 84 | +## </param> |
| 85 | +# |
| 86 | +interface(`pam_zfs_key_password',` |
| 87 | + gen_require(` |
| 88 | + type device_t; |
| 89 | + ') |
| 90 | + |
| 91 | + pam_zfs_key_query($1) |
| 92 | + |
| 93 | + # The zfs_open() function returns both a zfs handle and a zpool handle for |
| 94 | + # its containing pool; as part of the zpool fetching, the function grabs |
| 95 | + # the pool stats. The zpool information does not appear to be used when |
| 96 | + # changing the key, but cannot be skipped easily, so silence the denial. |
| 97 | + dontauditxperm $1 device_t:chr_file ioctl ZFS_IOC_POOL_STATS; |
| 98 | + |
| 99 | + auditallowxperm $1 device_t:chr_file ioctl ZFS_IOC_CHANGE_KEY; |
| 100 | + allowxperm $1 device_t:chr_file ioctl ZFS_IOC_CHANGE_KEY; |
| 101 | +') |
0 commit comments