You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/administration/environment-variables.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,7 @@ Note: The default values specified here refer to those in Mathesar's [docker-com
87
87
## Single Sign-on (SSO) {: #sso}
88
88
89
89
!!!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.
Copy file name to clipboardExpand all lines: docs/docs/administration/single-sign-on.md
+87-56Lines changed: 87 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,16 @@
1
1
# Single Sign-on (SSO)
2
2
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.
4
4
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.
6
6
7
+
## 1. Setting up your identity provider
7
8
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.
9
10
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:
11
12
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.
Whichever provider you're using, you'll begin by creating an application.
25
+
To get started, create an application within your chosen provider.
34
26
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.
36
28
37
29
!!!info "Configuring the callback URL"
38
30
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
44
36
Replace `<mathesar-domain>` with the domain name of your Mathesar installation.<br>
45
37
Examples: `mathesar.myorg.com`, `localhost:8000`
46
38
47
-
Replace `<provider-name>` with the name of your IdP provider.<br>
39
+
Replace `<provider-name>` with the key of your IdP provider.<br>
48
40
Examples: `auth0`, `okta`, `google`
49
41
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.
51
45
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
53
47
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`.
55
49
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.
57
51
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.
60
54
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:
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).
68
62
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:
70
64
71
65
=== "For Docker Compose installations"
72
66
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):
74
68
75
69
```diff
76
70
mathesar
@@ -94,32 +88,30 @@ Instructions for where to save the file vary slightly, depending on which instal
94
88
95
89
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.
96
90
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.
98
92
99
-
###3. Configuring the identity provider in Mathesar
93
+
## 3. Configuring the identity provider in Mathesar
100
94
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.
102
96
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 Auth0or Google.
104
98
105
-
####Naming Your Provider
99
+
### Naming Your Provider
106
100
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:
108
102
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.
110
105
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:
112
107
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)
119
111
120
-
Refer to your IdP’s documentation for the correct issuer or discovery URL.
112
+
Refer to your IdP's documentation for the exact value.
121
113
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`:
123
115
124
116
```diff
125
117
# This config file allows you to configure OpenID Connect(OIDC)
@@ -132,16 +124,16 @@ oidc_providers:
132
124
+ server_url: https://your-org.okta.com
133
125
```
134
126
135
-
####Configuring your provider
127
+
### Configuring your provider
136
128
137
-
Next, retrieve the following values from your IdP’s admin interface:
129
+
Next, retrieve the following credentials from your IdP’s admin interface:
138
130
139
131
-`client_id`
140
-
-`secret` (sometimes called `client secret`, `token`, or `client key`)
132
+
-`secret` (also referred to as client secret, token, or client key)
141
133
142
-
These credentials authenticate Mathesar with your IdP.
134
+
These allow Mathesar to securely authenticate with your identity provider.
143
135
144
-
Add them to the provider block like so:
136
+
Add them to the same provider block:
145
137
146
138
```diff
147
139
provider1:
@@ -151,12 +143,18 @@ Add them to the provider block like so:
151
143
+ secret: client-secret
152
144
```
153
145
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:
155
149
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)
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.
160
158
161
159
=== "For Docker Compose installations"
162
160
@@ -171,9 +169,12 @@ Finally, you'll need to restart Mathesar so it can read the `sso.yml` file and e
171
169
sudo systemctl restart mathesar.service
172
170
```
173
171
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:
175
173
176
174

175
+
/// caption
176
+
Mathesar's login screen with Okta SSO enabled.
177
+
///
177
178
178
179
## Additional configuration options
179
180
@@ -237,11 +238,41 @@ oidc_providers:
237
238
238
239
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.
239
240
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
241
272
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.
243
274
244
-
!!!warning "Resetting user passwords"
275
+
!!!danger "Resetting user passwords"
245
276
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.
0 commit comments