Repository navigation
fix: reject empty identity attributes in policy - #603
Conversation
…s in policy Two input-validation guards for auth_id policy rows: - FromTable now skips rows with an empty identity attribute and records a ConfigProblem, and validateClaim treats an empty identity attribute as never matching. Previously a row such as `root "" <issuer>` (for example from a config template with an unset variable) matched every token from that issuer that carries no email claim, which Azure-class OPs commonly omit. This extends the existing match-any guard to the empty-string case. - The oidc-match-end:email: match value must now begin with @, both at parse time (ConfigProblem) and at match time. Previously oidc-match-end:email:example.com also matched attacker@evil-example.com. The docs already show the @ form, so this enforces documented usage. Co-authored-by: Cursor <cursoragent@cursor.com>
| if strings.HasSuffix(strings.ToLower(claims.Email), strings.ToLower(user.IdentityAttribute[len(OIDC_WILDCARD_EMAIL):len(user.IdentityAttribute)])) { | ||
| if suffix, isWildcard := strings.CutPrefix(user.IdentityAttribute, OIDC_WILDCARD_EMAIL); isWildcard { | ||
| // The match value must begin with @ to bind the suffix to an email | ||
| // domain; "example.com" would also match attacker@evil-example.com |
There was a problem hiding this comment.
This is a postfix match, so matching ".*example.com" would also match "attacker@evil-example.com", "goodperson@email.example.com", and "ethan@eeexample.com". While you could do a match on everything after "@", the match here is designed to be more flexible.
|
Related PR and Issue |
|
Worthwhile to fix 1, but 2 I see as working as designed. I've had a number of AI scanners recommend splitting on the "@" to avoid someone writing an insecure policy, but I prefer to be more flexible here. If you change this to 1 only, I'll merge. |
Drop the oidc-match-end:email: @-boundary check. That postfix match is working as designed. Signed-off-by: SashaMIT <sash@ela.city>
|
You're right on 2. That postfix match is working as designed, and I will not fight the flexibility. Dropped the @-boundary check. This PR is now only the empty identity attribute guard: empty row skipped at parse time, never matches at enforce time. |
EthanHeilman
left a comment
There was a problem hiding this comment.
LGTM, thanks for fixing this
|
Thanks Ethan. Glad the empty-identity guard landed. |
##### [\`v0.17.0\`](https://github.com/openpubkey/opkssh/releases/tag/v0.17.0) ##### 🚀 Features - feat: support CI/CD login from Forgejo Actions (Codeberg) [@Blacks-Army](https://github.com/Blacks-Army) ([#580](openpubkey/opkssh#580)) - ssh-agent off by default [@EthanHeilman](https://github.com/EthanHeilman) ([#626](openpubkey/opkssh#626)) - feat: add GitLab CI provider support [@cgroschupp](https://github.com/cgroschupp) ([#559](openpubkey/opkssh#559)) - fix(verify): Rejects unsafe principals in authorized_keys [@EthanHeilman](https://github.com/EthanHeilman) ([#597](openpubkey/opkssh#597)) - Warn when a policy row matches on an unverified email [@arpitjain099](https://github.com/arpitjain099) ([#594](openpubkey/opkssh#594)) - Support sshd_session_t SELinux domain in installer [@ozan956](https://github.com/ozan956) ([#614](openpubkey/opkssh#614)) - login: load certificate into ssh-agent with configurable lifetime [@sini](https://github.com/sini) ([#611](openpubkey/opkssh#611)) - policy/plugins: marshal GROUPS and AUD env JSON with encoding/json [@SashaMIT](https://github.com/SashaMIT) ([#601](openpubkey/opkssh#601)) ##### 🐛 Bug Fixes - fix(verify): Rejects unsafe principals in authorized_keys [@EthanHeilman](https://github.com/EthanHeilman) ([#597](openpubkey/opkssh#597)) - fix: Policy footguns [@EthanHeilman](https://github.com/EthanHeilman) ([#596](openpubkey/opkssh#596)) - fix: Regression test for --private-key-file arg higher precedence over \~/.ssh/opkssh [@EthanHeilman](https://github.com/EthanHeilman) ([#592](openpubkey/opkssh#592)) - Accept a string email_verified claim in the plugin env vars [@arpitjain099](https://github.com/arpitjain099) ([#595](openpubkey/opkssh#595)) - Deny malformed oidc policy rows instead of panicking [@arpitjain099](https://github.com/arpitjain099) ([#593](openpubkey/opkssh#593)) ##### Chores - dep: Update to OpenPubkey v0.27.0 [@EthanHeilman](https://github.com/EthanHeilman) ([#598](openpubkey/opkssh#598)) - fix(deps): Update release-drafter/release-drafter action to v7.7.0 @[renovate\[bot\]](https://github.com/apps/renovate) ([#590](openpubkey/opkssh#590)) - fix(deps): Update actions/setup-go action to v7 @[renovate\[bot\]](https://github.com/apps/renovate) ([#578](openpubkey/opkssh#578)) - fix(deps): Update release-drafter/release-drafter action to v7.6.0 @[renovate\[bot\]](https://github.com/apps/renovate) ([#581](openpubkey/opkssh#581)) - \[fix] Windows linter errors [@EthanHeilman](https://github.com/EthanHeilman) ([#577](openpubkey/opkssh#577)) - fix(deps): Update zizmorcore/zizmor-action action to v0.6.0 @[renovate\[bot\]](https://github.com/apps/renovate) ([#575](openpubkey/opkssh#575)) - fix(deps): Update Docker @[renovate\[bot\]](https://github.com/apps/renovate) ([#568](openpubkey/opkssh#568)) - Bump testcontainers-go to 0.43.0 [@EthanHeilman](https://github.com/EthanHeilman) ([#571](openpubkey/opkssh#571)) - Update CLI documentation @[github-actions\[bot\]](https://github.com/apps/github-actions) ([#627](openpubkey/opkssh#627)) - fix(deps): Update dependency ubuntu to v26 @[renovate\[bot\]](https://github.com/apps/renovate) ([#616](openpubkey/opkssh#616)) - chore(deps): bump github.com/moby/go-archive from 0.2.0 to 0.3.0 @[dependabot\[bot\]](https://github.com/apps/dependabot) ([#608](openpubkey/opkssh#608)) - fix: reject empty identity attributes in policy [@SashaMIT](https://github.com/SashaMIT) ([#603](openpubkey/opkssh#603)) - fix(deps): Update go toolchain directive to v1.26.6 @[renovate\[bot\]](https://github.com/apps/renovate) ([#605](openpubkey/opkssh#605)) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Summary
Two input-validation guards for
auth_idpolicy rows, in the spirit of the match-any guard already present invalidateClaim:Empty identity attribute.
FromTableaccepts any 3-column row without validating the identity field, and the enforcer compares withstrings.EqualFold(claims.Email, user.IdentityAttribute), which is true when both sides are empty. A row likeroot "" <issuer>(plausible from a config template with an unset variable) therefore matches every token from that issuer that carries no email claim. Azure-class OPs commonly omit the email claim (noted insshcert/sshcert.go). The bare match-any wildcard form is already rejected; the empty string was unguarded.FromTablenow records aConfigProblemand skips the row.validateClaimtreats an empty identity attribute as never matching.oidc-match-end:email:suffix without an@boundary. The suffix match usesstrings.HasSuffixwith no@anchor, sooidc-match-end:email:example.comalso matchesattacker@evil-example.com. The match value must now begin with@, enforced both at parse time (ConfigProblem, row skipped) and at match time (logged and treated as no match). The docs example indocs/config.mdalready shows the@form (oidc-match-end:email:@example.com), so this enforces documented usage. Previously only the empty suffix was rejected.Both changes fail closed: an invalid row is skipped at load time and can never match at enforcement time, and one bad row still does not affect any other row.
Test plan
go build ./...go test ./...(all packages pass)FromTablewith a recorded problem; empty identity never matches a token with no email claim;oidc-match-end:email:without@rejected, including the lookalike-domain case;@form still matches (regression)Happy to split this into two PRs if you would rather review them separately.
Made with Cursor