Configure Aerospike Database to run as non-root
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
This page describes how to configure Aerospike Database to run as a non-root user on Linux systems that use systemd.
Running asd as a dedicated non-root user follows least-privilege security practices and makes ownership of Aerospike Database files, devices, and logs explicit. On nodes that run asd as root, Linux assigns root ownership to logs, namespace directories, shared memory segments, and raw block devices, so other users need elevated privileges to access them (for example, collectlogs).
Migrating an existing node from root to non-root is not a single configuration change.
Choose the target user and group, stop asd, then grant that user access to each resource the node uses: service identity, file and directory ownership, raw devices, shared memory, and any required kernel parameters.
Verify each change before you start the service again.
The sections on this page follow this order. For a new installation, skip Prepare shared memory for an existing installation and begin at Configure the node.
Applies to
- Aerospike Database on Linux nodes managed by
systemd - New installations and migrations from root
- All supported Database versions unless a step calls out a version-specific constraint (for example,
scheduler-moderemoved in 6.4.0)
Prerequisites
This task is for Linux cluster operators who manage Aerospike Database nodes with systemd and privileged OS access.
Confirm that the following conditions are true for the node:
- Aerospike Database is installed. See Install Aerospike on Linux.
- The node uses
systemdto manage the Aerospike Database service. - You can run privileged operating system commands from a root shell, or from an account with equivalent sudo permissions. The examples on this page assume those permissions.
For production clusters, convert one node at a time. Verify that the cluster is stable before you convert the next node.
Outcome
After this procedure, asd runs as AEROSPIKE_USER / AEROSPIKE_GROUP, can access namespace storage and logs, and the node returns OK from asinfo -v status and rejoins a stable cluster.
Prepare shared memory for an existing installation
Complete this section only when asd is running as root on the node. For a new installation, skip to Configure the node.
When asd runs as root, it creates shared memory segments for indexes and in-memory namespace data.
Before the service starts as AEROSPIKE_USER, stop asd and either preserve those segments or remove index segments so asd can recreate them under the new user.
-
Stop the Aerospike daemon (
asd) on the node.Terminal window systemctl stop aerospikeSee Aerospike daemon management for more details.
-
List shared memory segments and identify Aerospike Database resources.
Terminal window ipcs -mThe command prints a table of shared memory segments—chunks of RAM the kernel keeps around after
asdstops, so a laterasdprocess can reconnect to indexes and in-memory data without rebuilding everything from disk.Aerospike labels each segment in the key column. Match the start of that value to see what the segment holds:
If the key starts with… The segment holds… 0xaePrimary index 0xa2Secondary indexes 0xadIn-memory namespace data (not just indexes) These keyed segments apply to Enterprise Edition deployments that use shared-memory indexes (
index-typeorsindex-typeshmem) and, for0xad,storage-engine memoryon Database 7.0 and later.Other columns matter for non-root migration:
- owner — Linux user that created the segment. After
asdran as root, this is oftenrooteven after you switch the service toAEROSPIKE_USER. - perms — Access mode. Aerospike often shows
666, meaning any user on the host can read and write the segment. That is why a non-rootasdcan still use segments left behind by root.
- owner — Linux user that created the segment. After
-
Choose how to handle index segments before you configure the node.
Choose this path when the node must reuse existing primary and secondary index segments without a cold restart. Do not remove
0xaeor0xa2segments in this procedure.Use this path when you stop
asdfor non-root migration on the same host without rebooting. Do not runipcrmon index segments.After you configure the node and start
asd, Aerospike reattaches to existing segments when fast restart conditions are met.In
ipcs -moutput, owner may still showrootand perms may show666. That is expected and does not block a non-rootasdfrom reusing the segments. On hosts shared by untrusted users, treat666segments as a local exposure and prefer cold start or ASMT on those nodes.Use this path when shared memory will be lost, such as after a host reboot, and you must persist indexes to disk first.
- Back up indexes with ASMT before maintenance that clears shared memory.
- After maintenance (for example, a host reboot), restore indexes with ASMT before you start
asd. Restored segments may again show ownerrootand perms666inipcs -m; this is expected.
Use this path only if the node can restart without reusing the existing primary and secondary index shared memory segments. The next startup can take longer because
asdmust recreate those index segments underAEROSPIKE_USER. Remove only the existing primary and secondary index shared memory segments:Terminal window ipcs -m | awk '$1 ~ /^0xa[2e][0-9a-f]*/ {print $1}' | while read -r key; do ipcrm -M "$key"; done
Configure the node
Use the following steps for new and existing installations. If you prepared shared memory on an existing node, asd should remain stopped until you finish these steps.
-
Choose the service user and group.
Pick the Linux user and group for
asdto use after this migration. The same names appear in everychown, udev rule, and permission check in the steps that follow, so choose them before you change ownership elsewhere on the node.Use an existing non-root user and group, or create them now. Throughout this page, replace
AEROSPIKE_USERandAEROSPIKE_GROUPwith those names.Verify that both accounts exist:
Terminal window id AEROSPIKE_USERgetent group AEROSPIKE_GROUP -
Configure
systemdto startasdas that user and group.systemdstarts and supervisesasdon boot and onsystemctl start. A drop-in file addsUser=andGroup=to the existingaerospike.serviceunit without editing the package file directly.After this step,
systemdlaunches theasdprocess asAEROSPIKE_USERandAEROSPIKE_GROUP. The remaining steps grant that identity access to logs, data, devices, and shared memory.If a configuration management tool manages
systemdunit files in your environment, use that tool to set the sameUserandGroupvalues.Terminal window install -d -m 0755 /etc/systemd/system/aerospike.service.dcat > /etc/systemd/system/aerospike.service.d/non-root.conf <<'EOF'[Service]User=AEROSPIKE_USERGroup=AEROSPIKE_GROUPEOFsystemctl daemon-reloadTerminal window systemctl show aerospike.service -p User -p GroupRun
systemctl cat aerospike.serviceto inspect the full unit and drop-in configuration.Set the process identity with
User=andGroup=in the systemd drop-in. Ifaerospike.confdefinesservice.userorservice.group, those values must match the drop-in exactly. Mismatches causeasdto fail at startup with an “insufficient privileges to switch user” error. Remove or align any existing keys before you start the service. -
Configure Aerospike Database logging.
Choose one of the following options. Console logging is recommended for
systemdbecause logs are available throughjournalctlwithout extra directory permissions. For more information, see Access Aerospike logs with systemd.Add or update the
loggingstanza inaerospike.confto send logs to the service manager:logging {console {context any info}}If
aerospike.confstill defines afilesink for the main log, remove that sink or change it soasddoes not write to a path the non-root user cannot access.If your environment requires a log file (for example, for log rotation or
collectlogs), keep or add afilesink and grant the service user write access to the log directory:logging {file /var/log/aerospike/aerospike.log {context any info}}Terminal window chown -R AEROSPIKE_USER:AEROSPIKE_GROUP /var/log/aerospike/Configure log rotation for the file path you use.
-
Configure namespace storage permissions.
Aerospike Database must be able to read from and write to every namespace storage resource after
asdstops running as root. Complete every subsection that applies to this node. These storage types are not mutually exclusive.File-backed namespace
If namespace data is configured for persistence to a file,
AEROSPIKE_USERmust have write permission for the directory that contains the file.Terminal window chown -R AEROSPIKE_USER:AEROSPIKE_GROUP /opt/aerospike/data/Filesystem-mounted SSD
SSDs mounted as filesystems, such as SSDs used for a flash index, need the same directory ownership and permissions as file-backed namespace storage.
Terminal window chown -R AEROSPIKE_USER:AEROSPIKE_GROUP /opt/aerospike/data/Raw SSD
Raw SSD namespaces need persistent device paths in
aerospike.confand operating system permissions on the underlying block devices.-
Configure persistent
/dev/disk/by-id/paths inaerospike.conf.Use persistent
/dev/disk/by-id/paths because kernel-assigned names like/dev/sdbor/dev/sdccan change across reboots. ReplaceDEVICE_PATHwith the configured persistent device path, such as/dev/disk/by-id/DISK_BY_ID_PATH.namespace aerospike-example {...storage-engine device {device DEVICE_PATH...}} -
Add targeted udev rules for Aerospike Database namespace devices.
Use targeted udev rules that match only Aerospike Database namespace devices. This limits raw block-device access to the devices Aerospike uses.
Use
udevadm info --query=property --name=DEVICE_PATHto find a persistent identifier such asID_SERIAL_SHORT(NVMe) orID_WWN. On cloud VMs, match on the property present for that device (for exampleID_PATHorID_SERIALfor Google disks). Match on that identifier without aDEVTYPEfilter—partitions and whole disks share the sameID_SERIAL_SHORTandID_WWNvalues, so the rule applies whetherDEVICE_PATHis a partition or a whole disk. Add the rules to/etc/udev/rules.d/99-aerospike-non-root.rules.# Example: match each raw device by a persistent identifier.SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="DEVICE_SERIAL_1", OWNER="AEROSPIKE_USER", GROUP="AEROSPIKE_GROUP"SUBSYSTEM=="block", ENV{ID_WWN}=="DEVICE_WWID_2", OWNER="AEROSPIKE_USER", GROUP="AEROSPIKE_GROUP"Confirm that the chosen
ENV{…}key matches the output ofudevadm infofor eachDEVICE_PATHbefore you reload the rules. -
Reload and trigger the udev rules.
Run the trigger command for each
DEVICE_PATHconfigured for Aerospike Database.Terminal window udevadm control --reload-rulesudevadm trigger --type=devices --subsystem-match=block --action=change --name-match="$(readlink -f DEVICE_PATH)" --settle -
Configure the disk scheduler at the operating system level.
The
scheduler-modeparameter was removed in Aerospike Database 6.4.0. Set the disk scheduler at the operating system level for each raw namespace device. Follow Configure disk scheduler at the operating system level, including persistent scheduler rules in/etc/udev/rules.d/60-aerospike-scheduler.ruleswhen that procedure applies. -
Verify device ownership.
Replace
DEVICE_PATHwith the configured persistent device path. The resolved block device should be owned byAEROSPIKE_USERandAEROSPIKE_GROUP.Terminal window ls -l "$(readlink -f DEVICE_PATH)"
If your operating system policy requires group-based device access, add
AEROSPIKE_USERto the required disk group. Assess the scope of the disk group before using this option because it can grant broad raw block-device access.Terminal window usermod -a -G DISK_GROUP_NAME AEROSPIKE_USERRestart the Aerospike service (or reboot the node) after changing group membership so
asdpicks up the new group. -
-
Change ownership of additional Aerospike Database directories.
The system metadata and user-defined function directories store runtime state that
asdupdates after startup. Give the non-root service identity ownership of those directories.Terminal window chown -R AEROSPIKE_USER:AEROSPIKE_GROUP /opt/aerospike/smdchown -R AEROSPIKE_USER:AEROSPIKE_GROUP /opt/aerospike/usr -
Set required Linux kernel parameters.
This step applies when the node uses an all-flash deployment or primary index on flash. Those configurations require the values below for the node to start. Set them in sysctl before you start
asdasAEROSPIKE_USER.For secondary index on flash without
index-type flash, these values are recommended but not enforced at startup by the server.Persist the values in a sysctl configuration file under
/etc/sysctl.d/. Record the original values before changing them so you can restore them if you roll back this migration.Terminal window sysctl vm.dirty_bytes vm.dirty_background_bytes vm.dirty_expire_centisecs vm.dirty_writeback_centisecsTerminal window cat > /etc/sysctl.d/99-aerospike-non-root.conf <<'EOF'vm.dirty_bytes = 16777216vm.dirty_background_bytes = 1vm.dirty_expire_centisecs = 1vm.dirty_writeback_centisecs = 10EOFsysctl --systemVerify the active values:
Terminal window sysctl vm.dirty_bytes vm.dirty_background_bytes vm.dirty_expire_centisecs vm.dirty_writeback_centisecs
Outcomes and constraints
After migration:
systemdrunsasdasAEROSPIKE_USER/AEROSPIKE_GROUP.- Shared-memory segments may retain owner
rootand perms666when you preserve indexes in place or restore with ASMT. - Raw namespace devices use persistent
/dev/disk/by-id/paths, targeted udev ownership rules, and OS-level disk scheduler rules. - Optional
enforce-best-practicesfails startup when any best-practices check fails. - In production clusters, convert one node at a time and verify cluster stability before the next node.
Verify
After you configure the node, verify that the service starts, runs under the configured non-root user, and rejoins the cluster.
-
Start the Aerospike Database service and verify that it is active.
Starting the service is a service management action, so a root user or a user with sudo permissions must do it. After
systemdstarts the service, the runningasdprocess is owned by the configured non-root user.For options on starting the server, see Aerospike daemon management.
CommandTerminal window systemctl start aerospike.servicesystemctl is-active aerospike.serviceExpected output active -
Verify that
asdis running as the non-root user and group.Terminal window ps -o user,group,comm -C asdExpected output includes
AEROSPIKE_USER,AEROSPIKE_GROUP, andasd. -
Verify that the service port is ready.
CommandTerminal window asinfo -v statusExpected output OK -
Verify Aerospike Database shared memory segments.
Terminal window ipcs -mAfter a cold start or when
asdcreates new segments, the owner column inipcs -mshould showAEROSPIKE_USER. If you preserved segments in place or restored them with ASMT, owner may still showrootand perms may show666; verify that the expected index and in-memory segments (keys starting with0xae,0xa2, and if applicable0xad) are present. These keyed segments apply to Enterprise Edition deployments that use shared-memory indexes. -
For production clusters, verify that the cluster is stable before converting the next node.
Replace
CLUSTER_SIZEwith the expected number of nodes:Terminal window asinfo -v 'cluster-stable:size=CLUSTER_SIZE;ignore-migrations=false'The command returns
ERRORwhile migrations are in progress. When migrations complete, all nodes return the same cluster key. For more information, see Wait for migrations. -
(Recommended) Enable
enforce-best-practices.Complete the verification steps in Verify before you enable this setting. With
enforce-best-practicesenabled, startup fails when any best-practices check fails. Review logs from the successful start and resolve violations such asmin_free_kbytesor RAM reservation settings before you add the flag.Add the setting to
aerospike.conf:service {enforce-best-practices true}Restart the service and confirm that the node starts and returns
OKfromasinfo -v status:Terminal window systemctl restart aerospike.serviceasinfo -v status
Troubleshoot startup errors
If asd does not start, examine the logs for resources that still require attention:
journalctl -u aerospike.service -bCommon causes include missing user or group accounts, stale systemd unit definitions, incorrect file or device ownership, missing kernel parameter values, and enforce-best-practices failures.
Roll back changes
If the node does not start after the change, roll back the service identity and local operating system changes before you start the node again.
-
Remove the systemd drop-in override and reload the systemd manager configuration.
Terminal window rm -f /etc/systemd/system/aerospike.service.d/non-root.confsystemctl daemon-reload -
Recover shared memory if you removed index segments during migration.
If you removed
0xaeor0xa2segments in the cold-start path, expect index rebuild on the next start or restore indexes from ASMT before you startasd. Rolling back systemd alone does not restore removed segments. -
Disable or remove the udev rules added for Aerospike Database devices, if you added them.
If you used the dedicated rules file from this procedure, remove that file. If you added rules to another file, remove only the rules that you added for this migration. Run the trigger command for each
DEVICE_PATHthat used those rules.Terminal window rm -f /etc/udev/rules.d/99-aerospike-non-root.rulesudevadm control --reload-rulesudevadm trigger --type=devices --subsystem-match=block --action=change --name-match="$(readlink -f DEVICE_PATH)" --settleIf you used disk-group access, remove
AEROSPIKE_USERfrom that group according to your operating system policy. -
Restore the previous sysctl configuration, if you changed kernel parameters only for this migration.
Skip this step if these sysctl values are part of the required baseline for the node. Replace the
PREVIOUS_DIRTY_BYTES,PREVIOUS_DIRTY_BACKGROUND_BYTES,PREVIOUS_DIRTY_EXPIRE_CENTISECS, andPREVIOUS_DIRTY_WRITEBACK_CENTISECSplaceholders with the values you recorded before changing the sysctl configuration.Terminal window rm -f /etc/sysctl.d/99-aerospike-non-root.confsysctl -w vm.dirty_bytes=PREVIOUS_DIRTY_BYTESsysctl -w vm.dirty_background_bytes=PREVIOUS_DIRTY_BACKGROUND_BYTESsysctl -w vm.dirty_expire_centisecs=PREVIOUS_DIRTY_EXPIRE_CENTISECSsysctl -w vm.dirty_writeback_centisecs=PREVIOUS_DIRTY_WRITEBACK_CENTISECSsysctl --system -
Revert
aerospike.confchanges made for this migration.Remove or restore settings you added in this procedure, such as console or file logging changes and
enforce-best-practices. Removing the systemd drop-in in the first rollback step restores root for the service. Remove anyservice.userorservice.groupkeys fromaerospike.confif they were present before migration—Aerospike Database validates these deprecated keys against the process identity at startup, and a mismatched value causesasdto fail to start. -
Restore directory ownership if you changed it for the non-root user.
Terminal window chown -R root:root /opt/aerospike/datachown -R root:root /opt/aerospike/smdchown -R root:root /opt/aerospike/usrIf you changed ownership for file logging, restore the log directory as well (for example,
/var/log/aerospike/).Adjust paths and owners to match your environment’s pre-migration ownership.
-
Remove scheduler udev rules, if you added them while following Configure disk scheduler at the operating system level (for example,
/etc/udev/rules.d/60-aerospike-scheduler.rules). -
Start the service and verify that the node returns to the cluster.
Terminal window systemctl start aerospike.serviceasinfo -v status
Next steps
- Review best practices for remaining kernel and RAM settings.
- For raw devices, confirm disk scheduler configuration on every node.
- Convert additional cluster nodes one at a time; see Wait for migrations.