Skip to content

Instantly share code, notes, and snippets.

@STashakkori
Created June 16, 2025 02:27
Show Gist options
  • Save STashakkori/16d018df926a0a7827d647ed8e2195ac to your computer and use it in GitHub Desktop.
Save STashakkori/16d018df926a0a7827d647ed8e2195ac to your computer and use it in GitHub Desktop.
How to enforce group in lmod lua
-- Function to check if a user is in a given group
-- Hardcoded to allow group root. Can also add sudo
-- if needed and any other group to always allow
local function enforce_group(group)
local user = subprocess("whoami")
local command = "id -nG " .. user
local result = subprocess(command)
if result:find("root") then return end
if not result:find(group) then
LmodError("Access to this module is denied.")
end
end
-- Usage
enforce_group("a_group_to_enforce")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment