Skip to content

Commit

Permalink
ignore UIDs created as a result of CTF mishap (#239)
Browse files Browse the repository at this point in the history
* ignore UIDs created as a result of CTF mishap

During the CTF, a user was created with UID 13371337 for a challenge,
which resulted in new users being created with UIDs > 13370000. Ignore
all such users when calculating the next UID to generate (the current
users in that UID range will keep their UIDs).

* Fix typo
  • Loading branch information
ethanwu10 authored Dec 4, 2021
1 parent e4dddf8 commit 44bb2c7
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit 44bb2c7

Please sign in to comment.