Skip to content

Issue 7391 - Harden systemd service unit#7392

Draft
progier389 wants to merge 4 commits into389ds:mainfrom
progier389:i7391
Draft

Issue 7391 - Harden systemd service unit#7392
progier389 wants to merge 4 commits into389ds:mainfrom
progier389:i7391

Conversation

@progier389
Copy link
Copy Markdown
Contributor

@progier389 progier389 commented Apr 9, 2026

Set NoNewPrivileges and MemoryDenyWriteExecute settings in systemd unit

Issue: #7391

Reviewed by: ?

Summary by Sourcery

Enhancements:

  • Strengthen systemd SNMP service units with additional privilege and memory protection options.

@progier389 progier389 added the work in progress Work in Progress - can be reviewed, but not ready for merge. label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@packit-as-a-service
Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo dnf install -y 'dnf*-command(copr)'
  • dnf copr enable packit/389ds-389-ds-base-7392
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Comment thread rpm/389-ds-base.spec.in Outdated
type=AVC msg=audit(1775741107.400:9691): avc: denied { nnp_transition } for pid=980206 comm="(ns-slapd)" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:dirsrv_t:s0 tclass=process2 permissive=0
type=AVC msg=audit(1775833368.436:10776): avc: denied { nnp_transition } for pid=1113882 comm="(ap-agent)" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:dirsrv_snmp_t:s0 tclass=process2 permissive=0
type=AVC msg=audit(1775833368.442:10778): avc: denied { read } for pid=1113882 comm="ldap-agent" name="ldap-agent.conf" dev="dm-0" ino=12772110 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:dirsrv_config_t:s0 tclass=file permissive=0
type=AVC msg=audit(1775834425.008:10833): avc: denied { dac_override } for pid=1114135 comm="ldap-agent" capability=1 scontext=system_u:system_r:dirsrv_snmp_t:s0 tcontext=system_u:system_r:dirsrv_snmp_t:s0 tclass=capability permissive=0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dac_override is concerning, I think we should change the default user for ldap-agent to dirsrv, instead of running it as root.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that there should not be any dac_ovrride
But if I remember rightly ldap-agent uid must be root to be able to connect to snmpd.
IMHO the permission of some config files (memory map ? ldap-agent.conf ? dse.ldif ? ) are wrong and should allow read to dirsrv group

Comment thread rpm/389-ds-base.spec.in
if [ -f /usr/sbin/sestatus ] ; then
pushd /var/run/dirsrv >/dev/null
/usr/bin/audit2allow -M ns-slapd-test >/dev/null <<!
type=AVC msg=audit(1775741107.400:9691): avc: denied { nnp_transition } for pid=980206 comm="(ns-slapd)" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:dirsrv_t:s0 tclass=process2 permissive=0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to file a bug against selinux-policy in Fedora and RHEL if want to make this work.

Copy link
Copy Markdown
Contributor Author

@progier389 progier389 Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to file a bug against selinux-policy in Fedora and RHEL if want to make this work.

Definitively !
Current work-around is only for test purpose.
We need to change the SELinux before being able to merge this PR
But something looks strange with snmp:

snmpwalk -v3 -u user_name -M /usr/share/snmp/mibs:/usr/share/dirsrv/mibs/  -l AuthPriv -m +RHDS-MIB -A authentication_password -a SHA -X private_password -x AES localhost .1.3.6.1.4.1.2312.6.1.1
RHDS-MIB::dsAnonymousBinds.389 = Counter64: 0
RHDS-MIB::dsUnAuthBinds.389 = Counter64: 0
RHDS-MIB::dsSimpleAuthBinds.389 = Counter64: 0
RHDS-MIB::dsStrongAuthBinds.389 = Counter64: 0
RHDS-MIB::dsBindSecurityErrors.389 = Counter64: 0
...

but:

 ldapsearch -H ldap://localhost:389 -D "cn=directory manager" -w secret12 -b cn=snmp,cn=monitor
# extended LDIF
#
# LDAPv3
# base <cn=snmp,cn=monitor> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# snmp, monitor
dn: cn=snmp,cn=monitor
objectClass: top
objectClass: extensibleObject
cn: snmp
anonymousbinds: 0
unauthbinds: 0
simpleauthbinds: 4
strongauthbinds: 0
bindsecurityerrors: 1
...

od -x /var/run/dirsrv/slapd-i2.stats seems ok
but I do not see any error in dirsrv-agent log nor in dirsrv logs and no AVC is reported ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026-04-13 13:18:42 Opening stats file (/run/dirsrv/slapd-localhost.stat) for server: 389
2026-04-13 13:18:42 Unable to open stats file (/run/dirsrv/slapd-localhost.stat) for server: 389

But the file name is /run/dirsrv/slapd-localhost.stats. Looks like a regression from 00a3e07.

Should be:

-                                snprintf(serv_p->stats_file, vlen + strlen(instancename) + 7,
+                                snprintf(serv_p->stats_file, vlen + strlen(instancename) + 8,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: In the mean time I realised that the problem was occuring in main branch too and
created
#7406

@progier389
Copy link
Copy Markdown
Contributor Author

progier389 commented Apr 13, 2026

Created https://redhat.atlassian.net/browse/RHEL-167849 to update RHEL SELinux policy
and https://bugzilla.redhat.com/show_bug.cgi?id=2457951 for Fedora

@progier389
Copy link
Copy Markdown
Contributor Author

Apparently the following command avoid the dac_override
chmod 770 /run/dirsrv

@progier389 progier389 marked this pull request as draft April 22, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

work in progress Work in Progress - can be reviewed, but not ready for merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants