Skip to content
Snippets Groups Projects
Commit c8a9fb85 authored by esum's avatar esum Committed by root
Browse files

Add different roles for each user

parent 63834802
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,8 @@
"userBase": "ou=users,dc=adh,dc=crans,dc=org",
"realm": "pve",
"binddn": "cn=admin,dc=adh,dc=crans,dc=org",
"passwd": "mot de passe"
"passwd": "mot de passe",
"pve_vm_role": "PVEVMUser"
}
}
}
......@@ -50,6 +50,7 @@ if __name__ == '__main__':
users[target][uid][key] = urllib.parse.quote(users[target][uid][key])
groups = {}
roles = config['roles'] if 'roles' in config else {}
acls = []
# Recover groups with admin privileges
nounous_qid = base['admin'].search('dc=crans,dc=org', ldap.SCOPE_SUBTREE, 'cn=_nounou',
......@@ -84,7 +85,7 @@ if __name__ == '__main__':
owner = owner.decode('utf-8').split(',')
o = owner[0].split('=')[1]
owner = f'@{o}' if owner[1] == 'ou=clubs' else '{}@{}'.format(o,config['ldap']['user']['realm'])
acls.append({'propagate': 0, 'role': 'PVEVMUser', 'target': owner, 'path': f'/vms/{vmid}'})
acls.append({'propagate': 0, 'role': base['user']['pve_vm_role'], 'target': owner, 'path': f'/vms/{vmid}'})
acls.append({'propagate': 1, 'role': 'PVEDatastoreUser', 'target': owner, 'path': f'/storage/local'})
passwords = {}
......@@ -112,6 +113,6 @@ if __name__ == '__main__':
print(shadow_template.render(users=passwords))
elif os.path.ismount('/etc/pve'):
with open(os.path.join(args.path, 'user.cfg'), 'w') as file:
file.write(user_template.render(users=users, groups=groups, acls=acls))
file.write(user_template.render(users=users, roles=roles, groups=groups, acls=acls))
with open(os.path.join(args.path, 'priv/shadow.cfg'), 'w') as file:
file.write(shadow_template.render(users=passwords))
......@@ -2,5 +2,7 @@
{%endfor%}
{%for group,users in groups.items()%}group:{{ group }}:{{ users }}::
{%endfor%}
{%for role,privileges in roles.items()%}role:{{ role }}:{{ privileges | join(",") }}:
{%endfor%}
{%for acl in acls%}acl:{{acl['propagate']}}:{{acl['path']}}:{{acl['target']}}:{{acl['role']}}:
{%endfor%}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment