Skip to content

SCIM: sync the Enterprise User extension into user attributes (§8.2) - #22

Open
Yoshiofthewire wants to merge 21 commits into
kyguard/scorecardfrom
kyguard/scim-enterprise
Open

Yoshiofthewire wants to merge 21 commits into
kyguard/scorecardfrom
kyguard/scim-enterprise

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: SCIM now syncs title, department and manager (Enterprise User extension) into read-only user attributes, so reports can filter accounts by their owner's department.

§13 Phase 1A items: "attributes, SCIM Enterprise User extension (§8.2)".

What changed

  • The SCIM User resource registers urn:ietf:params:scim:schemas:extension:enterprise:2.0:User.
  • Create and PUT set all three values (an omitted one is cleared); PATCH changes only the values its operations touch (with or without the extension URI, manager.value, path-less maps).
  • Values are written with source = 'scim', so admins cannot edit them (Inventory: accounts, assets, descriptors and attributes (§8.2, §10) #20).
  • Deleting a SCIM user first clears it as owner of its accounts and deletes its attribute values (accounts.owner_user_id references the user, so the delete failed before).

Review this

Checked: TestEnterpriseUserAttributes (create, PATCH replace/remove/path-less/manager.value, PUT clearing, delete of an owner); 11 mutations killed.
Not checked: against a live IdP. GET does not echo the synced values back (DECISIONS 209).
Decided for you: DECISIONS 209.
You need to: nothing.

Detail
# Mutation Killed by
C1 PUT keeps values it omits TestEnterpriseUserAttributes
C2 synced values stored as admin-sourced TestEnterpriseUserAttributes
C3 extension PATCH path ignored TestEnterpriseUserAttributes
C4 delete skips ForgetUser TestEnterpriseUserAttributes
C5 create does not sync TestEnterpriseUserAttributes
C6 manager.displayName overwrites the manager TestEnterpriseUserAttributes
C7 a failed create leaves the user behind TestEnterpriseUserAttributes
C8 PATCH writes the profile before its attributes are checked TestEnterpriseUserAttributes
C9 a definition SCIM does not own is ignored TestEnterpriseUserAttributes
C10 attributes committed in their own transaction TestSCIMProfileAndAttributesAreAtomic
C11 prepare creates the SCIM definitions in their own transactions again TestEnterpriseUserAttributes ("a refused create left definitions behind")

Guide findings fixed: a create whose attribute sync fails now removes the new user so the IdP's retry starts clean; manager sub-attributes other than value are ignored. Second round (724d59e): prepare ensures the SCIM definitions before any user write, so a PATCH, PUT, create or adoption that cannot write its attributes changes nothing (400 mutability). Third round: a whole-extension PATCH path is refused by the library (400 invalidPath), pinned by a test; the security P2 ("commit SCIM profile and attribute changes atomically") is fixed in 073974f: the user write and its synced attributes, sessions and audit rows are one transaction (User.SCIMAttributes applied inside CreateUser/updateProfile). Guide "nonatomic deletion" fixed in 4328357: a SCIM delete clears ownership, deletes the attribute values and deletes the user in one transaction (atomic by construction; no fault-injection test for it). Round 4 (a1cc78b): Guide "Partial persistence": prepare now only reads and refuses a key an admin defined, and applySCIMAttributes creates a missing scim definition (ON CONFLICT DO NOTHING, audited) inside the user's own transaction, so a refused or rolled-back request leaves no definition behind (C11; TestSCIMProfileAndAttributesAreAtomic now also checks a rolled-back manager definition).

Round 6 (alder): merging main (through #21) conflicted in two places; both sides were kept.

  • internal/scim/handler.go create: main's issuer check runs first, then the attribute preparation; the user write carries both SCIMAttributes and main's WithAudit record.
  • internal/store/sqlstore.go CreateUser and updateProfile: the SCIM attributes are written, then main's audit record is appended, in the same transaction, so a failed attribute write still commits nothing.
  • enterprise_test.go follows main: RegisterRoutes(mux.Handle), and a SCIM issuer is configured (main refuses an externalId without one, §7.2).

Checks (round 6): internal/scim, internal/store, internal/api, internal/reporting (k80, SQLite) at #23; full suites at the bottom (#20) and top (#24).

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-22, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/scim-enterprise branch 3 times, most recently from 940da94 to 724d59e Compare November 25, 2026 13:07
Yoshiofthewire and others added 4 commits November 25, 2026 08:21
…8.2)

The User resource now registers the Enterprise User extension. Core
title and the extension's department and manager.value are written as
SCIM-sourced user attributes on create, PUT (omitted values cleared)
and PATCH (only touched values), so reports can filter accounts by
their owner's department. Admins cannot edit them. Deleting a SCIM
user first clears it as account owner and removes its attribute values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A create whose attribute sync failed left the user behind, so the IdP's
retry hit a uniqueness error. The user is now removed before the error
returns. PATCHing manager.displayName or manager.$ref (or a manager
object without value) no longer overwrites or clears the stored manager.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A PATCH, PUT, create or adoption whose title, department or manager
could not be written (an attribute of that key that SCIM does not own)
used to fail after the profile write had committed. prepare now ensures
the SCIM definitions first and refuses the request (400 mutability)
before anything is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

On the Guide's notes at d458abc:

  • Ignored extension: this form cannot succeed. The SCIM library rejects a PATCH whose path is the whole extension URN with 400 invalidPath before the handler runs. TestEnterpriseUserAttributes now pins that refusal (ce75f86).
  • Partial PATCH: partly addressed, and the rest is left for the owner. Since 724d59e, every condition that can be predicted (an attribute key SCIM does not own) is checked before any write, so those requests change nothing. What remains is a transient store failure (a cancelled context or a lost database connection) between the profile write and the attribute writes. Closing that needs the user store and the inventory store to share one transaction across UpdateSCIMProfile and SetValue. That changes an inherited store API that hawthorn's sso: identity by (issuer, subject); fresh, per-app sign-in #7 also edits, so I have not made it in this stack. The IdP retries a failed PATCH or PUT, and SetValue is idempotent, so a retry converges.

The security review found that a PATCH committed the profile change and
session revocation before the attribute writes, so a later failure left
a half-applied request. The handler now hands the changes to the store
on the User it writes (SCIMAttributes, never stored on the row), and
CreateUser and updateProfile apply them, with their audit rows, inside
their own transaction. The create compensation is gone: a failed create
writes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

The security P2 at ce75f86 ("commit SCIM profile and attribute changes atomically") is fixed at 073974f. It also covers the Guide's "Failed Cleanup" note.

  • The handler puts the synced values on the User it writes (SCIMAttributes, never stored on the row). CreateUser and updateProfile apply them, with their audit rows, inside their own transaction. The paths are create, adoption (TakeOverForSCIM), PUT and PATCH. The profile, session revocation, attribute values and audits now commit or roll back together, and the create compensation (which used the request context) is gone.
  • Fault-injection test TestSCIMProfileAndAttributesAreAtomic: an update changes status and two attributes, and the second attribute write fails. The status, the session and the first attribute all stay unchanged. Mutation: committing the attributes in their own transaction makes it fail.

Yoshiofthewire and others added 2 commits November 25, 2026 09:21
ForgetUser now also deletes the user row, so a failed SCIM delete leaves
the account ownership and attribute values untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

On the Guide's notes at 4328357:

  • Ignored PATCH: fixed. A title path qualified with the core User schema URI is now the same attribute (test added).
  • Partial Writes: this is intended, not a defect. department, manager and title are reserved for SCIM: the admin API refuses to define them (DECISIONS 200). A SCIM definition that survives a rejected request therefore reserves nothing that was not already SCIM's, and the next SCIM request reuses it. A refused request writes no user and no values.

Yoshiofthewire and others added 3 commits November 25, 2026 13:34
prepare created each missing SCIM definition in its own transaction
before checking the others, so a refused request (an admin owning
title, say) still claimed department and manager for SCIM. prepare now
only reads and refuses; applySCIMAttributes inserts a missing scim
definition (ON CONFLICT DO NOTHING, audited) inside the user write, so
a rollback takes the definitions with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Partial persistence: fixed in a1cc78b. prepare now only reads, and refuses a key an admin defined before anything is written. A missing SCIM definition is created by applySCIMAttributes (ON CONFLICT DO NOTHING, audited) inside the user's own transaction, so a refused or rolled-back request leaves no definition behind. TestEnterpriseUserAttributes posts title, department and manager while an admin owns title, then checks that only that one definition exists; going back to the old prepare fails it with "left definitions behind: 3" (C11).

Yoshiofthewire and others added 5 commits November 25, 2026 19:53
# Conflicts:
#	internal/scim/handler.go
#	internal/store/sqlstore.go
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main refuses an externalId while no SCIM issuer is set (§7.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant