Skip to content

Commit

Permalink
chore: systemd hardening
Browse files Browse the repository at this point in the history
加固 dbus 进程
  • Loading branch information
zsien committed Jun 25, 2024
1 parent 83b3e45 commit 204ac21
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 26 deletions.
1 change: 1 addition & 0 deletions misc/system-services/org.deepin.dde.Device1.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Name=org.deepin.dde.Device1
Exec=/usr/lib/deepin-api/device
User=root
SystemdService=dbus-org.deepin.dde.Device1.service
1 change: 1 addition & 0 deletions misc/system-services/org.deepin.dde.LocaleHelper1.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Name=org.deepin.dde.LocaleHelper1
Exec=/usr/lib/deepin-api/locale-helper
User=root
SystemdService=dbus-org.deepin.dde.LocaleHelper1.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Name=org.deepin.dde.SoundThemePlayer1
Exec=/usr/lib/deepin-api/sound-theme-player
User=deepin-sound-player
SystemdService=dbus-org.deepin.dde.SoundThemePlayer1.service
40 changes: 40 additions & 0 deletions misc/systemd/system/deepin-dde-device.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[Unit]
Description=Deepin Sound Theme Player

Requisite=sound.target
After=sound.target

# Ask for the dbus socket.
Wants=dbus.socket
After=dbus.socket

[Service]
Type=dbus
BusName=org.deepin.dde.Device1
ExecStart=/usr/lib/deepin-api/device

BindReadOnlyPaths=/run/dbus/system_bus_socket

DeviceAllow=DeviceAllow rw
DevicePolicy=closed

ProtectSystem=full
ProtectHome=yes
PrivateTmp=yes
#PrivateDevices=yes
PrivateNetwork=yes
ProtectHostname=yes
ProtectClock=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RemoveIPC=yes

[Install]
Alias=dbus-org.deepin.dde.Device1.service
39 changes: 39 additions & 0 deletions misc/systemd/system/deepin-locale-helper.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[Unit]
Description=Deepin Locale Helper

# Ask for the dbus socket.
Wants=dbus.socket
After=dbus.socket

[Service]
Type=dbus
BusName=org.deepin.dde.LocaleHelper1
ExecStart=/usr/lib/deepin-api/locale-helper

ReadWritePaths=/etc/default/locale
ReadWritePaths=/etc/locale.gen
ReadWritePaths=/usr/lib/locale/
ExecPaths=/usr/sbin/locale-gen

DevicePolicy=closed

ProtectSystem=full
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
PrivateNetwork=yes
ProtectHostname=yes
ProtectClock=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RemoveIPC=yes

[Install]
Alias=dbus-org.deepin.dde.LocaleHelper1.service
33 changes: 20 additions & 13 deletions misc/systemd/system/deepin-login-sound.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@ Requires=sound.target
After=dbus.service lightdm.service

[Service]
# added automatically, for details please see
# https://en.opensuse.org/openSUSE:Security_Features#Systemd_hardening_effort
ProtectSystem=full
ProtectHome=true
PrivateDevices=true
ProtectHostname=true
ProtectClock=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
RestrictRealtime=true
# end of automatic additions
Type=oneshot
ExecStart=/usr/bin/dbus-send --system --print-reply --dest=org.deepin.dde.SoundThemePlayer1 /org/deepin/dde/SoundThemePlayer1 org.deepin.dde.SoundThemePlayer1.PlaySoundDesktopLogin
RemainAfterExit=yes

DevicePolicy=closed

ProtectSystem=full
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
PrivateNetwork=yes
ProtectHostname=yes
ProtectClock=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RemoveIPC=yes

[Install]
WantedBy=multi-user.target
37 changes: 24 additions & 13 deletions misc/systemd/system/deepin-shutdown-sound.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,35 @@ Conflicts=shutdown.target
Before=shutdown.target

[Service]
# added automatically, for details please see
# https://en.opensuse.org/openSUSE:Security_Features#Systemd_hardening_effort
ProtectSystem=full
ProtectHome=true
#PrivateDevices=true
ProtectHostname=true
ProtectClock=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
RestrictRealtime=true
# end of automatic additions
Type=simple
ExecStart=/usr/bin/true
ExecStop=/usr/lib/deepin-api/deepin-shutdown-sound
RemainAfterExit=yes
TimeoutStopSec=7s

ReadOnlyPaths=/var/lib/deepin-sound-player
BindReadOnlyPaths=-/tmp/deepin-shutdown-sound.json

DeviceAllow=char-alsa rw
DevicePolicy=closed

ProtectSystem=full
ProtectHome=yes
PrivateTmp=yes
#PrivateDevices=yes
PrivateNetwork=yes
ProtectHostname=yes
ProtectClock=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RemoveIPC=yes

[Install]
WantedBy=graphical.target
41 changes: 41 additions & 0 deletions misc/systemd/system/deepin-sound-theme-player.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[Unit]
Description=Deepin Sound Theme Player

Requisite=sound.target
After=sound.target

# Ask for the dbus socket.
Wants=dbus.socket
After=dbus.socket

[Service]
Type=dbus
BusName=org.deepin.dde.SoundThemePlayer1
User=deepin-sound-player
ExecStart=/usr/lib/deepin-api/sound-theme-player

ReadWritePaths=/var/lib/deepin-sound-player

DeviceAllow=char-alsa rw
DevicePolicy=closed

ProtectSystem=full
ProtectHome=yes
#PrivateTmp=yes
#PrivateDevices=yes
PrivateNetwork=yes
ProtectHostname=yes
ProtectClock=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RemoveIPC=yes

[Install]
Alias=dbus-org.deepin.dde.SoundThemePlayer1.service

0 comments on commit 204ac21

Please sign in to comment.