-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ldap): alter external LDAP domains (#806)
- Loading branch information
Showing
7 changed files
with
488 additions
and
4 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...ageroot/var/lib/nethserver/cluster/actions/alter-external-domain/10validate_ldap_provider
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import sys | ||
import json | ||
import agent | ||
import os | ||
import cluster.userdomains | ||
|
||
# | ||
# Sample request: | ||
# { | ||
# "domain":"example.com", | ||
# "protocol": "ldap", | ||
# "bind_dn": "cn=ldapservice,dc=example,dc=com", | ||
# "bind_password": "s3cret", | ||
# "tls": true, | ||
# "tls_verify": true | ||
# } | ||
request = json.load(sys.stdin) | ||
domain = request['domain'] | ||
protocol = request['protocol'] | ||
rdb = agent.redis_connect(privileged=False) | ||
|
||
agent.set_weight(os.path.basename(__file__), 0) # Validation step, no task progress at all | ||
|
||
if protocol == 'ldap': | ||
conf = rdb.hgetall(f"cluster/user_domain/ldap/{domain}/conf") | ||
# Get the first provider: ["x.x.x.x:636"] | ||
providers = rdb.lrange(f"cluster/user_domain/ldap/{domain}/providers", 0, -1) | ||
host = providers[0].split(':')[0] | ||
port = providers[0].split(':')[1] | ||
|
||
validate= { | ||
'bind_dn': request['bind_dn'], | ||
'bind_password': request['bind_password'], | ||
'tls': request['tls'], | ||
'tls_verify': request['tls_verify'], | ||
'domain': domain, | ||
'protocol': protocol, | ||
'host': host, | ||
'port': int(port), | ||
'schema':conf['schema'], | ||
'base_dn': conf['base_dn'] | ||
} | ||
|
||
errors, logex = cluster.userdomains.validate_ldap(validate) | ||
|
||
if logex: | ||
print(agent.SD_ERR + f"{logex.__class__.__name__}: {logex}", file=sys.stderr) | ||
|
||
if errors: | ||
agent.set_status('validation-failed') | ||
json.dump(errors, fp=sys.stdout) | ||
sys.exit(3) |
48 changes: 48 additions & 0 deletions
48
core/imageroot/var/lib/nethserver/cluster/actions/alter-external-domain/50alter_ldap_domain
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import sys | ||
import json | ||
import agent | ||
import os | ||
|
||
# | ||
# Sample request: | ||
# { | ||
# "domain":"example.com", | ||
# "protocol": "ldap", | ||
# "bind_dn": "cn=ldapservice,dc=example,dc=com", | ||
# "bind_password": "s3cret", | ||
# "tls": true, | ||
# "tls_verify": true | ||
# } | ||
request = json.load(sys.stdin) | ||
domain = request['domain'] | ||
protocol = request['protocol'] | ||
|
||
rdb = agent.redis_connect(privileged=True) | ||
|
||
if protocol == 'ldap': | ||
conf = rdb.hgetall(f"cluster/user_domain/ldap/{domain}/conf") | ||
rdb.hset(f"cluster/user_domain/ldap/{domain}/conf", mapping={ | ||
'bind_dn': request['bind_dn'], | ||
'bind_password': request['bind_password'], | ||
'tls': 'on' if request['tls'] else 'off', | ||
'tls_verify': 'on' if request['tls_verify'] else 'off', | ||
}) | ||
|
||
# | ||
# Advertise new account provider setup | ||
# | ||
rdb.publish(os.getenv('AGENT_ID') + '/event/ldap-provider-changed', json.dumps({ | ||
'domain': domain, | ||
'key': f"cluster/user_domain/ldap/{domain}/providers", | ||
})) | ||
# Advertise new user domain setup | ||
rdb.publish(os.getenv('AGENT_ID') + '/event/user-domain-changed', json.dumps({ | ||
'domain': domain | ||
})) |
65 changes: 65 additions & 0 deletions
65
core/imageroot/var/lib/nethserver/cluster/actions/alter-external-domain/validate-input.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "alter-external-domain input", | ||
"description": "Configure an external user domain", | ||
"$id": "http://schema.nethserver.org/cluster/alter-external-domain-input.json", | ||
"examples": [ | ||
{ | ||
"domain": "example.com", | ||
"protocol": "ldap", | ||
"bind_dn": "cn=ldapservice,dc=example,dc=com", | ||
"bind_password": "s3cret", | ||
"tls": true, | ||
"tls_verify": true | ||
} | ||
], | ||
"type": "object", | ||
"required": [ | ||
"domain", | ||
"protocol" | ||
], | ||
"properties": { | ||
"domain": { | ||
"type": "string", | ||
"title": "User domain name", | ||
"minLength": 1 | ||
}, | ||
"protocol": { | ||
"type": "string", | ||
"title": "Provider protocol", | ||
"description": "Protocol used to communicate with the domain providers.", | ||
"enum": [ | ||
"ldap" | ||
] | ||
} | ||
}, | ||
"$defs": { | ||
"additional-properties-of-ldap": { | ||
"type": "object", | ||
"title": "LDAP domain properties", | ||
"description": "Additional required properties of LDAP-based domains", | ||
"properties": { | ||
"bind_dn": { | ||
"type": "string", | ||
"minLength": 1 | ||
}, | ||
"bind_password": { | ||
"type": "string", | ||
"minLength": 1 | ||
}, | ||
"tls": { | ||
"type": "boolean" | ||
}, | ||
"tls_verify": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"bind_dn", | ||
"bind_password", | ||
"tls", | ||
"tls_verify" | ||
] | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.