camunda/uralkal: ldap-debug — default GL_sarex-users member dump, paged search, bind on LDAP_PORTS
This commit is contained in:
parent
35587e5f8b
commit
585a24e3e5
@ -13,8 +13,10 @@ Configuration is via environment variables (sensible defaults for uralkali):
|
||||
BIND_DN e.g. svc-keycloak@local.uralkali.com or full DN (optional)
|
||||
BIND_PASSWORD password for simple bind (optional)
|
||||
SEARCH_FILTER default (&(objectClass=user)(sAMAccountName=*))
|
||||
GROUP_DN DN группы: вывести все атрибуты всех её пользователей
|
||||
NESTED "1" — учитывать вложенные группы (AD chain matching rule)
|
||||
GROUP_DN DN группы: вывести все атрибуты всех её пользователей,
|
||||
default CN=GL_sarex-users,OU=special,OU=groups,OU=_etc,OU=GL,OU=_GKUK,DC=local,DC=uralkali,DC=com
|
||||
NESTED "1" (default) — учитывать вложенные группы (AD chain matching rule),
|
||||
"0" — только прямые члены группы
|
||||
KRB5_PRINCIPAL e.g. svc-keycloak@LOCAL.URALKALI.COM (optional)
|
||||
KRB5_KEYTAB path to keytab, e.g. /opt/keytab/sarex.keytab (optional)
|
||||
TIMEOUT seconds per network op, default 10
|
||||
@ -36,8 +38,11 @@ BASE_DN = os.environ.get("BASE_DN", "DC=local,DC=uralkali,DC=com")
|
||||
BIND_DN = os.environ.get("BIND_DN", "")
|
||||
BIND_PASSWORD = os.environ.get("BIND_PASSWORD", "")
|
||||
SEARCH_FILTER = os.environ.get("SEARCH_FILTER", "(&(objectClass=user)(sAMAccountName=*))")
|
||||
GROUP_DN = os.environ.get("GROUP_DN", "")
|
||||
NESTED = os.environ.get("NESTED", "") == "1"
|
||||
GROUP_DN = os.environ.get(
|
||||
"GROUP_DN",
|
||||
"CN=GL_sarex-users,OU=special,OU=groups,OU=_etc,OU=GL,OU=_GKUK,DC=local,DC=uralkali,DC=com",
|
||||
)
|
||||
NESTED = os.environ.get("NESTED", "1") == "1"
|
||||
KRB5_PRINCIPAL = os.environ.get("KRB5_PRINCIPAL", "")
|
||||
KRB5_KEYTAB = os.environ.get("KRB5_KEYTAB", "")
|
||||
TIMEOUT = int(os.environ.get("TIMEOUT", "10"))
|
||||
@ -204,18 +209,41 @@ def dump_entry(entry):
|
||||
print(f" {attr}: {rendered if len(rendered) > 1 else rendered[0]}")
|
||||
|
||||
|
||||
def dump_raw_entry(entry):
|
||||
dn = entry.get("dn", "?")
|
||||
raw = entry.get("raw_attributes", {})
|
||||
print(f"\n--- {dn} " + "-" * max(0, 60 - len(dn)))
|
||||
for attr in sorted(raw, key=str.lower):
|
||||
rendered = []
|
||||
for v in raw[attr]:
|
||||
if isinstance(v, bytes):
|
||||
try:
|
||||
rendered.append(v.decode("utf-8"))
|
||||
except UnicodeDecodeError:
|
||||
rendered.append(f"0x{v.hex()}")
|
||||
else:
|
||||
rendered.append(str(v))
|
||||
print(f" {attr}: {rendered if len(rendered) > 1 else rendered[0]}")
|
||||
|
||||
|
||||
def check_group_members(conn, label):
|
||||
from ldap3 import SUBTREE
|
||||
|
||||
step(f"Group members: {GROUP_DN} nested={NESTED} ({label})")
|
||||
try:
|
||||
if NESTED:
|
||||
# AD matching rule IN_CHAIN: сразу все пользователи с учётом вложенности
|
||||
found = conn.search(
|
||||
# AD matching rule IN_CHAIN: сразу все пользователи с учётом вложенности.
|
||||
# paged_search — иначе AD молча обрезает выдачу на 1000 записей.
|
||||
entries = list(conn.extend.standard.paged_search(
|
||||
BASE_DN,
|
||||
f"(&(objectClass=user)(memberOf:1.2.840.113556.1.4.1941:={GROUP_DN}))",
|
||||
search_scope=SUBTREE, attributes=["*", "+"],
|
||||
)
|
||||
paged_size=500, generator=True,
|
||||
))
|
||||
ok(f"found {len(entries)} user entries")
|
||||
for entry in entries:
|
||||
dump_raw_entry(entry)
|
||||
return
|
||||
else:
|
||||
found = conn.search(GROUP_DN, "(objectClass=*)", attributes=["member"])
|
||||
if not found or not conn.entries:
|
||||
@ -230,12 +258,6 @@ def check_group_members(conn, label):
|
||||
else:
|
||||
print(f"\n--- {dn} --- not a readable user entry: {conn.result}")
|
||||
return
|
||||
if not found:
|
||||
fail(f"search failed: {conn.result}")
|
||||
return
|
||||
ok(f"found {len(conn.entries)} user entries")
|
||||
for entry in conn.entries:
|
||||
dump_entry(entry)
|
||||
except Exception as e: # noqa: BLE001
|
||||
fail("group members", e)
|
||||
|
||||
@ -294,10 +316,20 @@ def main():
|
||||
if 636 in PORTS:
|
||||
check_tls(636)
|
||||
|
||||
conn = check_ldap_anonymous(389) or check_ldap_anonymous(636)
|
||||
ldap_ports = [p for p in PORTS if p in (389, 636)] or [389, 636]
|
||||
|
||||
conn = None
|
||||
for port in ldap_ports:
|
||||
conn = check_ldap_anonymous(port)
|
||||
if conn:
|
||||
break
|
||||
|
||||
if BIND_DN and BIND_PASSWORD:
|
||||
bound = check_simple_bind(389) or check_simple_bind(636)
|
||||
bound = None
|
||||
for port in ldap_ports:
|
||||
bound = check_simple_bind(port)
|
||||
if bound:
|
||||
break
|
||||
if bound:
|
||||
check_search(bound, "simple bind")
|
||||
if GROUP_DN:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user