Review main Merged

96393[TASK] Add auth principal and local identity provider

Benni Mack CR +2 V +2 Hard +856 −44 updated 10/24/26, 07:25

Commit message

Authentication code needs a way to describe who is calling without
handing out the mutable user authentication object, and one place that
looks up be_users and fe_users records with the same visibility rules.
Both are added to EXT:core as internal groundwork for the
authentication modernization.

The Principal holds the PrincipalContext of the permission set API,
which carries role, id, groups and impersonation, and adds what only
authentication knows: the realm, the username and the group names. The
role of the context is the only source of the authorization level, and
frontend principals always carry the role USER. The user aspect of the
context API can be created from a Principal.

The LocalIdentityProvider offers separate lookups for backend and
frontend users. A frontend lookup names its storage page restriction
explicitly, and a username lookup that matches more than one record is
refused instead of returning an arbitrary one.

The command line user is resolved through the identity provider, which
also means that a _cli_ user that exists more than once is refused
instead of an arbitrary one being used. A missing one is checked again
and created under an exclusive lock, so that command line processes
starting at the same time no longer create it twice. A process that
waited for the lock uses the user the other one created, as the user
is looked up again after the creation instead of relying on whether
this process created it. ensureCliUserExists() therefore no longer
returns that. The thereby unused lookup helpers setBeUserByName() and
getRawUserByName() are removed.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Benjamin Franzke +1
    • Georg Ringer +1
  • Verified V +2 Done
    • Benni Mack +2
    • Benjamin Franzke +1
    • Georg Ringer +1
    • core-ci +1 CI

Issues 2

Files 14

Review log 4156

Show 2131 earlier messages
  1. Benni Mack uploaded patch set 1 10/06/26, 04:50

  2. core-ci voted on patch set 1 V -1 10/06/26, 05:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110174

  3. Benni Mack marked it work in progress 10/06/26, 05:11

  4. Benni Mack uploaded patch set 2 V -1 10/06/26, 05:53

  5. core-ci voted on patch set 2 V +1 10/06/26, 06:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110180

  6. Benni Mack uploaded patch set 3 V +1 10/06/26, 08:11

  7. core-ci voted on patch set 3 V -1 10/06/26, 08:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110202

  8. core-ci voted on patch set 3 V +1 10/06/26, 08:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110202

  9. Benni Mack marked it ready for review 10/07/26, 10:44

  10. Benjamin Franzke commented on patch set 3 10/08/26, 06:37

    Principal.php:31

    FYI: Something similar was introduced in > 92211: [TASK] Decouple BackendUserAuthentication::writelog | https://review.typo3.org/c/Packages/TYPO3.CMS/+/92211 Maybe this can be consolidated with the `Security/PermissionSet/PrincipalContext` that was created there.
  11. Oli Bartsch uploaded patch set 4 V +1 10/08/26, 20:01

  12. Oli Bartsch commented on patch set 4 10/08/26, 20:04

    Principal.php:31 Reply

    Hey! Thanks, I've consolidated this: Principal now uses the PrincipalRole from 92211 and is the single source for PrincipalContext via toPrincipalContext(). The remaining derivation in LogEntryRepository will follow in a separate change.
  13. core-ci voted on patch set 4 V -1 10/08/26, 20:09 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110526

  14. Oli Bartsch uploaded patch set 5 V -1 10/08/26, 20:15

  15. core-ci voted on patch set 5 V -1 10/08/26, 20:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110527

  16. Benni Mack commented on patch set 5 10/09/26, 09:09

    Breaking-110924-RemovedUserLookupHelpersOfUserAuthentication.rst:6

    I don't think we should create a breaking RST, because -> IF we are going to go further with Authentication in v15, this will be the least issue people will have :)
  17. Oli Bartsch uploaded patch set 6 V -1 10/09/26, 10:18

  18. Oli Bartsch commented on patch set 6 10/09/26, 10:19

    Breaking-110924-RemovedUserLookupHelpersOfUserAuthentication.rst:6 Reply

    Agreed, both were internal: the changelog entry and the [!!!] are removed.
  19. core-ci voted on patch set 6 V +1 10/09/26, 10:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110579

  20. Oli Bartsch uploaded patch set 7 V +1 10/09/26, 13:00

  21. core-ci voted on patch set 7 V +1 10/09/26, 13:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110603

  22. Oli Bartsch rebased onto patch set 8 V +1 10/09/26, 20:49

  23. core-ci voted on patch set 8 V -1 10/09/26, 21:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110717

  24. core-ci voted on patch set 8 V +1 10/09/26, 21:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110717

  25. Georg Ringer voted on patch set 8 CR +1 V +1 10/10/26, 06:26

  26. Wouter Wolters voted on patch set 8 CR +1 V +1 10/11/26, 09:50

  27. Markus Klein commented on patch set 8 10/11/26, 11:31

    CommandLineUserCreation.php:49

    This could deserve a slight performance improvement. Check for existence BEFORE the lock. And only if it does not exist: lock, check again, create, unlock This way the process does not get locked up the queue for the critical section, just because it needs to check for existence.
  28. Benjamin Franzke commented on patch set 8 10/12/26, 09:13

    I propose to add a `PrincipialInterface` (that is implemented by AbstractUserAuthentication) instead of a new value object and let that be implemented by `AbstractUserAuthentication`. That would be a similar construct to the `TranslatorInterface` that was implemented in `LanguageService` recently, where a new restricted and consolidated interface was added. This way we can use `PrincipialInterface` everywhere where `AbstractUserAuthentication` is available today and can evaluate which requirements are actually needed (it seems like this patch needs to guess quite some parts that *may* be needed later).

    Principal.php:31 Reply

    Can we extend (or phase out) the existing `PrincipalContext` – I think we should avoid having too many layers that *mean* the same. The mentioned patch was merged with basically the justification as this patch/relation-chain: > This is a preparation for decoupling permission handling from the necessity of always having a BackendUserAuthentication instance.
  29. Oli Bartsch uploaded patch set 9 CR +1 V +1 10/12/26, 12:32

  30. Oli Bartsch commented on patch set 8 10/12/26, 12:39

    Reply

    I looked into this, but I don't think an interface implemented by AbstractUserAuthentication can replace the value object. The principal exists before and without a user object. The authenticators in https://review.typo3.org/c/Packages/TYPO3.CMS/+/95287 / https://review.typo3.org/c/Packages/TYPO3.CMS/+/95288 return it before any user authentication object is built, and in https://review.typo3.org/c/Packages/TYPO3.CMS/+/96561 the backend user is built from the principal only after the login checks have passed. With an interface on AbstractUserAuthentication, every authenticator would first need a fully initialised user object, which is the coupling this chain removes. AbstractUserAuthentication also changes during a request (switch user, workspace, logoff), while the pipeline result has to be a snapshot. You are right about the guessing, though: claims, getClaim(), displayName, authenticatedAt and toPrincipalContext() had no consumer in Core and are removed. They can come back with their first consumer. If a narrow read interface (id, role, group ids) is still useful for consumers like UserAspect or LogEntryRepository, implemented by both the Principal and BackendUserAuthentication, I'm happy to add it in a follow-up.

    Principal.php:31 Reply

    Agreed. Two types carrying the same four fields was one layer too many. Principal now composes the PrincipalContext instead of duplicating it. Principal adds what only authentication knows (realm, username, group names, authentication methods). This also matches the docblock of PrincipalContext, which describes it as part of the Principal object. Phasing PrincipalContext out completely does not work, as it also covers SYSTEM and MAINTAINER contexts without a user record.
  31. Oli Bartsch commented on patch set 9 10/12/26, 12:39

    CommandLineUserCreation.php:49 Reply

    Done. existence is checked first, and only a missing user takes the lock, is checked again and created.
  1. core-ci voted on patch set 9 V +1 10/12/26, 12:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110903

  2. Markus Klein commented on patch set 9 10/12/26, 14:19

    CommandLineUserCreation.php:48

    Reading this again, I'm not sure about the return value. We return false if it did exist, and only true, if we just created it. That's not reflected by the method's name. At least I wouldn't derive this behaviour from the name and the description
  3. Oli Bartsch uploaded patch set 10 V +1 10/12/26, 19:57

  4. Oli Bartsch commented on patch set 10 10/12/26, 19:59

    CommandLineUserCreation.php:48 Reply

    Good catch.. caller now looks the user up again after ensureCliUserExists() instead of relying on its result, and the method returns void.
  5. core-ci voted on patch set 10 V +1 10/12/26, 20:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110939

  6. Andreas Kienast commented on patch set 10 10/22/26, 08:25

    LocalUserLookup.php:105

    IMO this should be an `elseif`, be_users AND storage PIDs contradict each other.
  7. Benni Mack uploaded patch set 11 V +1 10/23/26, 10:34

  8. core-ci voted on patch set 11 V +1 10/23/26, 10:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112270

  9. Benni Mack commented on patch set 11 10/23/26, 11:36

    LocalUserLookup.php:105 Reply

    Done
  10. Benni Mack uploaded patch set 12 V +1 10/23/26, 12:42

  11. Benni Mack commented on patch set 12 10/23/26, 12:43

    CommandLineUserCreation.php:48 Reply

    Done

    Principal.php:31 Reply

    please lets add the PrincipalInterface when we need it?
  12. Benni Mack commented on patch set 12 10/23/26, 12:43

    Reply

    yes. please add it as a followup
  13. Benni Mack commented on patch set 12 10/23/26, 12:43

    Reply

    Done
  14. Benjamin Franzke commented on patch set 12 10/23/26, 12:54

    LocalUserLookup.php:44

    The term "local" sounds like we already have remote users. Also it is very similar to our `Repository` patterns. Maybe just `UserRepository`?

    Principal.php:59

    It is hard for me to grasp why this is needed. I guess to detect if the user has `mfa` in progress. That's basically state of the user, not **the user principal** itself. On the other hand the relation chain introduces a `BadgeInteface` concept to describe derived data or state. It feels like this is rather a badge than part of the identity (=principal)? Can this be extracted? I'd wish for the Principal to only describe the user and realm, similar to kerberos principals: https://web.mit.edu/kerberos/krb5-1.5/krb5-1.5.4/doc/krb5-user/What-is-a-Kerberos-Principal_003f.html
  15. core-ci voted on patch set 12 V +1 10/23/26, 12:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112299

  16. Benni Mack uploaded patch set 13 V +1 10/23/26, 13:13

  17. Benni Mack commented on patch set 13 10/23/26, 13:14

    Principal.php:59 Reply

    removed it for both
  18. Benni Mack commented on patch set 13 10/23/26, 13:14

    LocalUserLookup.php:44 Reply

    Called it Provider

    Principal.php:59 Reply

    Done
  19. core-ci voted on patch set 13 V +1 10/23/26, 13:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112304

  20. Benjamin Franzke commented on patch set 13 10/23/26, 14:11

    Principal.php:54

    Sorry, I stumbled over another thing: `$groupNames` seems to be redundant with `PrincipalContext->groupIds` and is optional. Is that on purpose? In general I wonder why `$groupNames` is optional. Maybe that is related to my question in https://review.typo3.org/c/Packages/TYPO3.CMS/+/95284/comment/5da3fa40_7f0678a3/ where it seems that we have intermediate and hydrated Principals. I think, if we add this redundancy (i guess for the UserAspect derivation), we should require it to be always present, in order to avoid forgetting to supply the group names. *(Other than that +1 from my side, although it feels still a bit rough to have a PrincipalContext and a Principal, but I can't express why.)*
  21. Benni Mack commented on patch set 13 10/23/26, 14:21

    Principal.php:54 Reply

    PrincipalContext was because Olly started Authorization (and not Authentication), we should have had a better differentiation before. We need the groupNames because we are in UserContext so we make actually use of it at some point, and this is where we do. I hope we could migrate this away at some point.
  22. Benjamin Franzke commented on patch set 13 CR +1 V +1 10/23/26, 14:37

    Principal.php:54 Reply

    Ok, I can vote this (as this patch basically prepares but doesn't really uses the principal) in order to move forward, but I guess we'll need to revisit this as already mentioned (intermediate vs hydrated Principals): https://review.typo3.org/c/Packages/TYPO3.CMS/+/95284/comment/5da3fa40_7f0678a3/
  23. Georg Ringer voted on patch set 13 CR +1 V +1 10/24/26, 06:57

  24. Benni Mack voted on patch set 13 CR +2 V +2 10/24/26, 07:25

  25. Benni Mack merged patch set 14 10/24/26, 07:25