Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization scenarios and mechanisms analysis #763

Closed
Tracked by #84
martinothamar opened this issue Sep 11, 2024 · 1 comment
Closed
Tracked by #84

Authorization scenarios and mechanisms analysis #763

martinothamar opened this issue Sep 11, 2024 · 1 comment
Assignees

Comments

@martinothamar
Copy link
Contributor

martinothamar commented Sep 11, 2024

Description

We need to get an overview of common authorization scenarios and mechanisms that exist today and will be implemented into the platform. Here are some movements happening where there are questions related to authorization.

In scope

  • Map out the inbound flow and possible contexts
  • Map out the outbound flow (which tokens and mechanisms are used)
  • Start a design to better abstract authenticated state and context

Analysis

Mechanisms for authorization

These methods are supported through Altinn Authentication and Authorization through PEP and PDP.

  • User token (logged in through Altinn)
    • Authorized as: person
    • Access control: roles, instance delegations, dedicated XACML rules
  • Org token
  • Systemuser
    • Authorized as: system user
    • Access control: roles, system user delegations (what actions the system user owner approves that the system can do on behalf of the system user owner)
    • A system user is a special Maskinporten client (in principle) using Rich Authorization Request (RAR) protocol to enrich Maskinporten tokens with Altinn system user details (systemuser_id, system_id)
  • App (WIP)

User flow

Log into tt02 manually, then navigate to an app

  • Log into tt02.altinn.no - altinnContext cookie is set (this is still A2 I think)
    • Some base64 stuff?
  • Choose party/reportee - altinnContext and altinnReportee cookies are set (this is still A2 I think)
  • Go to Altinn 3 app URL directly - 302 redirect to platform.tt02.altinn.no/authentication/api/v1/authentication then back again
    • AltinnStudioRuntime is set by Authn API, it is a JWT, see below
  • Frontend renders party selection
    • Queries user, parties and current party (/profile/user, /parties, /authorization/parties/current)
  • Party selection invokes PUT /parties/{partyId}, AltinnPartyId cookie is set
  • App is rendered

JWT token claims:

{
  "nameid": "<int>",
  "urn:altinn:userid": "<int>",
  "urn:altinn:partyid": <int>,
  "urn:altinn:authenticatemethod": "<string>",
  "urn:altinn:authlevel": <int>,
  "scope": "altinn:portal/enduser"
}

Q:

  • The partyid claim in the auth cookie can differ from altinnReportee and AltinnPartyId, how does this stay consistent?

Self identified users

{
  "nameid": "<int>",
  "urn:altinn:userid": "<int>",
  "urn:altinn:username": "<string>",
  "urn:altinn:partyid": <int>,
  "urn:altinn:authenticatemethod": "SelfIdentified",
  "urn:altinn:authlevel": 0,
  "scope": "altinn:portal/enduser"
}

Org flow

  • Authenticate with a Maskinporten client
  • Exchange the token through Altinn authentication
  • Resulting Altinn token functions as an org token (XACML must allow org actions)

JWT token claims

{
  "urn:altinn:org": "<string>",
  "urn:altinn:orgNumber": "<int>",
  "urn:altinn:authenticatemethod": "<string>",
  "urn:altinn:authlevel": <int>
}

System user flow

More details to come, but

  • Make system
  • Use supplier/system enrollment flow to register a system user (which includes delegations)
  • Supplier authenticates with a Maskinporten client including RAR grant
  • Resulting Maskinporten token can be used directly without exchange

Q:

  • Does it really not need to be exchanged?

JWT token

{
  "authorization_details": [
    {
      "type": "urn:altinn:systemuser",
      "systemuser_id": ["ID of system user"],
      "systemuser_org": {
        "authority": "iso6523-actorid-upis",
        "ID": "0192:Org no of the org owning the system user"
      },
      "system_id": "ID of the system in the system register"
    }
  ]
}
More details

An Altinn system user concept consists of the following entities

  • System user (systembruker)
  • System (system)
  • Supplier (leverandør) - the organization providing some automated Altinn-related service
  • Customer (kunde) - the organization using the service provided by the supplier
  • Maskinporten client - Maskinporten provides org-level identities meant for integrating across orgs

The customer owns the system user, and the permissions/delegations are owned by the system user.
The supplier owns the system, and the system owns the Maskinporten client.
The system owner concept/feature in Altinn 3 allows a system to impersonate a system user,
thereby enabling the system to perform operations in Altinn 3 as if it was the system user.
So the system "inherits" all delegations and roles assigned to the system user and can utilize these
by authenticating with Maskinporten using the system user RAR grant.
A key differentiator from the "org token" mechanism is that the system user can have roles similarly to a regular user.
A system user can be viewed as a virtual user owned by some customer/client organization.

App flow

TBD

Outbound authn/authz

  • Storage - user token + APIM subscription key
    • User token comes from IUserTokenProvider which in reality is either the AltinnStudioRuntime cookie or the auth header, so it needs the HTTP Context directly
    • APIM subscription key is used to disallow anything but GET depending on the subscription (to allow mutating operators only from apps running in app clusters)
    • Consists of ApplicationClient, InstanceClient, InstanceEventClient, ProcessClient, SignClient, TextClient, DataClient
  • Notifications - PlatformAccessToken
  • Altinn2MetadataApiClient - none
  • NetsClient - API key from configuration
  • Events - user token + PlatformAccessToken + APIM subscription key
    • Events subscription only uses APIM subscription key + secret code (IEventsSecretCodeProvider)
  • Profile - user token + PlatformAccessToken + APIM subscription key
  • Maskinporten - Maskinporten token
  • Register - user token + PlatformAccessToken + APIM subscription key
  • Authentication - user token + APIM subscription key (used to refresh token)
  • Authorization - user token + APIM subscription key
    • Some operations use PEP and PDP directly through libraries
  • Azure
  • Key Vault - Entra client secret
  • PDF - user token (cluster local endpoint)

Conclusion

Work that needs to be done

  • Design an abstraction, something like IClientContext, that allows us to represent the authenticated state/context
    • Can represent users, orgs, systemusers and the app itself
    • How do we express outbound authn - when do we pass on the current context and when do we choose differently?
    • Formulate as ADR
    • Initial design in: Initial IAuthenticationContext abstraction #880
  • Start using internal abstraction IClientContext where possible - which encapsulates the authenticated state
    • Not always possible - i.e. PEP APIs and our own public APIs
    • JwtTokenUtil
    • IUserTokenProvider
    • .User (match case, whole word)
      • Consider deprecating ClaimsPrincipalExtensions
      • Consider deprecating UserHelper
      • ClaimsPrincipal
      • Manually iterating claims, such as TelemetryEnrichingMiddleware
    • Consider creating shim/abstraction between us and public PEP APIs such as DecisionHelper
  • Review all usage of profile client, as system users don't have profiles
  • Get updated PlatformUser (part of InstanceEvent) that considers system users
    • Update GenerateProcessChangeEvent, InstanceEventExtensions
  • Frontend updates
    • Confirmation page
    • Receipt page
    • PDF
    • Authorization/user/profile/party related requests
  • Figure out if there is a migration path to use Maskinporten tokens directly (no exchange)
@martinothamar martinothamar added the status/draft Status: When you create an issue before you have enough info to properly describe the issue. label Sep 11, 2024
@martinothamar martinothamar moved this to 📈 Todo in Team Apps Sep 11, 2024
@martinothamar martinothamar self-assigned this Sep 11, 2024
@martinothamar martinothamar moved this from 📈 Todo to 👷 In Progress in Team Apps Sep 11, 2024
@martinothamar martinothamar moved this from 👷 In Progress to 🔎 Review in Team Apps Nov 4, 2024
@martinothamar martinothamar removed the status/draft Status: When you create an issue before you have enough info to properly describe the issue. label Nov 4, 2024
@martinothamar martinothamar moved this from 🔎 Review to ✅ Done in Team Apps Nov 29, 2024
@martinothamar
Copy link
Contributor Author

Closing as the main work is done, but will probably be extended and/or moved into docs somewhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant