|
| 1 | +--- |
| 2 | +title: Use SAML groups information in Kubernetes |
| 3 | +--- |
| 4 | + |
| 5 | + |
| 6 | +The procedure below describes how you can reuse SAML group information in Kubernetes for authorization. |
| 7 | + |
| 8 | +Omni can extract SAML group information. For each group it will create a label on the identity in Omni. |
| 9 | + |
| 10 | +Suppose you have your groups information in the SAML attribute "membership". |
| 11 | +Start the Omni container with the following flags. |
| 12 | + |
| 13 | + |
| 14 | +| Flag | Description | |
| 15 | +| ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | |
| 16 | +| `--auth-saml-enabled` | Enable SAML authentication. | |
| 17 | +| `--auth-saml-url` | The URL to the IdP metadata file. | |
| 18 | +| `--auth-saml-label-rules='{"membership": "groups"}'` | This extracts the `membership` attribute from the SAML assertion into the label `saml.omni.sidero.dev/groups/groups` | |
| 19 | + |
| 20 | +For example: |
| 21 | + |
| 22 | +```bash |
| 23 | +--auth-saml-enabled=true |
| 24 | +--auth-saml-url=https://{your-saml-idp}/metadata/idp.xml |
| 25 | +--auth-saml-label-rules='{"membership": "groups"}' |
| 26 | +``` |
| 27 | + |
| 28 | +``` |
| 29 | +--auth-saml-label-rules='{"membership" : "groups" }' |
| 30 | +``` |
| 31 | + |
| 32 | +This will extract value from the SAML attribute `memberhip` into the Omni user's identity resource label with the |
| 33 | +prefix `saml.omni.sidero.dev/groups` |
| 34 | +Restart Omni, and log in using SAML. If you navigate to <b>Settings > Users</b>, you will now see your groups in a label. |
| 35 | +If your SAML attribute memberships contains the values `group1` and `group2` you will see the following two labels (the interface omits the prefix `saml.omni.sidero.dev`) |
| 36 | + |
| 37 | +```yaml |
| 38 | +groups/group1 |
| 39 | +groups/group2 |
| 40 | +``` |
| 41 | + |
| 42 | +You can now create an ACL that will create an impersonation in Kubernetes using this group information: |
| 43 | + |
| 44 | +```yaml |
| 45 | + |
| 46 | +metadata: |
| 47 | + namespace: default |
| 48 | + type: AccessPolicies.omni.sidero.dev |
| 49 | + id: access-policy |
| 50 | +spec: |
| 51 | + usergroups: |
| 52 | + group1: |
| 53 | + users: |
| 54 | + - labelselectors: |
| 55 | + - "saml.omni.sidero.dev/groups/group1=" --< Do not forget the `=` sign postfix |
| 56 | + clustergroups: |
| 57 | + staging: |
| 58 | + clusters: |
| 59 | + - match: staging-* |
| 60 | + production: |
| 61 | + clusters: |
| 62 | + - match: prod-* |
| 63 | + rules: |
| 64 | + - users: |
| 65 | + - groups/group1 |
| 66 | + clusters: |
| 67 | + - group/staging |
| 68 | + - group/production |
| 69 | + kubernetes: |
| 70 | + impersonate: |
| 71 | + groups: |
| 72 | + - group1 |
| 73 | +``` |
| 74 | +
|
| 75 | +The impersonate rule will make sure that you will have the right group assigned in kubernetes. |
| 76 | +You can then use that information in a RoleBinding: |
| 77 | +
|
| 78 | +```yaml |
| 79 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 80 | +kind: RoleBinding |
| 81 | +metadata: |
| 82 | + name: group1-access |
| 83 | + namespace: group1 |
| 84 | +roleRef: |
| 85 | + apiGroup: rbac.authorization.k8s.io |
| 86 | + kind: ClusterRole |
| 87 | + name: admin <--- or any other ClusterRole of course. |
| 88 | +subjects: |
| 89 | +- apiGroup: rbac.authorization.k8s.io |
| 90 | + kind: Group |
| 91 | + name: group1 |
| 92 | +``` |
| 93 | +
|
0 commit comments