Hi gonzalo,
With this diff Suricata no longer drops privileges: it keeps running
as root even with --user/--group or the run-as: _suricata that the
port puts in suricata.yaml.
The diff drops the patch-src_suricata_c hunk that called
SCSetUserID() before SCPledge() (8.0 split SuricataMain(), so the old
context no longer applies). The rest is still there: the "#if 0"
hunks make --user/--group accepted, and patch-src_util-privs_c still
defines SCSetUserID(), but nothing calls it any more. Upstream has
no privilege drop without libcap-ng (SCDropMainThreadCaps() is an
empty macro), so the port's call is the only one.
How to reproduce (8.0/amd64, the diff as posted, make package,
pkg_add):
# install -d -o _suricata -g _suricata /var/run/suricata /var/log/suricata
# suricata -c /etc/suricata/suricata.yaml -i lo0 \
--user _suricata --group _suricata -D \
--pidfile /var/run/suricata/suricata.pid
# ps -o user,uid,ruid,svuid,rgid,svgid -p $(cat
/var/run/suricata/suricata.pid)
USER UID RUID SVUID RGID SVGID
root 0 0 0 0 0
# ps -o user,pledge -p $(cat /var/run/suricata/suricata.pid)
USER PLEDGE
root stdio,rpath,wpath,cpath,fattr,unix,dns,bpf
With the patch below (on top of your diff) it is 800 everywhere
(_suricata), pledged as before.
Index: patches/patch-src_suricata_c
--- patches/patch-src_suricata_c
+++ patches/patch-src_suricata_c
@@ -22,3 +22,11 @@
SCLogError("libcap-ng is required to"
" drop privileges, but it was not compiled into Suricata.");
return TM_ECODE_FAILED;
+@@ -3192,5 +3192,7 @@ void SuricataPostInit(void)
+ SystemHugepageSnapshotDestroy(prerun_snap);
+ SystemHugepageSnapshotDestroy(postrun_snap);
+ }
++ if (suricata.do_setuid || suricata.do_setgid)
++ SCSetUserID(suricata.userid, suricata.groupid);
+ SCPledge();
+ }
(The do_setuid/do_setgid guard keeps suricata usable by a non-root
user without run-as, e.g. -r on a pcap file; the 7.0.7 call was
unconditional.)
8.0.8 is out. I tested it the same way: your diff +
the fix, SURICATA_V 8.0.8, SUPDATE_V 1.3.8 (the bundled one), new
distinfo. In 8.0.8 SCPledge() moved earlier in SuricataPostInit(),
before the threads are un-paused (upstream ticket #8300), so the
hunk above no longer applies there and moves with it:
+@@ -3184,6 +3184,8 @@ void SuricataPostInit(void)
+
+ /* pledge before allowing threads to continue to avoid an issue with pcap
file directory mode,
+ * see ticket #8300. */
++ if (suricata.do_setuid || suricata.do_setgid)
++ SCSetUserID(suricata.userid, suricata.groupid);
+ SCPledge();
+
+ /* Un-pause all the paused threads */
Nothing else needed patching: the other patches apply with offsets,
and PLIST only gains share/suricata/rules/sip-events.rules. I also
built it with Hyperscan by dropping the "prevent textproc/hyperscan"
CONFIGURE_ENV block and adding:
WANTLIB += hs
LIB_DEPENDS += textproc/hyperscan,avx2
CONFIGURE_ARGS += --with-libhs-includes=${LOCALBASE}/include/hs \
--with-libhs-libraries=${LOCALBASE}/lib
Test report, OpenBSD 8.0/amd64 (KVM guest, 4 vCPU), 8.0.8 + fix +
Hyperscan: make fake 509 s, make package OK, the package installs
with pkg_add, build-info says "Hyperscan support: yes", the binary
links libhs, suricata -T passes with the default suricata.yaml and
with mpm-algo/spm-algo set to hs, live pcap on lo0 starts in 1 s,
and the engine runs as _suricata (uid/ruid/svuid/rgid/svgid 800),
pledged. The same check on 8.0.6: root with your diff as posted,
_suricata with the fix.
Pierre Warnier