Skip to content

Running builds, scripts and automation on monitored servers

Anything that writes a program into a folder every user can write, and then runs it, looks like the first step of an attack. That is what the compromise indicators exist to notice, and it does not matter who or what does it: a person, a build or test runner, a configuration tool, a scheduled job or an automated assistant. WatchTower15 cannot tell them apart, and it does not try. You can, by choosing where your tooling writes. This page is how.

Why a program run from /tmp raises a Critical indicator, and why it stays Critical

Section titled “Why a program run from /tmp raises a Critical indicator, and why it stays Critical”

A running process whose executable lies under /tmp, /var/tmp or /dev/shm raises a process runs from a world-writable directory, which is Critical. An executable file left in those folders raises an executable file in a temporary directory: Warning in /dev/shm, Info in /tmp and /var/tmp.

These folders are shared: any account on the host can write to them, so any account can plant the program that a later run executes. Nothing in the folder tells a harmless build step from a planted one. That is why the Critical indicator is not lowered by who you are or what the program is called, and why no key or session can exempt its own activity. What you can change is where the program lies.

Give the service that builds or runs your programs its own account and its own temporary folder, closed to everyone else. With systemd, a drop-in on the service does it:

# /etc/systemd/system/<your-service>.service.d/10-known-temp.conf
[Service]
User=automation
StateDirectory=automation
StateDirectoryMode=0700
Environment=TMPDIR=/var/lib/automation/tmp
ExecStartPre=/usr/bin/install -d -m 0700 /var/lib/automation/tmp
PrivateTmp=yes

and a cleanup rule, so the folder does not fill up:

/etc/tmpfiles.d/automation.conf
e /var/lib/automation/tmp - - - 2d

The folder belongs to the account that runs your automation and is created at boot by that account, never by a web or application service account: a known folder is only as trustworthy as its owner. A program that runs from /var/lib/automation/tmp is not under /tmp, /var/tmp or /dev/shm, so neither indicator fires for it.

A script run as sh build.sh or python3 task.py runs the interpreter, which lies in a system folder. Only a script made executable and started by its own path is a program in the temporary folder. Prefer the interpreter form for anything you write to a shared folder.

Use noexec on /dev/shm, and on /tmp once nothing of yours executes there

Section titled “Use noexec on /dev/shm, and on /tmp once nothing of yours executes there”

Mount /dev/shm with noexec, and /tmp too once nothing you run needs to execute from it. The kernel then refuses to run a program from there, so the situation the indicators watch for cannot happen.

If a tool insists on a folder under /tmp or /var/tmp, declare that folder on the server profile as a known execution folder (see Disable, reconfigure, accept). An executable inside it is recorded as Info and never raises an alarm, as long as the folder is private to its owner: owned by the account that uses it (or by root), with no write access for group or others. If other users can write the folder, the finding keeps its severity and says so. Keep the folder private to its owner.

  • Accept one finding when you have looked at it and it is expected. It stays listed, and it opens again if the executable changes.
  • Reconfigure a rule on a profile or a server when a whole class of findings is expected: change its severity, or list the known folders.
  • Disable a rule on a profile or a server only when you do not want it checked there at all. The rule’s open and accepted findings then resolve, and enabling it later opens them afresh.

Members with the Security policy permission set these, every change names its reason and a review date within 12 months, and every change is recorded in the audit trail. A key stored on a monitored server should not hold the permission: it would let a compromise of that server reconfigure the indicator that watches it.