Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
proxmox-user
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nounous
proxmox-user
Commits
44b3b7e4
Commit
44b3b7e4
authored
3 years ago
by
shirenn
🌊
Committed by
shirenn
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
hosts
parent
1535c68a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
proxmox-user.py
+26
-5
26 additions, 5 deletions
proxmox-user.py
with
27 additions
and
5 deletions
.gitignore
+
1
−
0
View file @
44b3b7e4
proxmox-user.json
generated/
This diff is collapsed.
Click to expand it.
proxmox-user.py
+
26
−
5
View file @
44b3b7e4
...
...
@@ -25,7 +25,9 @@ if __name__ == '__main__':
parser
=
argparse
.
ArgumentParser
(
description
=
"
Generate user configuration for proxmox
"
,
)
parser
.
add_argument
(
'
-e
'
,
'
--export
'
,
help
=
'
Exporte la configuration vers la sortie standartd
'
,
action
=
'
store_true
'
)
group
=
parser
.
add_mutually_exclusive_group
()
group
.
add_argument
(
'
-e
'
,
'
--export
'
,
help
=
'
Export the user configuration to stdout
'
,
action
=
'
store_true
'
)
group
.
add_argument
(
'
-p
'
,
'
--path
'
,
help
=
'
Select path to export user configuration
'
,
default
=
'
/etc/pve
'
)
args
=
parser
.
parse_args
()
with
open
(
os
.
path
.
join
(
path
,
'
proxmox-user.json
'
))
as
file
:
...
...
@@ -36,7 +38,8 @@ if __name__ == '__main__':
for
target
,
cfg
in
config
[
'
ldap
'
].
items
():
base
[
target
]
=
connect
(
cfg
)
field
=
'
uid
'
if
cfg
[
'
realm
'
]
==
'
pam
'
else
'
cn
'
users_qid
=
base
[
target
].
search
(
cfg
[
'
userBase
'
],
ldap
.
SCOPE_ONELEVEL
,
'
objectClass=inetOrgPerson
'
)
users_qid
=
base
[
target
].
search
(
cfg
[
'
userBase
'
],
ldap
.
SCOPE_ONELEVEL
,
'
objectClass=inetOrgPerson
'
,
attrlist
=
[
'
givenName
'
,
'
sn
'
,
'
mail
'
,
'
userPassword
'
,
field
])
users_q
=
base
[
target
].
result
(
users_qid
)[
1
]
for
dn
,
entries
in
users_q
:
uid
=
entries
[
field
][
0
].
decode
(
'
utf-8
'
)
...
...
@@ -49,7 +52,8 @@ if __name__ == '__main__':
groups
=
{}
acls
=
[]
# Recover groups with admin privileges
nounous_qid
=
base
[
'
admin
'
].
search
(
'
dc=crans,dc=org
'
,
ldap
.
SCOPE_SUBTREE
,
'
cn=_nounou
'
)
nounous_qid
=
base
[
'
admin
'
].
search
(
'
dc=crans,dc=org
'
,
ldap
.
SCOPE_SUBTREE
,
'
cn=_nounou
'
,
attrlist
=
[
'
memberUid
'
])
nounous
=
base
[
'
admin
'
].
result
(
nounous_qid
)[
1
][
0
][
1
]
nounous
=
{
user
.
decode
(
'
utf-8
'
)
for
user
in
nounous
[
'
memberUid
'
]
}
apprentis
=
set
(
users
[
'
admin
'
].
keys
())
-
nounous
...
...
@@ -61,7 +65,8 @@ if __name__ == '__main__':
# Recover clubs
if
'
user
'
in
config
[
'
ldap
'
]:
clubs_qid
=
base
[
'
user
'
].
search
(
'
ou=clubs,dc=adh,dc=crans,dc=org
'
,
ldap
.
SCOPE_ONELEVEL
,
'
objectClass=organization
'
)
ldap
.
SCOPE_ONELEVEL
,
'
objectClass=organization
'
,
attrlist
=
[
'
description
'
,
'
o
'
])
clubs_q
=
base
[
'
user
'
].
result
(
clubs_qid
)[
1
]
for
dn
,
entries
in
clubs_q
:
club
=
entries
[
'
o
'
][
0
].
decode
(
'
utf-8
'
)
...
...
@@ -69,6 +74,17 @@ if __name__ == '__main__':
groups
[
club
]
=
'
,
'
.
join
(
[
'
{}@pve
'
.
format
(
user
.
decode
(
'
utf-8
'
))
for
user
in
entries
[
'
description
'
]
]
)
hosts_qid
=
base
[
'
user
'
].
search
(
'
ou=hosts,dc=adh,dc=crans,dc=org
'
,
ldap
.
SCOPE_ONELEVEL
,
'
(&(objectClass=device)(serialNumber=*))
'
,
attrlist
=
[
'
serialNumber
'
,
'
owner
'
])
hosts_q
=
base
[
'
user
'
].
result
(
hosts_qid
)[
1
]
for
dn
,
host
in
hosts_q
:
vmid
=
host
[
'
serialNumber
'
][
0
].
decode
(
'
utf-8
'
)
for
owner
in
host
[
'
owner
'
]:
owner
=
owner
.
decode
(
'
utf-8
'
).
split
(
'
,
'
)
o
=
owner
[
0
].
split
(
'
=
'
)[
1
]
owner
=
f
'
@
{
o
}
'
if
owner
[
1
]
==
'
ou=clubs
'
else
'
{}@{}
'
.
format
(
o
,
config
[
'
user
'
][
'
realm
'
])
acls
.
append
({
'
propagate
'
:
0
,
'
role
'
:
'
VMUser
'
,
'
target
'
:
owner
,
'
path
'
:
f
'
/vms/
{
vmid
}
'
})
passwords
=
{}
user_db
=
{}
...
...
@@ -76,7 +92,7 @@ if __name__ == '__main__':
for
user
,
info
in
users
[
target
].
items
():
user_db
[
'
{}@{}
'
.
format
(
user
,
cfg
[
'
realm
'
])]
=
info
if
cfg
[
'
realm
'
]
==
'
pve
'
:
passwords
[
user
]
=
info
[
'
userPassword
'
]
passwords
[
user
]
=
info
[
'
userPassword
'
]
.
replace
(
'
{CRYPT}
'
,
''
)
users
=
user_db
with
open
(
os
.
path
.
join
(
path
,
'
templates
'
,
'
user.cfg.j2
'
))
as
template
:
...
...
@@ -93,3 +109,8 @@ if __name__ == '__main__':
print
(
'
# | -> priv/shadow.cfg |
'
)
print
(
'
# +--------------------+
'
)
print
(
shadow_template
.
render
(
users
=
passwords
))
else
:
with
open
(
os
.
path
.
join
(
args
.
path
,
'
user.cfg
'
),
'
w
'
)
as
file
:
file
.
write
(
user_template
.
render
(
users
=
users
,
groups
=
groups
,
acls
=
acls
))
with
open
(
os
.
path
.
join
(
args
.
path
,
'
priv/shadow.cfg
'
),
'
w
'
)
as
file
:
file
.
write
(
shadow_template
.
render
(
users
=
passwords
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment