I have a web application which uses sudo to invoke python scripts as the user under which the application runs (NO root access). Is there any reason why sudo would would require sys_ptrace access for this? I only get this violation intermittenly, and not with every call to sudo. Here's the violation:
Summary:
SELinux is preventing sudo (httpd_t) "sys_ptrace" to <Unknown> (httpd_t).
Detailed Description:
SELinux denied access requested by sudo. It is not expected that this access is required by sudo and this access may signal an intrusion attempt. It is also possible that the specific version or configuration of the application is causing it to require additional access.
Allowing Access:
You can generate a local policy module to allow this access - see FAQ (http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385) Or you can disable SELinux protection altogether. Disabling SELinux protection is not recommended. Please file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against this package.
Additional Information:
Source Context system_u:system_r:httpd_t Target Context system_u:system_r:httpd_t Target Objects None [ capability ] Source sudo Source Path /usr/bin/sudo Port <Unknown> Host myhost.mydomain.com Source RPM Packages sudo-1.7.2p1-29.el5_10 Target RPM Packages Policy RPM selinux-policy-2.4.6-351.el5 Selinux Enabled True Policy Type targeted MLS Enabled True Enforcing Mode Enforcing Plugin Name catchall Host Name myhost.mydomain.com Platform Linux myhost.mydomain.com 2.6.18-419.el5 #1 SMP Fri Feb 24 22:06:09 UTC 2017 i686 i686 Alert Count 359 First Seen Tue Oct 8 09:24:50 2013 Last Seen Tue Aug 21 10:26:26 2018 Local ID 717eb9a4-cc7f-4ed1-b638-5db1a841abe4 Line Numbers
Raw Audit Messages
host=myhost.mydomain.com type=AVC msg=audit(1534872386.726:9642): avc: denied { sys_ptrace } for pid=8458 comm="sudo" capability=19 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:httpd_t:s0 tclass=capability
host=myhost.mydomain.com type=SYSCALL msg=audit(1534872386.726:9642): arch=40000003 syscall=3 success=yes exit=166 a0=1a a1=b7ff4000 a2=400 a3=89cabf0 items=0 ppid=8979 pid=8458 auid=4294967295 uid=48 gid=48 euid=0 suid=0 fsuid=0 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="sudo" exe="/usr/bin/sudo" subj=system_u:system_r:httpd_t:s0 key=(null)
Thank You,
Nataraj
On 08/21/2018 12:27 PM, Nataraj wrote:
I have a web application which uses sudo to invoke python scripts as the user under which the application runs (NO root access). Is there any reason why sudo would would require sys_ptrace access for this? I only get this violation intermittenly, and not with every call to sudo. Here's the violation:
Most likely you can just dontaudit this access. sys_ptrace is often caused by processes trying to read content in /proc.
Summary:
SELinux is preventing sudo (httpd_t) "sys_ptrace" to <Unknown> (httpd_t).
Detailed Description:
SELinux denied access requested by sudo. It is not expected that this access is required by sudo and this access may signal an intrusion attempt. It is also possible that the specific version or configuration of the application is causing it to require additional access.
Allowing Access:
You can generate a local policy module to allow this access - see FAQ (http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385) Or you can disable SELinux protection altogether. Disabling SELinux protection is not recommended. Please file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against this package.
Additional Information:
Source Context system_u:system_r:httpd_t Target Context system_u:system_r:httpd_t Target Objects None [ capability ] Source sudo Source Path /usr/bin/sudo Port <Unknown> Host myhost.mydomain.com Source RPM Packages sudo-1.7.2p1-29.el5_10 Target RPM Packages Policy RPM selinux-policy-2.4.6-351.el5 Selinux Enabled True Policy Type targeted MLS Enabled True Enforcing Mode Enforcing Plugin Name catchall Host Name myhost.mydomain.com Platform Linux myhost.mydomain.com 2.6.18-419.el5 #1 SMP Fri Feb 24 22:06:09 UTC 2017 i686 i686 Alert Count 359 First Seen Tue Oct 8 09:24:50 2013 Last Seen Tue Aug 21 10:26:26 2018 Local ID 717eb9a4-cc7f-4ed1-b638-5db1a841abe4 Line Numbers
Raw Audit Messages
host=myhost.mydomain.com type=AVC msg=audit(1534872386.726:9642): avc: denied { sys_ptrace } for pid=8458 comm="sudo" capability=19 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:httpd_t:s0 tclass=capability
host=myhost.mydomain.com type=SYSCALL msg=audit(1534872386.726:9642): arch=40000003 syscall=3 success=yes exit=166 a0=1a a1=b7ff4000 a2=400 a3=89cabf0 items=0 ppid=8979 pid=8458 auid=4294967295 uid=48 gid=48 euid=0 suid=0 fsuid=0 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="sudo" exe="/usr/bin/sudo" subj=system_u:system_r:httpd_t:s0 key=(null)
Thank You,
Nataraj
CentOS mailing list CentOS@centos.org https://lists.centos.org/mailman/listinfo/centos
On Tue, Aug 21, 2018 at 12:27:53PM -0700, Nataraj wrote:
Source RPM Packages sudo-1.7.2p1-29.el5_10 Policy RPM selinux-policy-2.4.6-351.el5 Platform Linux myhost.mydomain.com 2.6.18-419.el5 #1 SMP Fri Feb 24 22:06:09 UTC 2017 i686 i686
CentOS 5 was end of life on 31 March, 2017. There have bee no updates for over a year.
Might as well turn off SELinux, you're so behind on security updates it probably doesn't matter.
On 08/21/2018 12:41 PM, Jonathan Billings wrote:
On Tue, Aug 21, 2018 at 12:27:53PM -0700, Nataraj wrote:
Source RPM Packages sudo-1.7.2p1-29.el5_10 Policy RPM selinux-policy-2.4.6-351.el5 Platform Linux myhost.mydomain.com 2.6.18-419.el5 #1 SMP Fri Feb 24 22:06:09 UTC 2017 i686 i686
CentOS 5 was end of life on 31 March, 2017. There have bee no updates for over a year.
Might as well turn off SELinux, you're so behind on security updates it probably doesn't matter.
Thank you. I'm well aware that CentOS 5 is eol, and hoping to replace this server soon. I'm sitting here right now in heavy smoke (which has been going on since early June) in Northern Ca, just miles from huge fires and have spent the last 3 years rebuilding after damage in a 2015 fire. It kind of shakes up ones life a little bit. In the meantime, keeping selinux enabled helps me to keep the server from getting broken into. Since incoming services are limited for the most part to my userbase, I am doing very well so far. There is no remote login access.
Thank you,
Nataraj
On Aug 21, 2018, at 1:27 PM, Nataraj incoming-centos@rjl.com wrote:
I have a web application which uses sudo to invoke python scripts as the user under which the application runs (NO root access).
Why is the web app not running with that user’s permissions in the first place?
If your answer is that it needs root access to bind to port 80, there are two common solutions:
1. Start the service as root, set up the port 80 listener, then drop privileges internally with getpwent(“myuser”) and setuid(my_uid).
2. Use an HTTP[S] proxy server, such as Apache with mod_proxy configured. Bind the actual web app to localhost and a high-numbered random port, then forward external port 80 hits to the internal service. This method has the additional advantage that you can use the path part of the URL to relieves the web app of having to serve hits for the static resources — *.js, *.png, *.css… — which can speed the application up.
On 08/21/2018 02:20 PM, Warren Young wrote:
On Aug 21, 2018, at 1:27 PM, Nataraj incoming-centos@rjl.com wrote:
I have a web application which uses sudo to invoke python scripts as the user under which the application runs (NO root access).
Why is the web app not running with that user’s permissions in the first place?
If your answer is that it needs root access to bind to port 80, there are two common solutions:
Start the service as root, set up the port 80 listener, then drop privileges internally with getpwent(“myuser”) and setuid(my_uid).
Use an HTTP[S] proxy server, such as Apache with mod_proxy configured. Bind the actual web app to localhost and a high-numbered random port, then forward external port 80 hits to the internal service. This method has the additional advantage that you can use the path part of the URL to relieves the web app of having to serve hits for the static resources — *.js, *.png, *.css… — which can speed the application up.
CentOS mailing list CentOS@centos.org https://lists.centos.org/mailman/listinfo/centos
The php code runs as user apache under the webserver. If the php ran as the app users it would have full access to all of the data in the app. Using sudo the app can only invoke one specific python script (which is the command name in the sudoers file) to do what it needs to do, without having access to the rest of the apps data and other python scripts used by other functions in the app). Could be that I'm not seeing something, but this approach seems sensible to me, though I could be convinced otherwise if I could see where running the php as the app users, would make more sense.
It could be that giving sudo sys_ptrace access could increase the risk to the security of the system, but giving the php code app user access, increases the risk of data compromise in the app.
Thank You, Nataraj
On Aug 21, 2018, at 4:34 PM, Nataraj incoming-centos@rjl.com wrote:
On 08/21/2018 02:20 PM, Warren Young wrote:
On Aug 21, 2018, at 1:27 PM, Nataraj incoming-centos@rjl.com wrote:
I have a web application which uses sudo to invoke python scripts as the user under which the application runs (NO root access).
Why is the web app not running with that user’s permissions in the first place?
The php code runs as user apache under the webserver.
Okay, that’s useful to know, and it’s something we’re just now learning. You’ll get better advice if you include such details when using for help.
If the php ran as the app users it would have full access to all of the data in the app.
…and that’s a problem why, exactly? What could happen if that were allowed?
I understand that you’re creating a privilege separation scheme here, but if you want good advice, we need to know what you want to achieve with the scheme and why that is necessary.
What resources does this non-php user own that user php must not be allowed to have access to? Once we know that, we can advise on how to protect those resources.
Using sudo the app can only invoke one specific python script (which is the command name in the sudoers file) to do what it needs to do, without having access to the rest of the apps data and other python scripts used by other functions in the app).
Another way to go about it would be to have the background service running as the non-php user, then provide access to it over the many IPC mechanisms available in a Linux system: named pipes, SysV message queues, shared memory… Add to that all of the higher-level services available like message-oriented middleware:
https://en.wikipedia.org/wiki/Category:Message-oriented_middleware
Such services let one process tell another, “Hey, I need you to do something for me,” then wait for the answer, received as a single coherent message. Many of these schemes let you split that worker process off into a separate machine, or even a cluster of machines.
That could help you to get off CentOS 5: move the worker process onto a C7 box, then when that’s well-validated, move the PHP bits over.
Or, move the PHP bits to a *second* C7 box, and now you’ve got much stronger privilege separation. You may remember all of the ways that Shellshock — a local-only exploit — was able to be exploited over HTTP, because local web app code was using the shell, thus converting it into a remote-exploitable security hole. By separating the worker processes to a separate machine, that now can’t happen on the second box. If the front-end box has no sensitive material on it, that’s enough security: just wipe it and re-image it if it’s ever compromised.
However you do this, these mechanisms give you hard privilege separation without SELinux bugging you.
I could be convinced otherwise if I could see where running the php as the app users, would make more sense.
That depends on whether the boundary between user php and this unknown “appuser” is bidirectional or not.
If there are things owned by user “php” that “appuser” should not see, then continuing to run the web app as two separate users makes sense.
If “appuser” can be said to own everything in the web app, and the only reason you’re converting user php privileges to “appuser” privileges is so you don’t have to give user php access to everything in the web app, then I’d say my prior suggestion holds.
Now that I know you’re using PHP, I can recommend something like PHP-FPM:
That’s the old external project. It’s now part of the PHP core:
https://secure.php.net/manual/en/install.fpm.php
You’ll have to use the old version with C5, though, as that happened after C5 was released.
FPM isn’t the only way to go, just one idea, which happens to be well-supported within the PHP community.
Regardless of the exact method, this lets you run your PHP code as a non-php user, letting Apache proxy to it using mod_fcgi. Now you’ve got strong separation between things Apache is allowed to read and things it must talk down through PHP to get access to.
It could be that giving sudo sys_ptrace access could increase the risk to the security of the system
Once you give a process ptrace ability, it’s pretty much game over when it comes to security. The scope of what one process can do to another via ptrace(2) is HUUUUGE. I’d very much resist placating SELinux in this way.
SELinux might in fact be warning you about a real attack here, which would explain why it’s intermittent.
On 08/21/2018 05:45 PM, Warren Young wrote:
I could be convinced otherwise if I could see where running the php as the app users, would make more sense.
That depends on whether the boundary between user php and this unknown “appuser” is bidirectional or not.
If there are things owned by user “php” that “appuser” should not see, then continuing to run the web app as two separate users makes sense.
If “appuser” can be said to own everything in the web app, and the only reason you’re converting user php privileges to “appuser” privileges is so you don’t have to give user php access to everything in the web app, then I’d say my prior suggestion holds.
Now that I know you’re using PHP, I can recommend something like PHP-FPM:
https://php-fpm.org/
That’s the old external project. It’s now part of the PHP core:
https://secure.php.net/manual/en/install.fpm.php
You’ll have to use the old version with C5, though, as that happened after C5 was released.
FPM isn’t the only way to go, just one idea, which happens to be well-supported within the PHP community.
Regardless of the exact method, this lets you run your PHP code as a non-php user, letting Apache proxy to it using mod_fcgi. Now you’ve got strong separation between things Apache is allowed to read and things it must talk down through PHP to get access to.
It could be that giving sudo sys_ptrace access could increase the risk to the security of the system
Once you give a process ptrace ability, it’s pretty much game over when it comes to security. The scope of what one process can do to another via ptrace(2) is HUUUUGE. I’d very much resist placating SELinux in this way.
SELinux might in fact be warning you about a real attack here, which would explain why it’s intermittent. _______________________________________________
Thank you, this information was helpful. I will solve the problem without allowing ptrace capability.
Nataraj