Skip to content

Commit dffbeab

Browse files
committed
Environment variable documentation and general improvements
1 parent b845e50 commit dffbeab

File tree

3 files changed

+98
-61
lines changed

3 files changed

+98
-61
lines changed

docker-compose.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ x-config: &config
6262
# (Optional) Replace '5432' with the port on which postgres is running
6363
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
6464

65-
# (Optional) Can be used to configure single-sign on (sso) instead of an sso.yml
66-
# file.
67-
# See https://docs.mathesar.org/administration/single-sign-on/ for details on
68-
# how to configure this variable.
65+
# (Optional) Can be used to configure single-sign on (sso) instead of an
66+
# sso.yml configuration file.
67+
# See https://docs.mathesar.org/administration/single-sign-on/ for additional
68+
# details on how to configure this variable.
6969
OIDC_CONFIG_DICT: ${OIDC_CONFIG_DICT:-}
7070

7171
#-------------------------------------------------------------------------------
@@ -119,6 +119,12 @@ x-config: &config
119119
# client applications.
120120
# Example: 5555
121121
#
122+
# OIDC_CONFIG_DICT:
123+
# Default: N/A
124+
# Info: Specifies the settings necessary to configure Single Sign-on (SS0)
125+
# identity providers for Mathesar login. This is an optional, alternative
126+
# approach to configuring SSO via a configuration file.
127+
#
122128
#-------------------------------------------------------------------------------
123129
# INFO ABOUT VOLUMES
124130
#

docs/docs/administration/environment-variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Note: The default values specified here refer to those in Mathesar's [docker-com
8787
## Single Sign-on (SSO) {: #sso}
8888
8989
!!!note
90-
This is an optional variable used as an alternative method for [configuring Single Sign-on (SSO) in Mathesar](./single-sign-on.md), instead of the default `sso.yml` file.
90+
This is an optional variable used as an alternative method for [configuring Single Sign-on (SSO) in Mathesar](./single-sign-on.md), instead of the default `sso.yml` configuration file.
9191
9292
### `OIDC_CONFIG_DICT` (optional)
9393

docs/docs/administration/single-sign-on.md

Lines changed: 87 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
# Single Sign-on (SSO)
22

3-
This guide walks you through how to configure Single Sign-On (SSO) for Mathesar.
3+
Single sign-on (SSO) allows users to log into your Mathesar instance without the need to create or manage separate accounts.
44

5-
SSO allows users to log into your Mathesar instance without the need to create or manage separate accounts.
5+
This guide explains how to configure SSO for Mathesar. It is intended for IT and system administrators familiar with setting up identity providers and managing a Mathesar instance.
66

7+
## 1. Setting up your identity provider
78

8-
This guide is intended for IT admins or developers who are configuring secure access to Mathesar.
9+
First, you'll need to configure your identity provider (IdP) to work with Mathesar. Mathesar supports any identity provider that implements the [OpenID Connect (OIDC) standard](https://openid.net/developers/how-connect-works/), such as Okta, Azure Active Directory, Google Workspace, and others.
910

10-
### 1. Setting up your identity provider
11+
Below is a list of commonly used identity providers compatible with Mathesar’s OIDC-based SSO. Where possible, we’ve included links to their setup documentation:
1112

12-
First, configure your identity provider (IdP) to work with Mathesar.
13-
14-
???+ tip "How providers work in Mathesar"
15-
Mathesar supports any identity provider that implements the [OpenID Connect (OIDC) standard](https://openid.net/developers/how-connect-works/), such as Okta, Azure Active Directory, Google Workspace, and others.
16-
17-
Although all supported IdPs follow the same specification, they each have a different user interfaces and process for setting up an application.
18-
19-
Here are several popular identity providers that should work with Mathesar's OIDC SSO implementation. Where possible, we've linked to relevant documentation about configuring each provider.
20-
21-
| Provider | Key |
13+
| Provider | Key |
2214
|---------------|---------------|
2315
| [Apple](https://support.apple.com/guide/apple-business-manager/federated-authentication-identity-provider-axmfcab66783/web) | `apple` |
2416
| [Auth0](https://auth0.com/docs/get-started/auth0-overview/create-applications) | `auth0` |
@@ -30,9 +22,9 @@ Here are several popular identity providers that should work with Mathesar's OID
3022
| [Microsoft](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc) | `microsoft` |
3123
| [Okta](https://developer.okta.com/docs/guides/sign-into-web-app-redirect/asp-net-core-3/main/#create-an-app-integration-in-the-admin-console) | `okta` |
3224

33-
Whichever provider you're using, you'll begin by creating an application.
25+
To get started, create an application within your chosen provider.
3426

35-
During creation, you'll need to provide the "Callback URL"also referred to as the Redirect URI or Login URL, depending on the provider. The callback URL tells your identity provider where to send users after they’ve successfully logged in, so they can be redirected back to Mathesar.
27+
During this process, you'll be asked to specify a "Callback URL" (also called a Redirect URI or Login URL, depending on the provider). This is the URL your identity provider uses to return users to Mathesar after a successful login.
3628

3729
!!!info "Configuring the callback URL"
3830
In your provider's settings, set the Callback URL to:
@@ -44,33 +36,35 @@ During creation, you'll need to provide the "Callback URL"—also referred to as
4436
Replace `<mathesar-domain>` with the domain name of your Mathesar installation.<br>
4537
Examples: `mathesar.myorg.com`, `localhost:8000`
4638

47-
Replace `<provider-name>` with the name of your IdP provider.<br>
39+
Replace `<provider-name>` with the key of your IdP provider.<br>
4840
Examples: `auth0`, `okta`, `google`
4941

50-
Your identity provider will redirect users to this URL after authentication, so it's essential that it matches exactly between your IdP configuration and your Mathesar setup.
42+
Your identity provider will redirect users to this URL after authentication, so it’s important that the value matches exactly in both your IdP configuration and your Mathesar setup.
43+
44+
Once your IdP is configured, you can move on to the next steps: enabling SSO in Mathesar and configuring it with the required values from your provider.
5145

52-
Once your IdP is fully configured, you're ready to move on to the next step: populating your `sso.yml` file with the necessary values from your identity provider.
46+
## 2. Enabling SSO in Mathesar
5347

54-
### 2. Enabling SSO in Mathesar
48+
To enable SSO in Mathesar, you'll configure it outside the app's user interface using a simple configuration file named `sso.yml`.
5549

56-
SSO in Mathesar is configured outside of the application interface, using a straightforward configuration file. To enable SSO in Mathesar, start by creating a configuration file called `sso.yml`.
50+
This file contains all the necessary settings for your identity provider (IdP) and tells Mathesar how to handle authentication.
5751

58-
!!!info "Using the OIDC_CONFIG_DICT environment variable instead of sso.yml"
59-
If you're unable to write to the local filesystem, like when using a cloud provider with an ephemeral filesystem or for other purposes, you can also configure SSO in Mathesar by creating a `OIDC_CONFIG_DICT` environment variable which is a stringified JSON object.
52+
???+info "Using the OIDC_CONFIG_DICT environment variable instead of sso.yml"
53+
If Mathesar deployed in an environment where writing to the local filesystem isn't possible (e.g., a cloud platform with an ephemeral filesystem), you can use the `OIDC_CONFIG_DICT` environment variable instead of a sso.yml file.
6054

61-
You'll want to convert the YAML configuration in sso.yml, then stringify the JSON. Here's an example of the final result:
55+
This variable must contain the same configuration data as `sso.yml`, but converted to JSON and then stringified. Here's an example of the final result:
6256

6357
```env
6458
OIDC_CONFIG_DICT="{\"version\": 1,\"oidc_providers\": {\"provider1\": {\"provider_name\": \"okta\",\"client_id\": \"client-id\",\"secret\": \"client-secret\",\"server_url\": \"https://trial-2872264-admin.okta.com\"}}}"
6559
```
6660

67-
For docker installations, you'll also need to add the `OIDC_CONFIG_DICT` variable to the
61+
To create this, convert your `sso.yml` contents to JSON, then wrap the result in quotes and escape any internal quotation marks. Get additional help in our [environment variables guide](./environment-variables.md#oidc_config_dict-optional).
6862

69-
Instructions for where to save the file vary slightly, depending on which installation method you've used:
63+
Instructions for where to save the `sso.yml` file vary slightly, depending on which installation method you've used:
7064

7165
=== "For Docker Compose installations"
7266

73-
For [docker compose](./install-via-docker-compose.md) installations, create a `sso.yml` file next to your [`docker-compose.yml` file](https://github.com/mathesar-foundation/mathesar/raw/{{mathesar_version}}/docker-compose.yml).:
67+
For [docker compose](./install-via-docker-compose.md) installations, create a `sso.yml` file next to your [`docker-compose.yml` file](https://github.com/mathesar-foundation/mathesar/raw/{{mathesar_version}}/docker-compose.yml):
7468

7569
```diff
7670
mathesar
@@ -94,32 +88,30 @@ Instructions for where to save the file vary slightly, depending on which instal
9488

9589
For [non-Docker installations](./install-from-scratch.md), you'll need to create the `sso.yml` file in the installation directory you [defined while installing](./install-from-scratch.md#set-up-your-installation-directory) Mathesar.
9690

97-
Once the file is created, you paste in our [example configuration](https://github.com/mathesar-foundation/mathesar/raw/{{mathesar_version}}/sso.yml.example). You'll edit this configuration in the following steps to work with your provider.
91+
Once the file is created, paste in our [example configuration](https://github.com/mathesar-foundation/mathesar/raw/{{mathesar_version}}/sso.yml.example). You'll edit this configuration in the following steps to work with your provider.
9892

99-
### 3. Configuring the identity provider in Mathesar
93+
## 3. Configuring the identity provider in Mathesar
10094

101-
Now that your identity provider (IdP) is configured and you've created the `sso.yml` file, the next step is to tell Mathesar about your provider by adding it to the `sso.yml` file.
95+
With your identity provider (IdP) set up and the `sso.yml` file created, you're ready to configure Mathesar to use your provider.
10296

103-
We'll use **Okta** as the example provider, but the same structure applies to others like Auth0, Google, or Azure AD.
97+
We'll use Okta as the example, but the same format applies to other providers like Auth0 or Google.
10498

105-
#### Naming Your Provider
99+
### Naming Your Provider
106100

107-
Each provider is defined under a unique key (e.g., `provider1`). Inside that block, you must specify the `provider_name`, which is a lowercase, alphanumeric identifier for the IdP. It should match the value you used in the callback URL.
101+
Each provider is defined under a unique key (e.g., provider1). Inside that block, you must specify the following:
108102

109-
Examples: `okta`, `auth0`, or `google`.
103+
- `provider_name`: A lowercase, alphanumeric identifier that matches the value used in your callback URL.
104+
- `server_url`: The OIDC issuer or discovery URL provided by your IdP. Mathesar uses this to fetch OIDC metadata, including authorization and token endpoints.
110105

111-
You must also specify the `server_url`: the issuer URL or OIDC discovery URL provided by your IdP. This is the base URL that Mathesar uses to fetch OIDC metadata (including token endpoints, authorization endpoints, and keys).
106+
Examples of `server_url` values:
112107

113-
- In Okta, it looks like:
114-
`https://your-org.okta.com`
115-
- In Auth0, it might be:
116-
`https://your-tenant.auth0.com`
117-
- In Google, it’s typically a fixed value:
118-
`https://accounts.google.com`
108+
- Okta: `https://your-org.okta.com`
109+
- Auth0: `https://your-tenant.auth0.com`
110+
- Google: `https://accounts.google.com` (typically a fixed value)
119111

120-
Refer to your IdPs documentation for the correct issuer or discovery URL.
112+
Refer to your IdP's documentation for the exact value.
121113

122-
Now, we should have all the information necessary to add our first provider to `sso.yml`:
114+
Here’s how to start defining your first provider in `sso.yml`:
123115

124116
```diff
125117
# This config file allows you to configure OpenID Connect(OIDC)
@@ -132,16 +124,16 @@ oidc_providers:
132124
+ server_url: https://your-org.okta.com
133125
```
134126

135-
#### Configuring your provider
127+
### Configuring your provider
136128

137-
Next, retrieve the following values from your IdP’s admin interface:
129+
Next, retrieve the following credentials from your IdP’s admin interface:
138130

139131
- `client_id`
140-
- `secret` (sometimes called `client secret`, `token`, or `client key`)
132+
- `secret` (also referred to as client secret, token, or client key)
141133

142-
These credentials authenticate Mathesar with your IdP.
134+
These allow Mathesar to securely authenticate with your identity provider.
143135

144-
Add them to the provider block like so:
136+
Add them to the same provider block:
145137

146138
```diff
147139
provider1:
@@ -151,12 +143,18 @@ Add them to the provider block like so:
151143
+ secret: client-secret
152144
```
153145

154-
You've now completed all the minimum requirements to enable Single Sign-On (SSO) in Mathesar. Next, you can:
146+
You've now completed the **minimum required configuration** to enable SSO in Mathesar.
147+
148+
Next, you can explore optional (but **recommended**) features like:
155149

156-
- Add additional providers, if needed, by repeating this process
157-
- Explore optional but **recommended** settings like [restricting access to particular email domains](#restrict-access-to-specific-email-domains) and [setting default database roles](#set-default-user-roles-for-your-databases)
150+
- [Restricting access to particular email domains](#restrict-access-to-specific-email-domains)
151+
- [Setting default database roles](#set-default-user-roles-for-your-databases)
158152

159-
Finally, you'll need to restart Mathesar so it can read the `sso.yml` file and enable your changes. Be sure to use the correct method for your installation:
153+
You can also repeat this process for any additional providers.
154+
155+
## 4. Activating SSO
156+
157+
To activate Single sign-on, restart Mathesar so it can load the updated `sso.yml` file.
160158

161159
=== "For Docker Compose installations"
162160

@@ -171,9 +169,12 @@ Finally, you'll need to restart Mathesar so it can read the `sso.yml` file and e
171169
sudo systemctl restart mathesar.service
172170
```
173171

174-
These options can help you tailor authentication and access control to better fit your organization's needs.
172+
Visit your Mathesar installation and you should see your provider on the login screen:
175173

176174
![Sign into Mathesar with Okta](../assets/images/sso-login-page-okta.png)
175+
/// caption
176+
Mathesar's login screen with Okta SSO enabled.
177+
///
177178

178179
## Additional configuration options
179180

@@ -237,11 +238,41 @@ oidc_providers:
237238

238239
On first login, users will be granted the specified roles on each listed database. This simplifies onboarding and ensures consistent access control across your environment.
239240

240-
## Disabling Single Sign-On
241+
#### Overriding automatic role provisioning
242+
243+
If you wish to _override_ default role provisioning for specific users, you can manually create their user accounts in the Mathesar UI and assign DB roles directly. When those users log in via SSO for the first time, Mathesar will preserve the roles you set, instead of applying the default roles defined in the SSO provider configuration.
244+
245+
!!!info "Example scenario"
246+
**Company A** wants all employees to have read-only access by default, but account managers should have write access.
247+
248+
In their `sso.yml`, they set the default role to `readonly`. Then, before enabling SSO, they manually create Mathesar accounts for each account manager and assign them the `writeaccess` role in the appropriate database.
249+
250+
When account managers log in via SSO, Mathesar recognizes their email addresses and preserves the `writeaccess` roles, instead of applying the default `readonly` role.
251+
252+
## Transitioning Existing Users to SSO
253+
254+
If you already have users in Mathesar and want them to start using SSO, you can do so without disrupting their accounts, **as long as the email address used for SSO matches their existing Mathesar account email exactly**.
255+
256+
When a user logs in via SSO, Mathesar checks for a matching email address. If a match is found, the user will be logged into their existing Mathesar account. Their roles and access will remain intact.
257+
258+
#### Steps to prepare:
259+
260+
- **Verify email addresses**: Make sure the email for each existing user in Mathesar exactly matches the email returned by your identity provider.
261+
- **Update emails if needed**: If necessary, update existing Mathesar user emails before enabling SSO.
262+
263+
#### Admin caveats:
264+
265+
* **SSO for the default admin account**: If you're using a fresh Mathesar install and want to link the default admin account to an SSO identity, make sure the SSO user has the **same email address** as the admin account created during setup.
266+
Once SSO is enabled, logging in via SSO with that email will connect the SSO identity to the existing admin account.
267+
* **No admin account creation via SSO (yet)**: At this time, Mathesar does not support creating admin accounts through SSO. Admins must be created manually in the Mathesar UI before SSO is enabled.
268+
269+
This approach allows you to adopt SSO gradually while keeping access and roles intact.
270+
271+
## Disabling Single Sign-on
241272

242-
To disable SSO in Mathesar, delete the `sso.yml` file from your installation directory and restart the application. This will revert Mathesar to using only email and password-based authentication.
273+
To disable SSO in Mathesar, delete the `sso.yml` file from your installation directory (or remove the value of the `OIDC_CONFIG_DICT` variable) and restart Mathesar. This will revert Mathesar to using only email and password-based authentication.
243274

244-
!!!warning "Resetting user passwords"
275+
!!!danger "Resetting user passwords"
245276
Users who were originally created via SSO do not have a known password—they are automatically assigned a random, system-generated one during account creation. As a result, these users will not be able to log in after SSO is disabled unless their passwords are reset.
246277

247278
To restore access for these users:

0 commit comments

Comments
 (0)