-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harden systemd service #27
Harden systemd service #27
Conversation
Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
AmbientCapabilities=CAP_SYS_RAWIO | ||
CapabilityBoundingSet=CAP_SYS_RAWIO | ||
DeviceAllow=/dev/null rw | ||
DeviceAllow=block-sd r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should conflict with many non-sd devices, e.g. usb, scsi, raid, etc. Not something i would like to add by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add all remaining block devices:
DeviceAllow=block-blkext r
DeviceAllow=block-device-mapper r
DeviceAllow=block-md r
DeviceAllow=block-mdp r
DeviceAllow=block-sr r
I think USB and SCSI are block-sd
.
CapabilityBoundingSet=CAP_SYS_RAWIO | ||
DeviceAllow=/dev/null rw | ||
DeviceAllow=block-sd r | ||
DevicePolicy=strict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. May be we can add it commented out, as an example.
ReadOnlyPaths=-/ | ||
ReadWritePaths=-/var/lib/smartmontools | ||
RemoveIPC=yes | ||
RestrictAddressFamilies=AF_UNIX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would disallow smartd hooks to send an emails or to use any hooks with TCP interaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then also IPAddressDeny=any
won't be OK.
StateDirectory=smartmontools | ||
SystemCallArchitectures=native | ||
SystemCallFilter=@system-service | ||
SystemCallFilter=~@chown @clock @cpu-emulation @debug @ipc @module @mount @obsolete @privileged @raw-io @reboot @resources @swap memfd_create mincore mlock mlockall personality |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - not sure if it would not cause any issues with existing device support.
Thank you for PR. Not sure if we can accept it as-is. Few notes
What i can probably recommend is to document this settings on our wiki (i can help to create a page for that) and work with distribution vendors to secure their copies of the units if needed. I would like to keep our unit as simple as possible. |
ExecStart=/usr/local/sbin/smartd -n $smartd_opts | ||
Group=disk | ||
IPAddressDeny=any | ||
LimitNPROC=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would not allow to send any mails or run any externals
Thanks for the quick review. How about commenting out the controversial lines with explanatory notes? Then a local admin could make a note of them and try to enable them. |
I will think about this approach and will ask other contributors |
Follow up: I am not convinced that there is any benefits of including this hardening to unit, commented or not commented.
So if you want that to get accepted in some form - please modify it to make sure that none of the Linux smartd functionality is affected and add some comments about every new statement in the patch, inline or as PR comment. |
Tagging @chrfranke to get another review :) |
I agree with @samm-git. Such complex settings may affect various external scripts in ways which are difficult to predict. The attack surface of smartd itself is small as it does not use network connections or IPC. The only exception is a AF_UNIX socket (/var/run/systemd/notify) if Type=notify is used. Does the current PR allow mknod() calls? If not, this may break usage of -d aacraid, -d megaraid (and legacy -d 3ware) device types. Please note that there is a old smartd option -C (--capabilities), see ticket 45. It possibly has the same effect as:
|
I am closing this PR as potentially dangerous and without clear benefits for the users. Also our systemd service unit file is provided for the reference only and expected to be changed by the OS maintainers, so better to keep it as simple as possible. |
I understand your decision. I don't think distros will see things differently, probably the expectation is to keep mail sending features etc. working. This level of hardening only works without those features. Please note that while smartd might not be target to remote exploits, it may still become a stepping stone to gain more privileges (it's actually a juicy target with root equivalent capabilities) once the attacker gets in. I'd also recommend you to try to seeing hardening as positive thing and not dangerous. |
@topimiettinen thanks for understanding. I seeing it as a positive but dangerous thing :) |
Signed-off-by: Topi Miettinen toiwoton@gmail.com