i am using aws rhel 8 linux instance with tomcat folder mounted from EFS in AWS and using user ec2-user with full permissions on nfs mount data (tomcat folder) able to create delete files on /opt/mytomcat. (directory)
when i try to start directly from bin /opt/mytomcat/tomcat/bin/startup.sh working fine but when i try to run from /etc/systemd/system/tomcat.service it didnt worked i am sure my settings are correct , if i disable my selinux tomcat.service works fine.
Error :sudo systemctl start tomcat.service
tomcat.service: Failed to execute command: Permission denied Dec 14 10:58:02 ip-xxxxxxxx-2.compute.internal systemd[8827]: `
tomcat.service: Failed at step EXEC spawning
` `/opt/mytomcat/bin/startup.sh: Permission denied`
/opt/mytocmat/tomcat/startup.sh has context system_u:object_r:nfs_t:s0, should be system_u:object_r:usr_t:s0
when run audit2allow to find more details its show below to enabl nfs_t file
sudo audit2allow -a
#============= init_t ==============
allow init_t nfs_t:file { execute open read };
based on above i have tried to change permission on my nfs(efs aws drive) drive
[Tuesday 16:48] Rajesh Dandamudi sudo semanage fcontext -a -t init_t "/opt/mytomcat(/.*)?"
sudo restorecon -R -v /opt/mytomcat/
above command runs but nothing changes when check its still shows same its still same
system_u:object_r:nfs_t:s0. instead of init_t not sure how to fix it i am new selinux
my nfs drive mounting and working fine able to edit / update files without any issues
[ec2-user@ip-10-xxxxx ~]$ ls -lZ /opt/mytomcat
total 2273208
drwxr-x---. 2 ec2-user ec2-user system_u:object_r:**nfs_t**:s0 6144 Dec 10 18:11 audit
-rw-r-----. 1 ec2-user ec2-user system_u:object_r:nfs_t:s0 7727677 Dec 9 21:58 mytomcat
can some please help me , as i am new to selinux security bits
A few things you could try doing are:
chmod +x startup.sh)In my experience these kinds of problems seem to have a very simple root cause that may have been overlooked.