Skip to content

Commit 95c37c7

Browse files
committed
add oidc config variables
1 parent 90d4b01 commit 95c37c7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

configuration.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Here are the available configuration options and their default values:
2424
| `configuration_directory` | `./sqlpage/` | The directory where the `sqlpage.json` file is located. This is used to find the path to [`templates/`](https://sql-page.com/custom_components.sql), [`migrations/`](https://sql-page.com/your-first-sql-website/migrations.sql), and `on_connect.sql`. Obviously, this configuration parameter can be set only through environment variables, not through the `sqlpage.json` file itself in order to find the `sqlpage.json` file. Be careful not to use a path that is accessible from the public WEB_ROOT |
2525
| `allow_exec` | false | Allow usage of the `sqlpage.exec` function. Do this only if all users with write access to sqlpage query files and to the optional `sqlpage_files` table on the database are trusted. |
2626
| `max_uploaded_file_size` | 5242880 | Maximum size of forms and uploaded files in bytes. Defaults to 5 MiB. |
27+
| `oidc_issuer_url` | | The base URL of the [OpenID Connect provider](#openid-connect-oidc-authentication). Required for enabling Single Sign-On. |
28+
| `oidc_client_id` | sqlpage | The ID that identifies your SQLPage application to the OIDC provider. You get this when registering your app with the provider. |
29+
| `oidc_client_secret` | | The secret key for your SQLPage application. Keep this confidential as it allows your app to authenticate with the OIDC provider. |
30+
| `oidc_scopes` | openid email profile | Space-separated list of [scopes](https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims) your app requests from the OIDC provider. |
2731
| `max_pending_rows` | 256 | Maximum number of rendered rows that can be queued up in memory when a client is slow to receive them. |
2832
| `compress_responses` | true | When the client supports it, compress the http response body. This can save bandwidth and speed up page loading on slow connections, but can also increase CPU usage and cause rendering delays on pages that take time to render (because streaming responses are buffered for longer than necessary). |
2933
| `https_domain` | | Domain name to request a certificate for. Setting this parameter will automatically make SQLPage listen on port 443 and request an SSL certificate. The server will take a little bit longer to start the first time it has to request a certificate. |
@@ -83,6 +87,43 @@ If the `database_password` configuration parameter is set, it will override any
8387
It does not need to be percent-encoded.
8488
This allows you to keep the password separate from the connection string, which can be useful for security purposes, especially when storing configurations in version control systems.
8589

90+
### OpenID Connect (OIDC) Authentication
91+
92+
OpenID Connect (OIDC) is a secure way to let users log in to your SQLPage application using their existing accounts from popular services. When OIDC is configured, all access to your SQLPage application will require users to log in through the chosen provider. This enables Single Sign-On (SSO), allowing you to restrict access to your application without having to handle authentication yourself.
93+
94+
To set up OIDC, you'll need to:
95+
1. Register your application with an OIDC provider
96+
2. Configure the provider's details in SQLPage
97+
98+
#### Cloud Identity Providers
99+
100+
- **Google**
101+
- Documentation: https://developers.google.com/identity/openid-connect/openid-connect
102+
- Set *oidc_issuer_url* to `https://accounts.google.com`
103+
104+
- **Microsoft Entra ID** (formerly Azure AD)
105+
- Documentation: https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app
106+
- Set *oidc_issuer_url* to `https://login.microsoftonline.com/{tenant}/v2.0`
107+
- ([Find your tenant name](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc#find-your-apps-openid-configuration-document-uri))
108+
109+
- **GitHub**
110+
- Issuer URL: `https://github.com`
111+
- Documentation: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps
112+
113+
#### Self-Hosted Solutions
114+
115+
- **Keycloak**
116+
- Issuer URL: `https://your-keycloak-server/auth/realms/your-realm`
117+
- [Setup Guide](https://www.keycloak.org/getting-started/getting-started-docker)
118+
119+
- **Authentik**
120+
- Issuer URL: `https://your-authentik-server/application/o/your-application`
121+
- [Setup Guide](https://goauthentik.io/docs/providers/oauth2)
122+
123+
After registering your application with the provider, you'll receive a client ID and client secret. These are used to configure SQLPage to work with your chosen provider.
124+
125+
Note: OIDC is optional. If you don't configure it, your SQLPage application will be accessible without authentication.
126+
86127
### Example `.env` file
87128

88129
```bash

src/app_config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ pub struct AppConfig {
198198
#[serde(default = "default_max_file_size")]
199199
pub max_uploaded_file_size: usize,
200200

201+
/// The base URL of the `OpenID` Connect provider.
202+
/// Required when enabling Single Sign-On through an OIDC provider.
203+
pub oidc_issuer_url: Option<String>,
204+
/// The client ID assigned to `SQLPage` when registering with the OIDC provider.
205+
/// Defaults to `sqlpage`.
206+
#[serde(default = "default_oidc_client_id")]
207+
pub oidc_client_id: String,
208+
/// The client secret for authenticating `SQLPage` to the OIDC provider.
209+
/// Required when enabling Single Sign-On through an OIDC provider.
210+
pub oidc_client_secret: Option<String>,
211+
/// Space-separated list of [scopes](https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims) to request during OIDC authentication.
212+
/// Defaults to "openid email profile"
213+
#[serde(default = "default_oidc_scopes")]
214+
pub oidc_scopes: String,
215+
201216
/// A domain name to use for the HTTPS server. If this is set, the server will perform all the necessary
202217
/// steps to set up an HTTPS server automatically. All you need to do is point your domain name to the
203218
/// server's IP address.
@@ -528,6 +543,14 @@ fn default_markdown_allow_dangerous_protocol() -> bool {
528543
false
529544
}
530545

546+
fn default_oidc_client_id() -> String {
547+
"sqlpage".to_string()
548+
}
549+
550+
fn default_oidc_scopes() -> String {
551+
"openid email profile".to_string()
552+
}
553+
531554
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone, Copy, Eq, Default)]
532555
#[serde(rename_all = "lowercase")]
533556
pub enum DevOrProd {

0 commit comments

Comments
 (0)