AzBuilder / terrakube

Open source IaC Automation and Collaboration Software.
https://docs.terrakube.io
Apache License 2.0
496 stars 38 forks source link

Auto add user to correct organization based on JWT token #1286

Open pimmerks opened 2 weeks ago

pimmerks commented 2 weeks ago

Feature description 💡

Hi, we would like to have an option available to automatically add users to the correct Organization based on the ID/JWT token that the user is authenticated with.

This feature can have different use-cases:

The general flow would be:

  1. User logs in The IDP adds a specific claim to the JWT token, for example organization
  2. Terrakube checks JWT token ({..., "organization": "org-a", ...})
  3. Terrakube checks if org-a exists
  4. Terrakube adds user to org-a

We could possible also create the organization if it does not exists yet.

This behaviour should be configurable in the settings.

# Settings example:
createOrganizationOnLogin: true/false
addUserToOrganizationOnLogin: true/false
organizationNameClaim: "organization"

I am able to help with creating a PR if you see value in this feature.

Anything else?

No response

alfespa17 commented 2 weeks ago

This sounds like an interesting idea, feel free to send a pull request with this feature and just keep in mind to leave some option to enable or disable it.

I guess you can add some logic similar to the one that we use to validate if a PAT token is deleted in this part of the code

https://github.com/AzBuilder/terrakube/blob/9b45945f3e9a2b509a91b440052831af330519ba/api/src/main/java/org/terrakube/api/plugin/security/authentication/dex/DexAuthenticationManagerResolver.java#L51

And you can parse the token similar to this.

https://github.com/AzBuilder/terrakube/blob/9b45945f3e9a2b509a91b440052831af330519ba/api/src/main/java/org/terrakube/api/plugin/security/authentication/dex/DexAuthenticationManagerResolver.java#L92

Or you can also parse it like this.

https://github.com/AzBuilder/terrakube/blob/9b45945f3e9a2b509a91b440052831af330519ba/registry/src/main/java/org/terrakube/registry/configuration/authentication/dex/RegistryAuthenticationManagerResolver.java#L57