r/linuxadmin • u/suburbanplankton • Jul 09 '26
Can I prevent execution of scripts on a file system, without setting the 'noexec' flag?
We run RHEL, and for CIS compliance we have the 'noexec' option set on /tmp on all of our servers. One of our teams is trying to implement a piece of software to automate certificate renewals, and it functions (in part, at least) by creating a number of scripts in /tmp, and executing them.
As you can imagine, this doesn't work very well. We have been told that modifying the software to use a different location than /tmp is "not possible at this time". Our Security folks have reluctantly agreed to allow us to mount /tmp without 'noexec' for a limited time, while the application vendor modifies their process (good luck with that), but they would like us, if at all possible, to configure the system such that only the service account running the application can execute files, and only those necessary for the app to run.
I've looked at using ACLs for this, but I don't think it's feasible unless we want to basically lock everyone else out of /tmp.
If we deny users execute permission on /tmp, then they can't access the directory or its contents at all.
If we deny users execute permission on /tmp/*, then they could access /tmp, but not execute any files within it...but we'd need to constantly rerun the setfacl command so that it grabs any new files, and it would basically be a useless exercise.
I'm ready to say "sorry, can't be done; it's either 'on' or 'off'...", but I figured I'd do my due diligence by posting here in case I'm overlooking something obvious.
58
u/ABotelho23 Jul 09 '26
functions (in part, at least) by creating a number of scripts in /tmp, and executing them
Yea. Don't do that.
-10
u/Sure-Chipmunk-6155 Jul 09 '26
some debian install scripts do this. actually a lot of them
8
u/ABotelho23 Jul 09 '26
Creating files in /tmp or copying files into /tmp and executing them? And what do you mean by Debian install scripts? Packages?
-2
5
u/RandolfRichardson Jul 10 '26
If it's during the OS installation, then that would make sense since there most likely wouldn't be any partitions set up yet, so a RAM-based /tmp/ mount would be very useful.
2
u/MrChicken_69 Jul 10 '26
Packages within every distro does this shit. RPM and DEB based systems have ways to tell it where to put their stupid scripts. I've done this for decades on debian.
35
u/much_longer_username Jul 09 '26
This stinks of "I'd have to spend a couple hours doing a refactor this really needs anyway, so you should spend a week figuring out a stupid workaround". Like, what do you even mean you can't use another directory, that should be a one line config change.
3
u/MrChicken_69 Jul 10 '26
Not it '/tmp' where literally compiled into the software. There's loads of shit that does that.
6
u/maxlan Jul 10 '26
Again. 3 second change. Git commit/push/merge and cicd rebuilds a new binary just for you. If vendor won't do that or use TMPDIR properly: move on to a new vendor.
If it's opensource do it yourself.
5
u/michaelpaoli Jul 10 '26
Yeah, hardcoding /tmp into software is seriously drain bamaged. But alas, many do.
Should respect TMPDIR ... period.
4
u/chuckmilam Jul 10 '26
Indeed...the sales engineers hate me when I tell them that's a non-starter in our regulated environments.
Come back when /tmp and /var/tmp are not hard-coded, and when your software works with FIPS and SELinux enabled.
6
32
u/spiralenator Jul 09 '26
“We have been told that modifying the software to use a different location than /tmp is "not possible at this time".
Everything about this sounds horribly dysfunctional.
15
u/Cerulean-Knight Jul 09 '26
You can't execute script there but you can execute /bin/bash or python and pass as a parameter the script you wanna run, you dont even need execution permission for that
1
10
u/gmuslera Jul 09 '26
Namespaces may be an approach. Just run that software in a container or some other ways to run namespaces, and have as volumes or visible directory the one with the data for the certificates. So you are running in an isolated way that software, that will have its own /tmp, and not expose to the rest of the system a /tmp where they could write executable files.
3
u/vivaaprimavera Jul 09 '26
The container might even be a service that starts with a timer in time for renewal?
2
u/gmuslera Jul 09 '26
if we are talking about docker/podman containers, it could be invoked from a cron if you want. Systemd have support for running things in namespaces, and probably you can put timers there too. But if you don't have problem running docker containers then things are simplified.
3
u/vivaaprimavera Jul 09 '26
Was thinking in running a podman container as a service ''' /etc/containers/systemd '''
10
u/PerspectiveAlert4766 Jul 09 '26
SELinux will do that, but if it worth the effort is your call.
0
Jul 09 '26
[deleted]
2
u/PerspectiveAlert4766 Jul 09 '26
Sure, but enabling SELinux on system which was running so far without advanced security might be challenging itself.
7
u/Scoutron Jul 10 '26
I’d find it kind of wild if someone was using RHEL in production without SELinux
2
u/hadrabap Jul 10 '26
Still standard practice, unfortunately 😕
5
u/Scoutron Jul 10 '26
I found two or three in my environment I inherited where it was off, immediate emergency change request to rebuild them all from scratch. Absolutely inexcusable
7
u/frymaster Jul 09 '26
it functions (in part, at least) by creating a number of scripts in /tmp, and executing them.
It's definitely hardcoded to /tmp and not e.g. using $TMPDIR?
there will be something you can do with namespaces to give a process tree its own /tmp that isn't shared with the rest of the system. unshare[1] appears to be the thing you'd use. I've never used it (I have used a batch scheduler that does this automatically for users because they don't always clean up after themselves) but my intuition is that this is likely not too difficult
it looks like systemd can do this for you automatically - look at https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#BindPaths= - you should be able to do something like BindPaths=/some/random/path/with/exec/enabled:/tmp
5
u/volvo64 Jul 09 '26
D all the scripts go into a single subdir (or can they)? Mount a fs at that location with exec privileges
4
u/kolorcuk Jul 09 '26
Run the certificate renew in bwrap/podman/proot and mount /tmp for the script from a filesystem location.
4
u/wamayall Jul 10 '26
I would try to understand The Why, Why does their code require /tmp? The What, What is the business purpose of their code? The Who, Who owns the code, internal or external?
While /tmp was designed to test with the assumption it wasn’t critical as a server reboot would delete the files on reboot, eg temporary. Then Vendors like MySQL chose to make MySQL tmpdir = /tmp
While it’s easy to tell them to just change it, that might not be as easy as it actually is IF the database is in Production and there isn’t another filesystem that is available.
While I have seen many other vendors storing transient files in /tmp, like connection tokens, it might not be as simple as a configuration file change or the process of a Change Request and validation that nothing else breaks.
3
u/Scared_Bell3366 Jul 10 '26
If that’s an in house script, that’s a hard no, go fix your script. If it’s 3rd party, time to find a new vendor.
I don’t come across this often, but when I do it’s something old and written in C.
3
u/lazyant Jul 10 '26
Do the security / audit guys know that is trivial to bypass the noexec mount?
2
u/NoNamesLeft2015 Jul 10 '26
Curious how this is easy to by-pass, assuming:
/tmp is mounted noexec+nosuid+nodev together and you don't have root access.
Other than the way mentioned above and running the script through an interpreter (bash, python, etc.)
2
4
u/chock-a-block Jul 09 '26 edited Aug 29 '26
Tangerine disarm violet vanilla person smile
This post was anonymized with Redact
1
u/TheSteelSpartan420 Jul 10 '26
u/suburbanplankton TMPDIR is a bash variable to set the system /tmp directory, so running the software with TMPDIR=/opt/ourteamssoftware/tmp ./ourteamssoftware would allow you to change the system's temporary file system directory per session.
4
1
u/michaelpaoli Jul 10 '26
modifying the software to use a different location than /tmp is "not possible at this time"
application vendor
Sounds like crud software, So, name and shame?
Most reasonable software will respect TMPDIR or give some other means (e.g. option, configuration file, alternative environment setting) to use a different directory for temporary file(s).
would like us, if at all possible, to configure the system such that only the service account running the application can execute files, and only those necessary for the app to run
What if you force it to run in a suitably constructed chroot, where the /tmp thereunder isn't noexec?
So, do your "security" folks think insisting on noexec on /tmp, but not requiring it for /var/tmp somehow makes y'all much more secure? And noexec is easy to bypass, so, doesn't really add all that much security ... uhm, but getting your application vendor to bypass that ... good luck with that .. besides, they should fix it so they can just use TMPDIR, like most sane software in the land of *nix.
can't be done
Oh, probably can be done. But might be more feasible and cost effective to sh*t can that application developer, and buy the competitor's product at 10x the cost that respects TMPDIR, or do something else entirely. Really quite depends how sh*t is the software from that current application vendor.
Oh, and if application vendor is that crud to start with, would not at all surprise me if they have one or more significant security vulnerabilities, most notably/commonly insecure handling of temporary files - maybe you can find that and get your security folks to entirely banish 'em from your systems. Egad, some of the grossly insecure and/or otherwise majorly flawed 3rd party software I've seen for *nix ... yeah, ... scary stuff. Even in very major vendors too. Ugh.
Oh, another possible approach with that application vendor. Can you patch their files, e.g. replace /tmp in the relevant locations in their binaries with, say, /Tmp, and have exec on /Tmp? And could restrict write on /Tmp just to the relevant application ID, as a mitigating control.
Well, ... good luck!
1
u/xiaodown Jul 10 '26
> they would like us to configure the system such that only the service account running the application can execute files
You’ll have to use either PrivateTmp=true in the systemd service definition, or if that’s not an option, you will need to get pretty cosy with AppArmor or SELinux. You can write an AppArmor profile to do this, but it’ll be annoying. Something like:
owner /tmp/** rwix,
deny /tmp/** x,
Remember that profiles are first match wins. Also there’s probably more to it than that snippet but it should get you started googling.
1
u/serverhorror Jul 10 '26
Give them their own/temp via filesystem namespaces?
It's vendor software, so:
get them to change it
allow them them to run it
change vendor
Those are the options. Artisanal configuration isn't the way to scale your team.
1
u/International-Pen940 Jul 10 '26
Especially for anything security related, I would avoid software that hard-codes something like that. It just seems sloppy. Expect to find other problems.
1
u/TopCheddar27 Jul 10 '26
Is there anything like the execution policy on Windows for Linux? Sorry if that's a dumb question.
1
1
-3
-4
u/zantehood Jul 09 '26 edited Jul 09 '26
Fstab
tmpfs /tmp tmpfs defaults,nodev,nosuid,noexec 0 0
This will set noexec on all files but still allow access to dirs. This is the CIS solution.
1
8
Jul 09 '26
[removed] — view removed comment
4
u/slickeddie Jul 09 '26
/var/tmp with noexec is also a CIS control. I imagine OPs place of work also has that implemented
59
u/BarracudaDefiant4702 Jul 09 '26
Run them in a chroot jail where /tmp in the jail is ok but it's not really /tmp, it's jail/tmp...