Keeps SLURM user associations in sync with UNIX group membership.
UNIX groups (/etc/group) YAML config (accounts.yml)
┌─────────────────────┐ ┌──────────────────────────┐
│ ml_team: alice,bob │ │ declared_groups │
│ bio_team: carol │─────┐ │ ml_approved: │
│ hpc_users: alice, │ │ │ groups: [ml_team] │
│ carol,dave│ │ │ whitelist: [hpc_users]│
└─────────────────────┘ │ │ accounts: │
│ getent group │ │ research > ml_group │
│ └──▶│ associations: │
▼ │ ml_gpu_assoc: │
┌─────────────────────┐ │ account: ml_group │
│ Group expansion │◀────────│ groups: [ml_approved]│
│ + set operations │ └──────────────────────────┘
│ (union/intersect/ │
│ add/exclude) │
└────────┬────────────┘
│ resolved (user, account) pairs
▼
┌─────────────────────┐ ┌──────────────────────────┐
│ Diff engine │ │ SLURM accounting DB │
│ │◀────────│ sacctmgr list assoc │
│ desired vs current │ └──────────────────────────┘
└────────┬────────────┘
│
┌─────┴──────┐
▼ ▼
create delete
assoc assoc
│ │
└─────┬──────┘
▼
┌─────────────────────┐
│ sacctmgr │ dry-run: only print commands
│ (--dry-run / live) │ --execute: apply to SLURM
└─────────────────────┘
SLURM requires explicit (user, account, partition, cluster) association tuples for every user and has no native mechanism to derive these from UNIX groups. This tool reads a YAML config, expands group memberships via getent group, and drives sacctmgr to create, update, and delete associations accordingly.
The core of this repository was not generated via AI models, only the docker testing environment.
- Python 3.x
sacctmgrin$PATH- Read access to
/etc/group(viagetent)
# Dry run (default) — prints sacctmgr commands, executes nothing
python main.py
# Apply changes
python main.py --execute
# Use a different config file
python main.py --file /etc/slurm/accounts.yml| Flag | Short | Description |
|---|---|---|
--execute |
-e |
Execute sacctmgr commands. Without this flag the tool only logs what it would do. |
--file PATH |
-f |
Path to the YAML config file. Defaults to accounts.yml in the current directory. |
The config file is accounts.yml by default.
declared_groups: # optional — define virtual groups from real UNIX groups
defaults: # required — cluster, org, and default account mappings
accounts: # required — SLURM account hierarchy
associations: # required — maps groups to accountsVirtual groups built from real UNIX groups using set operations, applied in this order:
- Union of all listed
groups - Add individual users via
add_users - Remove individual users via
exclude_users - Intersect with
whitelistgroups
declared_groups:
ml_approved:
groups:
- ml_team
whitelist:
- cluster_users
add_users:
- serviceaccount
exclude_users:
- intern01Virtual groups can be used anywhere a real UNIX group can.
defaults:
cluster: my-cluster # must match ClusterName in slurm.conf
organization: myorg
groups: # optional: default account per group
ml_approved:
account: ml_group
users: # optional: default account per user (highest priority)
jdoe:
account: researchDefault account resolution order per user:
defaults/users/<username>if defined- First matching entry in
defaults/groupswhere the user is a member - Falls back to a personal account named after the user
Defines the SLURM account hierarchy. Accounts without a parent are placed under root.
accounts:
research:
description: Top-level research account
fairshare: 10
ml_group:
description: Machine learning research
parent: research
fairshare: 5
bio_group:
description: Bioinformatics
parent: research
fairshare: 3Supports all sacctmgr limit fields: fairshare, qos, defaultqos, grptres, maxtres, maxwall, etc.
Maps groups (real or virtual) to accounts with optional per-association limits.
associations:
ml_gpu_assoc:
account: ml_group
groups:
- ml_approved
extra_users:
- serviceaccount
fairshare: 55See example_accounts.yml.
A self-contained test environment is in docker/. It runs MariaDB and a SLURM accounting daemon (slurmdbd) with four test users (alice, bob, carol, dave) pre-populated in /etc/group.
# Build and start
docker compose -f docker/docker-compose.yml up --build -d
# Run the test suite
docker compose -f docker/docker-compose.yml exec slurm docker/run_tests.sh
# Poke around manually
docker compose -f docker/docker-compose.yml exec slurm bash
# Tear down
docker compose -f docker/docker-compose.yml down -vpodman-compose is a separate package — install it first if needed (pip install podman-compose or via your distro).
# Build and start
podman-compose -f docker/docker-compose.yml up --build -d
# Run the test suite
podman-compose -f docker/docker-compose.yml exec slurm docker/run_tests.sh
# Poke around manually
podman-compose -f docker/docker-compose.yml exec slurm bash
# Tear down
podman-compose -f docker/docker-compose.yml down -vAlternatively, if you have Podman 4.4+ with the Docker-compatible CLI alias:
podman compose -f docker/docker-compose.yml up --build -dThe test suite covers dry-run safety, account creation, association correctness, and idempotency.