Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore UIDs created as a result of CTF mishap #239

Merged
merged 2 commits into from
Dec 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ocflib/account/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
(61184, 65535),
]

IGNORED_UID_RANGES = [
# Incident with OCF CTF resulted in users being created in this range
(13371337, 13371800),
]


def _get_first_available_uid(known_uid=_KNOWN_UID):
"""Return the first available UID number.
Expand All @@ -65,13 +70,24 @@ def _get_first_available_uid(known_uid=_KNOWN_UID):
entries greater than that for performance. This value can then be cached
and passed back in to make subsequent calls faster.
"""
assert all(start <= end for start, end in IGNORED_UID_RANGES)

with ldap_ocf() as c:
c.search(
OCF_LDAP_PEOPLE,
'(uidNumber>={KNOWN_MIN})'.format(KNOWN_MIN=known_uid),
attributes=['uidNumber'],
)
uids = [int(entry['attributes']['uidNumber']) for entry in c.response]

def is_ignored_uid(uid):
for start, end in sorted(IGNORED_UID_RANGES):
if start <= uid <= end:
return True
return False

uids = [uid for uid in uids if not is_ignored_uid(uid)]

if uids:
max_uid = max(uids)
else:
Expand All @@ -80,7 +96,7 @@ def _get_first_available_uid(known_uid=_KNOWN_UID):

assert all(start <= end for start, end in RESERVED_UID_RANGES)
next_uid = max_uid + 1
for start, end in sorted(RESERVED_UID_RANGES):
for start, end in sorted(RESERVED_UID_RANGES + IGNORED_UID_RANGES):
if start <= next_uid <= end:
next_uid = end + 1

Expand Down