> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siderolabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto-Assign Roles to SAML and OIDC Users

> Automatically assign Omni roles to SAML and OIDC users based on labels from the identity provider.

When SAML or OIDC authentication is enabled, Omni can automatically assign roles to users based on the attributes or claims sent by the identity provider. To configure this, use `SAMLLabelRule` resources to map the resulting labels to Omni roles. Despite its name, a `SAMLLabelRule` applies to labels from both SAML and OIDC logins. If no rules are configured, [roles must be assigned manually](https://docs.siderolabs.com/omni/security-and-authentication/manage-user-in-omni.md) by an administrator.

## Prerequisites

Before creating label rules, make sure you have the following:

* SAML or OIDC authentication must be configured on your Omni instance. See [Authentication and Authorization](https://docs.siderolabs.com/omni/security-and-authentication/authentication-and-authorization.md) for setup instructions.
* `omnictl` must be installed and configured with Admin access to your Omni instance.

## How label rules work

Omni turns information from the identity provider into labels on each user, and `SAMLLabelRule` resources assign roles based on those labels. SAML and OIDC logins produce labels in different ways.

### Labels from SAML logins

When a SAML user logs in to Omni, their SAML attributes are read and mapped to labels on the user resource. Omni recognises the following SAML attribute names by default and maps them to the `role` label key:

| SAML attribute | Provider |
| - | - |
| `http://schemas.microsoft.com/ws/2008/06/identity/claims/role` | Microsoft |
| `Role` | Google |
| `role` | Samltest |

For example, a user with the SAML attribute `Role: engineers` will be labeled `saml.omni.sidero.dev/role/engineers` in Omni automatically when using Google or a compatible provider.

If your SAML identity provider uses a different attribute name, you must configure Omni to map it to the `role` key. This can be done via the CLI flag when starting the Omni server:

```bash theme={null}
--auth-saml-label-rules='{"your-custom-attribute": "role"}'
```

**Or** via the Omni configuration file:

```yaml theme={null}
auth:
  saml:
    attributeRules:
      your-custom-attribute: role
```

For the full list of configuration options, see the [Omni Configuration reference](https://docs.siderolabs.com/omni/reference/omni-configuration.md#auth-saml).

### Labels from OIDC logins

When an OIDC user logs in to Omni, the `groups` and `roles` claims of the ID token become labels in the format `oidc.omni.sidero.dev/<claim>/<value>`. For example, an ID token with `"groups": ["engineers"]` labels the user `oidc.omni.sidero.dev/groups/engineers`. Other claims do not create labels. The labels are updated on every login, and labels whose values are no longer in the ID token are removed.

Some identity providers include the `groups` claim only when it is requested with a scope, usually named `groups`. Without it, OIDC users have no labels and no rule matches them. Add the scope with the `--auth-oidc-scopes` flag when starting Omni:

```bash theme={null}
--auth-oidc-scopes=openid,profile,email,groups
```

**Or** via the Omni configuration file:

```yaml theme={null}
auth:
  oidc:
    scopes:
      - openid
      - profile
      - email
      - groups
```

By default, Omni does not create OIDC users on their first login. An administrator creates each OIDC user, and a user who does not exist is refused. To create OIDC users on their first login, as SAML users are, set the `--auth-oidc-auto-create-users` flag:

```bash theme={null}
--auth-oidc-auto-create-users
```

**Or** via the Omni configuration file:

```yaml theme={null}
auth:
  oidc:
    autoCreateUsers: true
```

A user created this way gets the role from the matching `SAMLLabelRule` resources, or `None` if no rule matches.

> [!WARNING]
>
> Enable `autoCreateUsers` only when every account of the identity provider belongs to your organization. Otherwise, any account of the identity provider can create a user in Omni.

For the full list of OIDC options, see the [Omni Configuration reference](https://docs.siderolabs.com/omni/reference/omni-configuration.md#auth-oidc).

### Assign roles with label rules

Once the correct labels are appearing on your users, a `SAMLLabelRule` resource can automatically assign an Omni role when a matching label is found. If multiple rules match the same user, the role with the highest access level is assigned.

## Create and verify a SAML label rule

The following example creates a rule that assigns the `Operator` role to any SAML user whose SAML attributes include `Role: engineers`. To match OIDC users instead, use an OIDC label such as `oidc.omni.sidero.dev/groups/engineers` in `matchlabels`.

### Step 1: Create the rule

Create and apply the `SAMLLabelRule` resource:

```bash theme={null}
cat <<EOF | omnictl apply -f -
metadata:
  namespace: default
  type: SAMLLabelRules.omni.sidero.dev
  id: assign-operator-to-engineers-label
spec:
  assignrole: Operator
  updateoneachlogin: true
  matchlabels:
    - saml.omni.sidero.dev/role/engineers
EOF
```

The fields in the `spec` are:

| Field | Description |
| - | - |
| `assignrole` | The Omni role to assign to matching users. Valid values are `None`, `Reader`, `Operator`, and `Admin`. The `Auditor` role cannot be assigned this way, so it has to be set on the user directly. Note that a matching rule with `updateoneachlogin` set to true overwrites the user's role on every login, which would undo a manual `Auditor` assignment. |
| `updateoneachlogin` | If `true`, the role is re-evaluated and updated on every login, not just the first. If `false`, the role is only assigned when the user is created. |
| `matchlabels` | A list of labels to match against. SAML labels follow the format `saml.omni.sidero.dev/<attribute-name>/<attribute-value>`, and OIDC labels follow the format `oidc.omni.sidero.dev/<claim>/<value>`. |

### Step 2: Verify the rule was applied

Log in to Omni as a user with the matching attribute or claim, then list the users of your instance:

```bash theme={null}
omnictl user list
```

The output shows the role and labels of each user. The `ROLE` column shows the assigned role. The `LABELS` column lists the labels without their `saml.omni.sidero.dev/` or `oidc.omni.sidero.dev/` prefix, so `oidc.omni.sidero.dev/groups/engineers` appears as `groups/engineers=`.

## Limitations

The following limitations apply when automatically assigning roles to SAML and OIDC users:

* A rule with `updateoneachlogin` set to `false` only assigns a role when the user is created. If the user already exists, their role is not changed by the rule and must be updated manually by an administrator, or by a rule with `updateoneachlogin` set to `true`.
* If no rule matches when an existing user logs in, the user keeps their current role, even with `updateoneachlogin` set to `true`. For example, removing a user from a group in the identity provider does not change their role in Omni.
* If the user is the first user to log in to an Omni instance, the `SAMLLabelRule` will not apply. The first user is always assigned the `Admin` role, regardless of any label rules.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.