Let only chosen groups sign in to an app
Docs version v1 (main)Nauthera is pre-1.0, in a design-partner programUpdated
This guide gives an application to the people in one or two groups and to nobody else.
It fills two groups from an Active Directory, lists them in the application's
OIDCClient, and has the application map its roles from the
groups claim. Grafana is the example; any OpenID Connect application works the same
way. You need a Nauthera release with its operator running, the
namespace nauthera admitted to the main organization, and kubectl. At the end, a user
outside both groups is refused by Nauthera before the application sees them, and leaving
a group takes access away at the user's next refresh. The main limit: a directory
group's members are read when they sign in through the directory, so a change there
reaches Nauthera at that user's next sign-in.
| Step | Resource | What it does |
|---|---|---|
| Read the directory's groups | LDAPDirectory | Each sign-in through the directory reads the user's groups, nested ones included |
| Declare the groups | Group | Each group follows a directory group, an email domain, or members added by hand |
| Restrict the client | OIDCClient | Only members of the listed groups sign in; the groups claim names theirs |
| Map roles in the application | Grafana's configuration | Admins get Admin, everyone else let in gets Viewer |
1. Read the directory's groups
Skip this step if your groups follow email domains or are filled by hand.
The directory connection reads a user's groups only when its spec.groups says how. On
Active Directory, inChain follows nested groups in one search:
apiVersion: nauthera.io/v1alpha1
kind: LDAPDirectory
metadata:
name: corp
namespace: nauthera
spec:
url: ldaps://dc1.corp.example:636
userBaseDn: OU=Staff,DC=corp,DC=example
userFilter: (objectClass=user)
usernameAttribute: sAMAccountName
groups:
lookup: inChain
baseDn: OU=Groups,DC=corp,DC=exampleThe client must also offer the directory, in its spec.ldapDirectories (step 3). On
another LDAP server, use lookup: search or memberOf; see
Reading a user's groups for
what each reads and what it misses.
2. Declare the groups
One Group for the people who administer Grafana, and one for everyone else who may
use it. directoryGroups follows a group in the directory by its DN, spelled as the
directory spells it; emailDomains admits every verified address at a domain:
apiVersion: nauthera.io/v1alpha1
kind: Group
metadata:
name: grafana-admins
namespace: nauthera
spec:
displayName: Grafana Admins
directoryGroups:
- directory: corp
dn: CN=Grafana Admins,OU=Groups,DC=corp,DC=example
---
apiVersion: nauthera.io/v1alpha1
kind: Group
metadata:
name: grafana-users
namespace: nauthera
spec:
displayName: Grafana Users
directoryGroups:
- directory: corp
dn: CN=Engineering,OU=Groups,DC=corp,DC=example
emailDomains: [corp.example]Both must be Ready before a client can name them:
kubectl -n nauthera get groupsA group fills as its people sign in: a user joins when a session is established for them and a mapper matches. An owner can also add someone by hand on the group's page in the admin dashboard, which no mapper undoes. See Mappers for how members come and go.
3. Restrict the client
The application's OIDCClient lists the Groups by resource name in allowedGroups, and
asks for the groups scope so the application can tell the two apart:
apiVersion: nauthera.io/v1alpha1
kind: OIDCClient
metadata:
name: grafana
namespace: nauthera
spec:
clientId: grafana
redirectUris: [https://grafana.example.com/login/generic_oauth]
grantTypes: [authorization_code, refresh_token]
allowRefresh: true
scopes: [openid, profile, email, groups]
allowedGroups: [grafana-admins, grafana-users]
ldapDirectories:
- slug: corp
allowSignIn: true
allowSignUp: true
secret:
generate: trueThe Groups must be in the client's namespace. The operator waits for each to be declared
on the server, reporting GroupNotFound until it is, and never registers the client with
a shorter list than the manifest says. The operator writes the client's credentials into
the Secret grafana, under client-id, client-secret and issuer.
kubectl -n nauthera get oidcclient grafana4. Map roles in the application
Nauthera has already refused everyone outside both groups, so the application only decides who gets which role. In Grafana:
[auth.generic_oauth]
enabled = true
name = Nauthera
client_id = grafana
client_secret = $__file{/etc/secrets/grafana/client-secret}
scopes = openid profile email groups
auth_url = https://auth.example.com/authorize
token_url = https://auth.example.com/token
api_url = https://auth.example.com/userinfo
use_pkce = true
login_attribute_path = preferred_username
groups_attribute_path = groups
role_attribute_path = contains(groups[*], 'Grafana Admins') && 'Admin' || 'Viewer'Mount the Secret grafana at /etc/secrets/grafana. The claim carries display names,
so the expression names Grafana Admins, not the resource name grafana-admins.
Check it
- A member signs in and lands in Grafana with the role the expression gives.
- Someone outside both groups signs in to Nauthera and is sent back to Grafana with
access_denied. The audit log records it asoauth.with the causeauthorization. requested group_not_allowed, and theaccess_deniedrunbook walks through it. - The client's page in the admin dashboard lists the two groups under who may sign in.
Taking access away
- Leaving the directory group withdraws the user from the
Groupat their next sign-in through the directory, and their next refresh is refused withinvalid_grant. Membership is as of that sign-in: someone disabled in the directory, who never signs in again, stays a member, and a refresh token they already hold keeps working. End their sessions from their page in the admin dashboard, which retires those refresh tokens, or remove them from the group by hand. - Removing someone by hand on the group's page takes effect at their next refresh, and lasts until their next sign-in if a mapper still matches them; change the directory group or the mapper to keep them out.
- An access token already issued stays valid until it expires, since revocation does
not reach access tokens (
issuer.access_token_ttl, ten minutes by default). Keep it short for applications that need access to end promptly.
Related
- Group: mappers, members by hand, and the
groupsclaim - OIDCClient:
allowedGroupsandGroupNotFound - LDAPDirectory: how a sign-in reads groups
- Operator: who may write
GroupandOIDCClient