Cannot write policy to allow { relabelto }
I am having a weird problem writing a policy for a service. The service needs to set SELinux file contexts, so I've created a rule to allow this:
allow acme_nss_t cert_t : file { read write create getattr setattr relabelfrom relabelto open } ;
Despite this, I am still getting this denial:
avc: denied { relabelto } for pid=3561 comm="update-mod-nss" name="cert8.db" dev="dm-0" ino=50343845 scontext=system_u:system_r:acme_nss_t:s0 tcontext=unconfined_u:object_r:cert_t:s0 tclass=file
Any ideas?
Signature · 4 lines
======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ========================================================================
Quoted 7 lines · Ian Pilcher
I am having a weird problem writing a policy for a service. The service needs to set SELinux file contexts, so I've created a rule to allow this:
allow
acme_nss_tcert_t: file { read write create getattr setattr relabelfrom relabelto open } ;
Quoted 8 lines
Despite this, I am still getting this denial:
avc: denied { relabelto } for pid=3561 comm="update-mod-nss" name="cert8.db" dev="dm-0" ino=50343845 scontext=system_u:system_r:acme_nss_t:s0 tcontext=unconfined_u:object_r:cert_t:s0 tclass=file
Any ideas?
acme_nss_t needs to be associate with "can_change_object_identity" to be able to change the object identity from system_u to unconfined_u
typeattribute acme_nss_t can_change_object_identity;
or the appropriate macro:
domain_obj_id_change_exemption(acme_nss_t)
But there is no need to change the object identity in the first place, system_u will do fine.
Quoted 11 lines
Signature · 10 lines
-- ======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 8 lines · Dominick Grift
acme_nss_tneeds to be associate with "can_change_object_identity" to be able to change the object identity fromsystem_utounconfined_utypeattribute
acme_nss_tcan_change_object_identity;or the appropriate macro:
domain_obj_id_change_exemption(acme_nss_t)
Excellent, thank you!
Quoted 3 lines
But there is no need to change the object identity in the first place,
system_uwill do fine.
I'll have to think about this. I'm actually copying a directory tree from one place to another and copying the context from the source to destination with getfilecon() and setfilecon().
What APIs should I use if I *only* wanted to copy the type?
Signature · 4 lines
======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ========================================================================
Quoted 13 lines · Ian Pilcher
Quoted 8 lines · Dominick Grift
acme_nss_tneeds to be associate with "can_change_object_identity" to be able to change the object identity fromsystem_utounconfined_utypeattribute
acme_nss_tcan_change_object_identity;or the appropriate macro:
domain_obj_id_change_exemption(acme_nss_t)Excellent, thank you!
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
But there is no need to change the object identity in the first place,
system_uwill do fine.I'll have to think about this. I'm actually copying a directory tree from one place to another and copying the context from the source to destination with
getfilecon()andsetfilecon().
If you would be using getfilecon() then you would, most likely, not end up with unconfined_u as the identity
where are you copying that object to? There should be no content with type "cert_t" in a user home directory
Quoted 13 lines
What APIs should I use if I *only* wanted to copy the type?
Signature · 9 lines
======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 14 lines · Dominick Grift
Quoted 13 lines · Ian Pilcher
Quoted 8 lines · Dominick Grift
acme_nss_tneeds to be associate with "can_change_object_identity" to be able to change the object identity fromsystem_utounconfined_utypeattribute
acme_nss_tcan_change_object_identity;or the appropriate macro:
domain_obj_id_change_exemption(acme_nss_t)Excellent, thank you!
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
But there is no need to change the object identity in the first place,
system_uwill do fine.I'll have to think about this. I'm actually copying a directory tree from one place to another and copying the context from the source to destination with
getfilecon()andsetfilecon().If you would be using
getfilecon()then you would, most likely, not end up withunconfined_uas the identity
if there is a getfilecon_default() then try that instead of getfilecon()
Quoted 21 lines
where are you copying that object to? There should be no content with type "
cert_t" in a user home directoryQuoted 13 lines
What APIs should I use if I *only* wanted to copy the type?
Signature · 9 lines
======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 2 lines · Dominick Grift
where are you copying that object to? There should be no content with type "
cert_t" in a user home directory
I'm copying the mod_nss NSS database directory (/etc/httpd/alias). The program is intended to update Let's Encrypt certificates in mod_nss.
I've moved the actual mod_nss database into a directory named something like /etc/httpd/alias-20170218081357 and /etc/httpd/alias is now a symbolic link to that directory.
My program does this following:
* Create a new directory with a current timestamp:
/etc/httpd/alias-20170408143539 for example.
* Copy the NSS database files (cert8.db, key3.db, and secmod.db) from the "old" directory to the new directory. I can get away with this, because mod_nss always opens the database read-only.
* Open the NSS database in the new directory, delete any existing certificates with the matching nickname (hostname), and import the new certificate.
* Recursively copy any other content (files, symlinks, subdirectories) from the old directory to the new directory. This step also copies the ownership, permissions, and SELinux context of *all* objects, including the NSS database files. (This is where I hit the relabelto denial.)
* Create a new symbolic link, /etc/httpd/alias.new, that points to the new directory.
* Rename the /etc/httpd/alias.new symbolic link to /etc/httpd/alias.
* Recursively delete the old directory.
* Reload (SIGUSR1) httpd, so it will start using the new certificate. (Actually, systemd does this in an ExecStartPost.)
Signature · 4 lines
======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ========================================================================
Quoted 24 lines · Ian Pilcher
Quoted 2 lines · Dominick Grift
where are you copying that object to? There should be no content with type "
cert_t" in a user home directoryI'm copying the
mod_nssNSS database directory (/etc/httpd/alias). The program is intended to update Let's Encrypt certificates inmod_nss.I've moved the actual
mod_nssdatabase into a directory named something like/etc/httpd/alias-20170218081357and/etc/httpd/aliasis now a symbolic link to that directory.My program does this following:
* Create a new directory with a current timestamp:
/etc/httpd/alias-20170408143539 for example.* Copy the NSS database files (cert8.db, key3.db, and secmod.db) from the "old" directory to the new directory. I can get away with this, because
mod_nssalways opens the database read-only.* Open the NSS database in the new directory, delete any existing certificates with the matching nickname (hostname), and import the new certificate.
Quoted 5 lines
* Recursively copy any other content (files, symlinks, subdirectories) from the old directory to the new directory. This step also copies the ownership, permissions, and SELinux context of *all* objects, including the NSS database files. (This is where I hit the relabelto denial.)
Okay so i suppose that behaves like cp -a. That copies the file context as well.
I think then you are stuck with the object id change exemption solution because AFAIK there is no cp -a-minus-selinux-context or equivalent
This is also an issue with dracut, where it cp -a a bunch of files from / to /var/tmp/dracut to create the initramfs forcing us the me to allow dracut to manage and relabel a lot of files
Quoted 21 lines
* Create a new symbolic link,
/etc/httpd/alias.new, that points to the new directory.* Rename the
/etc/httpd/alias.newsymbolic link to/etc/httpd/alias.* Recursively delete the old directory.
* Reload (SIGUSR1) httpd, so it will start using the new certificate. (Actually, systemd does this in an ExecStartPost.)
Signature · 9 lines
======================================================================== Ian Pilcher [email protected] -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift