How to mount ecryptfs and preserve individual SELinux tag of underlying files?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1














I am trying to mount ecryptfs on a system that uses SELinux (e.g. Cent-OS), and I want to preserve the security tag of all individual underlying files. Using mount -o command I can set the security tag of all files, e.g.



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o context="system_u:object_r:mysqld_db_t:s0" 


which is not what I want. As far as I know, ecryptfs supports extended attributes, and functions such as ecryptfs_setxattr and ecryptfs_getxattr are defined in the file inode.c of ecryptfs kernel module.
In addition, from man mount the option fscontext seems to do exactly what I want:




The fscontext= option works for all filesystems, regardless of their xattr support. The fscontext option sets the overarching filesystem label to a specific security context. This filesystem label is separate from the individual labels on the files. It represents the entire filesystem for certain kinds of permission checks, such as during mount or file creation. Individual file labels are still obtained from the xattrs on the files themselves. The context option actually sets the aggregate context that fscontext provides, in addition to supplying the same label for individual files.




Still the following command



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o fscontext="system_u:object_r:mysqld_db_t:s0"


changes the SELinux tag of all files to system_u:object_r:mysqld_db_t:s0, even for the file /var/lib/mysql/mysql.sock with the original tag system_u:object_r:mysqld_var_run_t:so.



My questions:



1) How can I mount ecryptfs on a directory and preserve the security tags (i.e. SELinux tags) of each file?



2) Why doesn't mount -o fscontext work for ecryptfs as it suppose to?



Note: I am using mysql directory just as an example, I was able to add policy modules to SELinux and make mysqld work when ecryptfs is mounted on top. Here, I am asking for a general solution to make ecryptfs transparent to SELinux.










share|improve this question













migrated from stackoverflow.com Dec 20 '18 at 21:57


This question came from our site for professional and enthusiast programmers.














  • +1 for the migration. Good job.
    – jww
    Dec 21 '18 at 1:07
















1














I am trying to mount ecryptfs on a system that uses SELinux (e.g. Cent-OS), and I want to preserve the security tag of all individual underlying files. Using mount -o command I can set the security tag of all files, e.g.



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o context="system_u:object_r:mysqld_db_t:s0" 


which is not what I want. As far as I know, ecryptfs supports extended attributes, and functions such as ecryptfs_setxattr and ecryptfs_getxattr are defined in the file inode.c of ecryptfs kernel module.
In addition, from man mount the option fscontext seems to do exactly what I want:




The fscontext= option works for all filesystems, regardless of their xattr support. The fscontext option sets the overarching filesystem label to a specific security context. This filesystem label is separate from the individual labels on the files. It represents the entire filesystem for certain kinds of permission checks, such as during mount or file creation. Individual file labels are still obtained from the xattrs on the files themselves. The context option actually sets the aggregate context that fscontext provides, in addition to supplying the same label for individual files.




Still the following command



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o fscontext="system_u:object_r:mysqld_db_t:s0"


changes the SELinux tag of all files to system_u:object_r:mysqld_db_t:s0, even for the file /var/lib/mysql/mysql.sock with the original tag system_u:object_r:mysqld_var_run_t:so.



My questions:



1) How can I mount ecryptfs on a directory and preserve the security tags (i.e. SELinux tags) of each file?



2) Why doesn't mount -o fscontext work for ecryptfs as it suppose to?



Note: I am using mysql directory just as an example, I was able to add policy modules to SELinux and make mysqld work when ecryptfs is mounted on top. Here, I am asking for a general solution to make ecryptfs transparent to SELinux.










share|improve this question













migrated from stackoverflow.com Dec 20 '18 at 21:57


This question came from our site for professional and enthusiast programmers.














  • +1 for the migration. Good job.
    – jww
    Dec 21 '18 at 1:07














1












1








1







I am trying to mount ecryptfs on a system that uses SELinux (e.g. Cent-OS), and I want to preserve the security tag of all individual underlying files. Using mount -o command I can set the security tag of all files, e.g.



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o context="system_u:object_r:mysqld_db_t:s0" 


which is not what I want. As far as I know, ecryptfs supports extended attributes, and functions such as ecryptfs_setxattr and ecryptfs_getxattr are defined in the file inode.c of ecryptfs kernel module.
In addition, from man mount the option fscontext seems to do exactly what I want:




The fscontext= option works for all filesystems, regardless of their xattr support. The fscontext option sets the overarching filesystem label to a specific security context. This filesystem label is separate from the individual labels on the files. It represents the entire filesystem for certain kinds of permission checks, such as during mount or file creation. Individual file labels are still obtained from the xattrs on the files themselves. The context option actually sets the aggregate context that fscontext provides, in addition to supplying the same label for individual files.




Still the following command



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o fscontext="system_u:object_r:mysqld_db_t:s0"


changes the SELinux tag of all files to system_u:object_r:mysqld_db_t:s0, even for the file /var/lib/mysql/mysql.sock with the original tag system_u:object_r:mysqld_var_run_t:so.



My questions:



1) How can I mount ecryptfs on a directory and preserve the security tags (i.e. SELinux tags) of each file?



2) Why doesn't mount -o fscontext work for ecryptfs as it suppose to?



Note: I am using mysql directory just as an example, I was able to add policy modules to SELinux and make mysqld work when ecryptfs is mounted on top. Here, I am asking for a general solution to make ecryptfs transparent to SELinux.










share|improve this question













I am trying to mount ecryptfs on a system that uses SELinux (e.g. Cent-OS), and I want to preserve the security tag of all individual underlying files. Using mount -o command I can set the security tag of all files, e.g.



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o context="system_u:object_r:mysqld_db_t:s0" 


which is not what I want. As far as I know, ecryptfs supports extended attributes, and functions such as ecryptfs_setxattr and ecryptfs_getxattr are defined in the file inode.c of ecryptfs kernel module.
In addition, from man mount the option fscontext seems to do exactly what I want:




The fscontext= option works for all filesystems, regardless of their xattr support. The fscontext option sets the overarching filesystem label to a specific security context. This filesystem label is separate from the individual labels on the files. It represents the entire filesystem for certain kinds of permission checks, such as during mount or file creation. Individual file labels are still obtained from the xattrs on the files themselves. The context option actually sets the aggregate context that fscontext provides, in addition to supplying the same label for individual files.




Still the following command



mount -t ecryptfs /var/lib/mysql /var/lib/mysql -o fscontext="system_u:object_r:mysqld_db_t:s0"


changes the SELinux tag of all files to system_u:object_r:mysqld_db_t:s0, even for the file /var/lib/mysql/mysql.sock with the original tag system_u:object_r:mysqld_var_run_t:so.



My questions:



1) How can I mount ecryptfs on a directory and preserve the security tags (i.e. SELinux tags) of each file?



2) Why doesn't mount -o fscontext work for ecryptfs as it suppose to?



Note: I am using mysql directory just as an example, I was able to add policy modules to SELinux and make mysqld work when ecryptfs is mounted on top. Here, I am asking for a general solution to make ecryptfs transparent to SELinux.







linux mount selinux xattr ecryptfs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 20 '18 at 19:06







Bahram











migrated from stackoverflow.com Dec 20 '18 at 21:57


This question came from our site for professional and enthusiast programmers.






migrated from stackoverflow.com Dec 20 '18 at 21:57


This question came from our site for professional and enthusiast programmers.













  • +1 for the migration. Good job.
    – jww
    Dec 21 '18 at 1:07

















  • +1 for the migration. Good job.
    – jww
    Dec 21 '18 at 1:07
















+1 for the migration. Good job.
– jww
Dec 21 '18 at 1:07





+1 for the migration. Good job.
– jww
Dec 21 '18 at 1:07











0






active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490221%2fhow-to-mount-ecryptfs-and-preserve-individual-selinux-tag-of-underlying-files%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown
























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490221%2fhow-to-mount-ecryptfs-and-preserve-individual-selinux-tag-of-underlying-files%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown