Skip to content

Commit 71b2584

Browse files
author
Rajat Gupta
committed
Add systemd configurations to strengthen OS core security
Signed-off-by: Rajat Gupta <[email protected]>
1 parent 931c1aa commit 71b2584

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

distribution/packages/src/common/systemd/opensearch.service

+95
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,101 @@ SuccessExitStatus=143
6060
# Allow a slow startup before the systemd notifier module kicks in to extend the timeout
6161
TimeoutStartSec=75
6262

63+
# Prevent modifications to the control group filesystem
64+
ProtectControlGroups=true
65+
66+
# Prevent loading or reading kernel modules
67+
ProtectKernelModules=true
68+
69+
# Prevent altering kernel tunables (sysctl parameters)
70+
ProtectKernelTunables=true
71+
72+
# Set device access policy to 'closed', allowing access only to specific devices
73+
DevicePolicy=closed
74+
75+
# Make /proc invisible to the service, enhancing isolation
76+
ProtectProc=invisible
77+
78+
# Make /usr, /boot, and /etc read-only (less restrictive than 'strict')
79+
ProtectSystem=full
80+
81+
# Prevent changes to control groups (redundant with earlier setting, can be removed)
82+
ProtectControlGroups=yes
83+
84+
# Prevent changing the execution domain
85+
LockPersonality=yes
86+
87+
88+
# System call filtering
89+
# System call filterings which restricts which system calls a process can make
90+
# @ means allowed
91+
# ~ means not allowed
92+
SystemCallFilter=@system-service
93+
SystemCallFilter=~@reboot
94+
SystemCallFilter=~@swap
95+
96+
SystemCallErrorNumber=EPERM
97+
98+
# Capability restrictions
99+
# Remove the ability to block system suspends
100+
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND
101+
102+
# Remove the ability to establish leases on files
103+
CapabilityBoundingSet=~CAP_LEASE
104+
105+
# Remove the ability to use system resource accounting
106+
CapabilityBoundingSet=~CAP_SYS_PACCT
107+
108+
# Remove the ability to configure TTY devices
109+
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
110+
111+
# Remov below capabilities:
112+
# - CAP_SYS_ADMIN: Various system administration operations
113+
# - CAP_SYS_PTRACE: Ability to trace processes
114+
# - CAP_NET_ADMIN: Various network-related operations
115+
CapabilityBoundingSet=~CAP_SYS_ADMIN ~CAP_SYS_PTRACE ~CAP_NET_ADMIN
116+
117+
118+
# Address family restrictions
119+
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
120+
121+
# Filesystem Access
122+
123+
ReadWritePaths=/var/log/opensearch
124+
ReadWritePaths=/var/lib/opensearch
125+
ReadWritePaths=/mnt/snapshots
126+
127+
## Allow read access to system files
128+
ReadOnlyPaths=/etc/os-release /usr/lib/os-release /etc/system-release
129+
130+
## Allow read access to Linux IO stats
131+
ReadOnlyPaths=/proc/self/mountinfo /proc/diskstats
132+
133+
## Allow read access to control group stats
134+
ReadOnlyPaths=/proc/self/cgroup /sys/fs/cgroup/cpu /sys/fs/cgroup/cpu/-
135+
ReadOnlyPaths=/sys/fs/cgroup/cpuacct /sys/fs/cgroup/cpuacct/- /sys/fs/cgroup/memory /sys/fs/cgroup/memory/-
136+
137+
138+
RestrictNamespaces=true
139+
140+
NoNewPrivileges=true
141+
142+
# Memory and execution protection
143+
MemoryDenyWriteExecute=true # Prevent creating writable executable memory mappings
144+
SystemCallArchitectures=native # Allow only native system calls
145+
KeyringMode=private # Service does not share key material with other services
146+
LockPersonality=true # Prevent changing ABI personality
147+
RestrictSUIDSGID=true # Prevent creating SUID/SGID files
148+
RestrictRealtime=true # Prevent acquiring realtime scheduling
149+
ProtectHostname=true # Prevent changes to system hostname
150+
ProtectKernelLogs=true # Prevent reading/writing kernel logs
151+
ProtectClock=true # Prevent tampering with the system clock
152+
153+
# Socket restrictions
154+
SocketBindAllow=tcp:9200
155+
SocketBindAllow=tcp:9300
156+
SocketBindDeny=any # Deny all other socket bindings
157+
63158
[Install]
64159
WantedBy=multi-user.target
65160

0 commit comments

Comments
 (0)