Skip to content

sudo_ldap_role_to_priv: treat an invalid sudoNotAfter as expired - #580

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:ldap-gentime-fail-closed
Oct 26, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:ldap-gentime-fail-closed

Conversation

@iefa-m

@iefa-m iefa-m commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

sudo_ldap_role_to_priv() stores parse_gentime() for sudoNotBefore/sudoNotAfter without checking it, and the -1 error value is the same as UNSPEC, which sudoers_lookup() reads as "no time restriction". parse_gentime() also only accepted one fraction digit, so a valid GeneralizedTime like sudoNotAfter: 20200101000000.00Z fails to parse and the expired role keeps granting the command. With SSSD (sudo_timed defaults to false) or LDAP with SUDOERS_TIMED off, sudo is the only thing enforcing the limit; testsudoers -i ldif prints "Command allowed" for such a role, while the sudoers grammar rejects the same value.

An unparseable time now makes the role expired (NOTAFTER at the epoch) with a warning when warnings are on, which matches what the sudoers parser does by refusing the rule. parse_gentime() now skips the remaining fraction digits so valid directory values work. check_gentime gets multi-digit fraction cases and testsudoers test34 covers the LDIF path; it fails before the change and make check in plugins/sudoers passes after.

parse_gentime() returns -1 on error, which is also the value of UNSPEC, so a sudoNotBefore or sudoNotAfter value that cannot be parsed made the sudoRole unrestricted instead of time-limited. parse_gentime() only accepted one fraction digit, so a valid GeneralizedTime such as 20200101000000.00Z took this path and an expired role kept working. The sudoers grammar already rejects an invalid NOTBEFORE/NOTAFTER value.

Treat a role with an unparseable time as expired, warning when warnings are enabled, and let parse_gentime() skip any number of fraction digits. Add check_gentime cases and a testsudoers regression test.

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

@millert
millert merged commit 70e6437 into sudo-project:main Oct 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants