Created
June 16, 2025 02:27
-
-
Save STashakkori/16d018df926a0a7827d647ed8e2195ac to your computer and use it in GitHub Desktop.
How to enforce group in lmod lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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