feat: assign users to teams via OIDC claims #1393

Merged
konrad merged 93 commits from viehlieb/api:950_reworked_assign_teams_via_oidc into main 2024-03-02 08:47:12 +00:00
Showing only changes of commit 9011668512 - Show all commits

View File

@ -1,23 +1,20 @@
# Assign teams via oidc
Adds the functionality to assign users to teams via oidc.
Read carefully and brief your administrators to use this feature.
You need to configure your oidc provider as explained in the documentation below to make this feature work.
Tested with oidc provider authentik.
To distinguish between teams created in vikunja and teams generated via oidc, a string attribute for vikunja teams is introduced, which is called: *oidcID*
You should conigure your provider to send an oidcID to vikunja.
Vikunja is capable of automatically adding users to a team based on a group defined in the oidc provider. If used, Vikunja will sync teams, automatically create new ones and make sure the members are part of the configured teams. Teams which only exist because they are generated from oidc attributes are not configurable in Vikunja.
## Setup
See below for setup instructions.
Edit [config.yml](https://kolaente.dev/vikunja/api/src/branch/main/config.yml.sample) to include scope: openid profile email vikunja_scope
To distinguish between teams created in Vikunja and teams generated automatically via oidc, generated teams have an `oidcID` assigned internally.
For authentik to use group assignment feature:
- go to: .../if/admin/#/core/property-mappings
## Setup for atuhentik
viehlieb marked this conversation as resolved Outdated

Typo: Should be Authentik.

Typo: Should be `Authentik`.
- create a new mapping called "vikunja_scope"
To configure automatic team management through authentik, we assume you have already set up Authentik as an oidc provider for authentication with Vikunja.
There is a field to enter python expressions that will be delivered with the oidc token.
To use Authentik's group assignment feature, follow these steps:
- write a small script, for adding group information to vikunja_scope.
1. Edit [config.yml](https://kolaente.dev/vikunja/api/src/branch/main/config.yml.sample) to include scope: `openid profile email vikunja_scope`
2. Open `<your authentik url>/if/admin/#/core/property-mappings`
3. Create a new mapping called `vikunja_scope`. There is a field to enter python expressions that will be delivered with the oidc token.
4. Write a small script like this to add group information to `vikunja_scope`:
```python
@ -25,8 +22,9 @@ groupsDict = {"vikunja_groups": []}
for group in request.user.ak_groups.all():
groupsDict["vikunja_groups"].append({"name": group.name, "oidcID": group.num_pk})
return groupsDict
```
"""
```
output example:
viehlieb marked this conversation as resolved Outdated

Can you move the title to the outside of the example json?

Can you move the title to the outside of the example json?
{
"vikunja_groups": [
konrad marked this conversation as resolved Outdated

Please add to this guide how to add the scope to the Auth provider so that it actually shows up in Vikunja.

Please add to this guide how to add the scope to the Auth provider so that it actually shows up in Vikunja.

Now done.

Now done.
@ -40,21 +38,27 @@ output example:
}
]
}
"""
```
Now when you log into Vikunja via oidc there will be a list of scopes you are claiming from your oidc provider.
You should see the description you entered in the oidc provider's admin area.
Now when you log in via oidc there will be a list of scopes you are claiming from your oidc provider.
You should see "the description you entered in the oidc provider's admin area"
Log in and go to teams.
viehlieb marked this conversation as resolved Outdated

Please change this so that it's clear that we're talking about Vikunja here.

Please change this so that it's clear that we're talking about Vikunja here.
You should see "(sso: XXXXX)" written next to each team you were asigned through oidc.
viehlieb marked this conversation as resolved Outdated

What's the XXXX part?

What's the `XXXX` part?
- Log in and go to teams.
- You will see "(sso: XXXXX)" written next to each team you were asigned through oidc.
## IMPORTANT NOTES:
* **SSO/OIDC teams cannot be edited.**
viehlieb marked this conversation as resolved Outdated

Please don't make every paragraph here bold.

Please don't make every paragraph here bold.
* **It is required to deliver the key "vikunja_groups" via your custom_scope since this is the key vikunja is looking for to start the procedure.**
* **Additionally, make sure to deliver an "oidcID" and a "name" attribute in the oidc token.**
____________________________________________________________________________
---
viehlieb marked this conversation as resolved Outdated

This is unnecessary, please remove it

This is unnecessary, please remove it
## BEHAVIOR
viehlieb marked this conversation as resolved Outdated

What kind of behaviour? Please rename it to something more specific.

And please don't capitalize the heading, same for the other headings.

What kind of behaviour? Please rename it to something more specific. And please don't capitalize the heading, same for the other headings.
*(.. examples for "team1" ..)*
*All examples assume one team called "team 1"*
1. *Token delivers team.name +team.oidcId and Vikunja team does not exist:* \
New team will be created called "team 1" with attribute oidcId: "33929"
viehlieb marked this conversation as resolved Outdated

Is the attribute called oidcId or oidcID? The Authentik example was using oidcId.

Is the attribute called `oidcId` or `oidcID`? The Authentik example was using `oidcId`.

in authentik it is called oidcID

in migration:

type teams20230104152903 struct {
	OidcID string `xorm:"varchar(250) null" maxLength:"250" json:"oidc_id"`
}

Therefore in the db it is called oidc_id

I agree, there is an inconsistency in the .md file.

I try to fit the naming to the context.
Do you have suggested changes in renaming?

in authentik it is called `oidcID` in migration: ``` type teams20230104152903 struct { OidcID string `xorm:"varchar(250) null" maxLength:"250" json:"oidc_id"` } ``` Therefore in the db it is called oidc_id I agree, there is an inconsistency in the .md file. I try to fit the naming to the context. Do you have suggested changes in renaming?

I think the name is fine, but please use the same one everywhere.

I think the name is fine, but please use the same one everywhere.