Skip to content

fix: reject empty identity attributes in policy - #603

Merged
EthanHeilman merged 3 commits into
openpubkey:mainfrom
SashaMIT:fix/policy-validation-guards
Aug 14, 2026
Merged

EthanHeilman merged 3 commits into
openpubkey:mainfrom
SashaMIT:fix/policy-validation-guards

Conversation

@SashaMIT

Copy link
Copy Markdown
Contributor

Summary

Two input-validation guards for auth_id policy rows, in the spirit of the match-any guard already present in validateClaim:

  1. Empty identity attribute. FromTable accepts any 3-column row without validating the identity field, and the enforcer compares with strings.EqualFold(claims.Email, user.IdentityAttribute), which is true when both sides are empty. A row like root "" <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 in sshcert/sshcert.go). The bare match-any wildcard form is already rejected; the empty string was unguarded.

    • FromTable now records a ConfigProblem and skips the row.
    • validateClaim treats an empty identity attribute as never matching.
  2. oidc-match-end:email: suffix without an @ boundary. The suffix match uses strings.HasSuffix with no @ anchor, so oidc-match-end:email:example.com also matches attacker@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 in docs/config.md already 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)
  • New tests: empty identity row skipped by FromTable with 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

…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>
Comment thread policy/enforcer.go Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@EthanHeilman

Copy link
Copy Markdown
Member

@EthanHeilman

EthanHeilman commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

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>
@SashaMIT SashaMIT changed the title fix: reject empty identity attributes and unbound email suffix matches in policy fix: reject empty identity attributes in policy Aug 13, 2026
@SashaMIT

Copy link
Copy Markdown
Contributor Author

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 EthanHeilman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for fixing this

@EthanHeilman
EthanHeilman merged commit 7d4029f into openpubkey:main Aug 14, 2026
18 checks passed
@SashaMIT

Copy link
Copy Markdown
Contributor Author

Thanks Ethan. Glad the empty-identity guard landed.

sdwilsh pushed a commit to sdwilsh/ansible-playbooks that referenced this pull request Oct 7, 2026
##### [\`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>
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