Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 305 additions & 0 deletions docs/enterprise/deployments-administration/okta-role-mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
---
keywords: [GreptimeDB Enterprise, Okta, SSO, OIDC, RBAC, role mapping]
description: Map Okta groups to GreptimeDB Enterprise roles and verify access from the Dashboard.
---

# Map Okta Groups to GreptimeDB Roles

Use role-based access control (RBAC) to grant GreptimeDB Enterprise permissions
based on Okta group membership. With the Okta Org Authorization Server,
GreptimeDB verifies the access token using remote OpenID Connect (OIDC)
introspection, reads `groups` from UserInfo, and resolves the matching database
roles. The roles supply the privileges and access control lists (ACLs).
GreptimeDB identifies the single sign-on (SSO) user by the issuer and `sub`
and derives that user's permissions during authentication. The SSO identity
stays out of the user store, and existing password accounts keep working.

:::note Version compatibility
This guide applies to Nightly. Use a GreptimeDB Enterprise build that supports
`jwt_auth.group_role_mapping_file` and an SSO-capable Enterprise Dashboard.
If you use dashboard-apiserver, use a version that forwards Bearer credentials.
:::

## 1. Configure the Okta Application

Follow [Configure Okta](./sso.md#configure-okta) to set up an OIDC
**Single-Page Application** with Authorization Code + PKCE and
**Client authentication** set to **None**. Use your Okta org URL as the issuer,
for example `https://your-org.okta.com`; `/oauth2/default` is a custom
Comment thread
fengjiachun marked this conversation as resolved.
Resolved
authorization server outside this guide's scope. Register the exact Dashboard
sign-in redirect URI, such as
`https://dashboard.example.com/dashboard/auth/callback`, and note the app's
client ID.

Okta's Org Authorization Server issues access tokens for Okta's own resources,
and its token audience cannot be customized. In remote OIDC mode, GreptimeDB
binds a token to `jwt_auth.issuer` and `jwt_auth.client_id` through
introspection and accepts it without checking an audience. Every active Bearer
access token that Okta issues to this client with the `openid` scope passes
that check. Deployments that require tokens minted for a dedicated API
audience need Okta's [custom authorization servers](https://developer.okta.com/docs/concepts/auth-servers/#custom-authorization-server),
which is outside this guide's scope.

For this example, use two Okta groups, `greptimedb-alpha-readers` and
`greptimedb-beta-readers`, with a different test user in each. Assign both groups
to the application in **Assignments**. Verify the app assignments and group
memberships separately. If you use existing groups, substitute their names in
the following steps.

## 2. Return Groups from Okta UserInfo

Open the app's **Sign On** settings and edit **Group Claims** under
**OpenID Connect ID Token**. If the fields are hidden, expand
**Show legacy configuration**. Set the claim name to `groups`.

Choose the claim type by the source of the groups themselves. Check which of
those groups each user belongs to in **Directory → People**, then check each
group's source in **Directory → Groups**. A directory-synced user who belongs
to an Okta-native group uses the same name filter as an Okta-native user.

- **Okta-native groups only:** Select **Filter → Matches regex**. Match only
the groups used by this deployment:

```text
^greptimedb-(alpha|beta)-readers$
```

- **Imported or mixed-source groups:** Select **Expression**. Replace the
placeholders with the Okta group IDs of the groups you want to allow:

```text
getFilteredGroups({"<OKTA_GROUP_ID_1>", "<OKTA_GROUP_ID_2>"}, "group.name", 40)
```

The expression returns the names of the listed groups that the user belongs
to. `40` is the per-user result limit. GreptimeDB matches the returned group
names, so give the allowed groups distinct names.
See [Okta's static group allowlist guide](https://developer.okta.com/docs/guides/customize-tokens-static/main/).

- **Groups from one directory with a dedicated prefix:** If matching by name
is appropriate, use `Groups.startsWith("<DIRECTORY_INSTANCE_ID>", "greptimedb-", 40)`
as the expression. Use the directory integration's instance ID. Groups with
that prefix can enter the claim as membership changes. Use the ID allowlist
above if the set of eligible groups must stay fixed. See
[Okta's dynamic group allowlist guide](https://developer.okta.com/docs/guides/customize-tokens-dynamic/main/).

Save the app settings. See [Okta's groups claim guide](https://developer.okta.com/docs/guides/customize-tokens-groups-claim/main/#add-a-groups-claim-for-the-org-authorization-server)
for the Org Authorization Server. After deploying the `scopes` configuration
in step 5, sign in with a fresh session. Send the access token as a Bearer
credential to the discovered UserInfo endpoint (typically `GET /oauth2/v1/userinfo`).
Verify that the response contains the expected `groups` string array.
GreptimeDB maps only the `groups` value from this UserInfo response.

## 3. Create the GreptimeDB Roles

Use an existing GreptimeDB administrator to create the roles in the catalog
where the mapped users will connect. For this example, use the `greptime`
catalog with two existing tables in the `public` database:

| Okta group | Role name | Access |
| --- | --- | --- |
| `greptimedb-alpha-readers` | `alpha_reader` | `SELECT` on `public.alpha_metrics` |
| `greptimedb-beta-readers` | `beta_reader` | `SELECT` on `public.beta_metrics` |

Send `POST /v1/roles` with an operation list and a table ACL. Replace the server
URL and admin username in this example. `curl` prompts for the admin password.

```shell
curl --include --user '<admin-user>' \
'https://greptimedb.example.com/v1/roles?db=greptime-public' \
--header 'Content-Type: application/json' \
--data '{
"name": "alpha_reader",
"allowed_ops": ["sql.select"],
"acl_map": {
"public": [{"type": "match", "table": "alpha_metrics"}]
}
}'
```

Repeat with `beta_reader` and `beta_metrics`. Each successful request returns
`201 Created` and the role definition. Check the returned `catalog`,
`allowed_ops`, and `acl_map`, and record the role `id` for verification. The
mapping file uses role **names**; the current-user endpoint reports role **IDs**.

An Enterprise Dashboard with role management lists the created roles and the
built-in `__ops_*` system roles on the **Role Management** page. The Dashboard's
role editor changes a role's allowed operations and keeps its existing table
ACLs, so create the ACLs through the role API as shown above.

![Enterprise Dashboard Role Management page with two custom SELECT-only roles and built-in system roles](/ent_user/role-management.png)

## 4. Write the Group-to-Role Mapping

Save this file as `group-roles.json`:

```json
{
"catalog": "greptime",
"mapping_field": "groups",
"roles": {
"greptimedb-alpha-readers": "alpha_reader",
"greptimedb-beta-readers": "beta_reader"
}
}
```

- `catalog` is the catalog where GreptimeDB looks up roles. It defaults to
`greptime`. Non-admin users must connect to this catalog and a database
allowed by the mapped roles.
- `mapping_field` is the exact top-level UserInfo field name. The field's value
can be a string or an array of strings.
- `roles` is a non-empty object. Each key matches an Okta claim value exactly,
including case. Each value names a role in the configured catalog. When
several groups match, GreptimeDB deduplicates the roles (up to 64) and merges
their operation grants and ACLs separately. An operation granted by one role
can apply to a table added by another. Review the combined grants for users
with multiple roles.
- An optional `"*"` entry supplies a fallback role only when no explicit group
matches. It also applies if the claim is missing, `null`, or an empty array.
A claim with an invalid type is rejected. This example omits the fallback,
so a user with no matching group is denied.

Use scoped custom roles for ordinary access. The target `admin` selects the
built-in administrator role and grants full privileges; `role:admin` refers
to a custom role literally named `admin`.

The mapping must be a readable regular file of at most 64 KiB. Use strict JSON:
the parser rejects unknown fields and duplicate group keys. Limit who can change
the file, because it controls which roles an Okta user receives.

## 5. Configure GreptimeDB and the Dashboard

Merge the following into the standalone or Frontend TOML configuration. Place
`user_provider` at the top level before any table. If the enterprise user
provider is already configured, keep its existing setting. Add the `jwt_auth`
options to a single plugin entry and replace the issuer and client ID:

```toml
user_provider = "greptime_ee_user_provider:"

[[plugins]]
[plugins.jwt_auth]
issuer = "https://your-org.okta.com"
client_id = "your-oidc-app-client-id"
introspection_client_id_location = "query"
scopes = ["openid", "profile", "email", "groups"]
display_name = "Okta"
group_role_mapping_file = "/etc/greptimedb/sso/group-roles.json"
```

`introspection_client_id_location = "query"` sends `client_id` in the URL query
for Okta's public-client introspection. Omit `secret`, `public_key`, `jwks_url`,
`audience`, `algorithm`, and other JWKS settings for remote OIDC. Leave
`auto_provision` and its privilege and database lists unset: group mapping and
automatic user provisioning exclude each other, and the Frontend fails to start
when a configuration combines them.

The Dashboard uses `scopes` in the OIDC authorization request. Include `openid`
and `groups`, and keep `profile` for the default UserInfo display name,
`preferred_username`. Okta must grant the `groups` scope and return the claim
according to the app's Group Claims settings.

Serve the Dashboard over HTTPS. Allow the browser to reach Okta's discovery
document (`<issuer>/.well-known/openid-configuration`), authorization endpoint,
and token endpoint. Allow GreptimeDB to reach discovery, introspection, and
UserInfo over trusted HTTPS. If you use dashboard-apiserver, point the instance
at the configured Frontend and set `enableUserAuthentication: true` in the
dashboard-apiserver configuration.

### Mount the Mapping on Kubernetes

Create a ConfigMap in the cluster's namespace. Set `NAMESPACE` to that namespace
before running this command from the directory containing `group-roles.json`:

```shell
kubectl -n "$NAMESPACE" create configmap okta-role-mapping \
--from-file=group-roles.json=./group-roles.json
```

For the [Enterprise Helm deployment](./deploy-on-kubernetes/installation.md),
merge the TOML into `frontend.configData`. If the deployment sets
`frontend.configFile`, put the TOML in that file; the chart then builds the
Frontend configuration from `configFile` alone. If `auth.enabled` is set,
verify that `auth.useBuiltIn: true` selects the Enterprise user provider.
Add the mount to the existing Helm values, preserving other volumes and mounts:

```yaml
frontend:
podTemplate:
volumes:
- name: sso-group-roles
configMap:
name: okta-role-mapping
main:
volumeMounts:
- name: sso-group-roles
mountPath: /etc/greptimedb/sso
readOnly: true
```

If you manage `GreptimeDBCluster` directly, use `spec.frontend.config` for the
TOML and `spec.frontend.template` for the volumes and mounts. For deployments
with [named Frontend groups](/user-guide/deployments-administration/deploy-on-kubernetes/configure-frontend-groups.md),
configure `config` and `template` on each serving group.

Mount the directory as shown so its files follow ConfigMap updates. A `subPath`
mount of the single file keeps the content from container start until the pod
restarts. For a deployment outside Kubernetes, place the JSON at the configured
path and give the GreptimeDB process read access.

### Roll Out and Update the Mapping

Apply the Helm or `GreptimeDBCluster` changes and wait for all serving
Comment thread
fengjiachun marked this conversation as resolved.
Resolved
Frontends to be ready. Outside Kubernetes, restart the configured processes.

GreptimeDB checks the mapping file during startup, fails to start when the file
is unreadable or invalid, and reads the file again on each SSO authentication.
To change the rules, update the ConfigMap or atomically replace the file at the
same path. A new Bearer-authenticated HTTP request or SQL connection uses the
updated rules once the change reaches its server. ConfigMap projection takes
time, so check the file on every replica. If the ConfigMap is immutable, create
a new one and roll out the updated volume reference. Existing SQL connections
keep their session permissions; close those connections if you need immediate
revocation. Changing the TOML or mapping path requires a restart.

## 6. Verify and Troubleshoot

1. Check `GET /v1/auth/config` directly or through the
[Dashboard proxy](./sso.md#how-it-works). Confirm `auth_required: true`
and that the `oidc` method advertises your issuer, client ID, and `groups`
scope.
2. Use a fresh browser session for each test user. Sign in with Okta and check
`GET /v1/users/current?db=greptime-public`. The response should have
`auth_source: "sso"` and the expected `role_ids` from step 3.
3. In the `public` database, run `SELECT * FROM public.alpha_metrics LIMIT 1`
and `SELECT * FROM public.beta_metrics LIMIT 1` separately. For a user in
just one group, the corresponding query should succeed and the other should
be denied (`403` over HTTP).
4. Try an app-assigned user with no matching group. With no `"*"` rule, that
user's Bearer requests should be rejected (`401` over HTTP).
5. To test a mapping update, change one rule in a test environment. Once the
new file has reached the Frontends, repeat the HTTP checks with the same
unexpired token. Verify the new role IDs and SQL results, then restore the
original mapping.

At startup, the Frontend log `Bearer authentication configured` should show
`verification="oidc_introspection"` and `identity_resolution="group_role_mapping"`.
For troubleshooting, temporarily set `[logging]` `level` to
`"info,user_server=debug"` on the affected server. If Helm manages logging, add
`user_server=debug` to `frontend.logging.filters`. Use the following
stages to find the failing check:

| Symptom or log stage | What to check |
| --- | --- |
| Only password login appears | Check dashboard-apiserver's `enableUserAuthentication` setting, the instance's Frontend address, and the raw `/v1/auth/config` response. |
| `introspection` or `userinfo` | Check issuer, client ID, `query` placement, HTTPS connectivity, and that the access token is valid. UserInfo must include `sub` and the configured display-name claim. |
| `group_mapping_file` | Check the actual file path and mount on the serving Frontend, file permissions, size, and JSON syntax. |
| `group_selection` | Check the app assignment, actual group membership, granted scope, UserInfo claim type, and exact group names. Sign in again after changing group claim settings. |
| `role_lookup` | Confirm the mapped role names exist in the specified catalog. |
| `/v1/users/current` succeeds but a query is denied | Check the role's operation grants and database/table ACLs for that query. |
| Different replicas return different permissions | Check that all Frontends have the same configuration and have received the updated file. |

Restore the normal log level after troubleshooting. Remove access tokens, ID
tokens, passwords, and OAuth callback URLs before sharing logs or filing a
support request.
1 change: 1 addition & 0 deletions docs/enterprise/deployments-administration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The following sections describe the enterprise-specific features and capabilitie
- [Standalone Leader-Follower Mode](./standalone-follower.md): Run standalone nodes with leader election, automatic promotion, and optional follower reads.
- [LDAP Authentication](authentication.md): Enhanced authentication capabilities for GreptimeDB Enterprise.
- [SSO Authentication](./sso.md): Configure Okta login, database users, and access permissions.
- [Map Okta Groups to GreptimeDB Roles](./okta-role-mapping.md): Grant database permissions based on Okta group membership.

## Monitoring

Expand Down
14 changes: 9 additions & 5 deletions docs/enterprise/deployments-administration/sso.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ description: Set up Okta SSO for GreptimeDB Enterprise, provision database users
Use OpenID Connect (OIDC) single sign-on (SSO) with Okta to access the
GreptimeDB Enterprise Dashboard. The Dashboard completes the Authorization
Code + PKCE flow and sends the resulting access token to GreptimeDB.
GreptimeDB verifies the token with Okta, maps it to a database user, and
applies that user's privileges and ACLs. Password login remains available
alongside SSO.
This guide covers account-based SSO: GreptimeDB verifies the token with Okta
Comment thread
fengjiachun marked this conversation as resolved.
Resolved
and applies the privileges and ACLs of the corresponding database user.
For permissions derived from Okta group membership, see
[Map Okta Groups to GreptimeDB Roles](./okta-role-mapping.md).
Password login remains available alongside SSO.

:::note Version compatibility
These instructions apply to Nightly. Use GreptimeDB Enterprise and Dashboard
Expand Down Expand Up @@ -91,6 +93,7 @@ user_provider = "greptime_ee_user_provider:"
[[plugins]]
jwt_auth.issuer = "https://your-org.okta.com"
jwt_auth.client_id = "your-oidc-app-client-id"
jwt_auth.introspection_client_id_location = "query"
```

- Place the top-level `user_provider` before any TOML tables, such as `[http]`
Expand Down Expand Up @@ -122,6 +125,7 @@ Add optional settings to the same `[[plugins]]` entry:
| `jwt_auth.username_claim` | `"preferred_username"` | Top-level UserInfo field used as the database username. There is no fallback to `email` or `sub` if the selected field is missing or empty. |
| `jwt_auth.scopes` | `["openid", "profile", "email"]` | Requested login scopes; must include `openid`. |
| `jwt_auth.display_name` | `"SSO"` | Name displayed on the login button, for example `"Okta"`. |
| `jwt_auth.introspection_client_id_location` | `"form"` | Where the introspection request carries the public client's `client_id`: the request body (`"form"`) or the URL query string (`"query"`). Okta's org authorization server requires `"query"` for public clients. See [Okta introspection requirements](https://developer.okta.com/docs/api/openapi/okta-oauth/oauth/orgas/introspect). |
| `jwt_auth.auto_provision` | `false` | Create missing users on first SSO login. |
| `jwt_auth.auto_provision_privileges` | `[]` | Initial privileges for new users; required when provisioning is enabled and must not include `Admin`. |
| `jwt_auth.auto_provision_databases` | `[]` | Databases new users can access; required when provisioning is enabled. |
Expand All @@ -138,8 +142,8 @@ but users do not enter that password for SSO.

Keep application usernames unique after normalization and do not reassign a
former user's name. When changing an Okta username, update the database account
accordingly and review its permissions. Manage privileges and ACLs in GreptimeDB;
Okta groups do not automatically grant database roles.
accordingly and review its permissions. With account-based SSO, manage the
user's privileges and ACLs in GreptimeDB.

The built-in lowercase `admin` account cannot sign in using SSO or tokens.
For SSO administration, use another username and explicitly grant `Admin`.
Expand Down
Loading
Loading