Skip to content

Commit e1b66b4

Browse files
Ramiro Nuñez Dosiofsansalvadorekangmingtay
authored
Blog post: Supabase Engineering: What is SAML Authentication. (supabase#20490)
* Blog post: Supabase Engineering: What is SAML Authentication. * Add images and internal links. * Update copy. * Swap image. * prettify blog post * Update apps/www/_blog/2024-01-17-what-is-saml-authentication.mdx Co-authored-by: Kang Ming <[email protected]> * Update apps/www/_blog/2024-01-17-what-is-saml-authentication.mdx Co-authored-by: Kang Ming <[email protected]> * Update apps/www/_blog/2024-01-17-what-is-saml-authentication.mdx Co-authored-by: Kang Ming <[email protected]> * Update apps/www/_blog/2024-01-17-what-is-saml-authentication.mdx Co-authored-by: Kang Ming <[email protected]> --------- Co-authored-by: Francesco Sansalvadore <[email protected]> Co-authored-by: Kang Ming <[email protected]>
1 parent bfad422 commit e1b66b4

9 files changed

+178
-22
lines changed
+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
title: What is SAML? A practical guide to the authentication protocol
3+
description: Learn what is SAML authentication, how it differentiates from SSO, SAML with Postgres, and more.
4+
author: kangmingtay
5+
image: what-is-saml/what-is-saml-og.png
6+
thumb: what-is-saml/what-is-saml-thumb.png
7+
categories:
8+
- engineering
9+
tags:
10+
- supabase-engineering
11+
date: '2024-01-17'
12+
toc_depth: 3
13+
---
14+
15+
In the digital landscape, ensuring secure access is paramount, and that's where Security Assertion Markup Language (SAML) steps in. In this post, we'll explore how SAML simplifies the complex process of verifying identities across different platforms.
16+
17+
## What is SAML?
18+
19+
As organizations scale, their HR and IT departments struggle to keep employee and identity records across various applications. Typically they use an identity provider, like GSuite, Microsoft Active Directory, or Okta, to consolidate all of their employee data and permissions in one place.
20+
21+
Using an **identity provider** allows them to easily automate the on-boarding and off-boarding processes for employees. Without an identity provider, adding or removing (typically called provisioning) access to 3rd-party applications for each employee can quickly turn into an administrative nightmare.
22+
23+
These 3rd-party applications, also known as **service providers,** have Single Sign On (SSO) integrated to allow users to sign into the app. For an identity provider to authenticate with a service provider, an authentication protocol needs to be established first. SAML (Security Assertion Markup Language) is one such protocol that helps to facilitate SSO between an identity provider and a service provider.
24+
25+
The SAML protocol uses the XML format to store encrypted data related to the authenticated user, also known as SAML assertions. Before the identity provider and the service provider can establish a successful SAML authorization flow, both providers need to exchange their public keys, which come in the form of an X.509 certificate. This allows the identity provider to verify the incoming SAML request and allows the service provider to verify the SAML response returned by the identity provider.
26+
27+
## SAML vs SSO
28+
29+
SAML and Single Sign-On (SSO) are integral components in the realm of authentication and access management, but each plays a distinct role.
30+
31+
SSO is a broader concept centered around simplifying user experiences by allowing access to multiple applications or services with a single set of credentials. Unlike SAML, SSO is not a protocol but a versatile approach that can be realized through various protocols, including SAML, OAuth, or OpenID Connect. Its scope extends beyond specific data exchange formats, aiming to streamline user logins across diverse systems. For example, a user signing into their Google account experiences SSO as they effortlessly access various Google services without the hassle of repeated logins. In essence, while SAML addresses secure data exchange for authentication, SSO encompasses a broader vision of user convenience and access management.
32+
33+
## How does SAML authentication work?
34+
35+
Here’s a story about how SAML is enabled between an application (Supabase) and its users (ACME Inc.).
36+
37+
Alice is a software engineer at ACME Inc. a Fortune 500 company that loves Postgres and Supabase. Recently, she joined the Innovation department to discover new avenues for growth. She sees this as an opportunity to build rapid prototypes with Supabase and persuades the management team to allow her team to use Supabase.
38+
39+
Management gives the green light and Alice reaches out to Supabase’s sales department and strikes a deal.
40+
41+
However, ACME Inc. has 1000 developers on payroll and a very demanding security team that mandates either SAML or OIDC Single Sign-On for all 3rd-party applications. They also use GSuite as their identity provider.
42+
43+
So Alice asks Supabase for this, and they help her set up SAML for ACME. But first, Supabase needs Alice to send over information about their identity provider. Alice chases down Bob, who’s in ACME’s IT department, and asks for help to enable Supabase.
44+
45+
Supabase and Bob need to exchange some information to establish a SAML Connection between Supabase and ACME’s GSuite system.
46+
47+
### What does Bob need from Supabase?
48+
49+
- An X.509 certificate that GSuite can use to identify SAML SSO requests as originating from Supabase.
50+
- An Entity ID that uniquely identifies Supabase’s authentication system.
51+
- An ACS URL, a callback API endpoint where GSuite will send SAML Responses for validation.
52+
- A Site URL, where employees in GSuite can pick Supabase and get instant access to it.
53+
- Supabase’s logo/icon so that the application shows up nicely in the list of 3rd-party apps approved by ACME.
54+
- A list of mandatory attributes to be included in the SAML Assertion.
55+
- Usually email, name, department, phone, …
56+
57+
### What does Bob need from Alice?
58+
59+
The list of employees that should be able to access Supabase - so that Bob can get Supabase to show up to the correct people.
60+
61+
### What Supabase needs from Bob?
62+
63+
- An X.509 certificate that Supabase can use to identify SAML Responses as originating from ACME’s GSuite.
64+
- An Entity ID that uniquely identifies ACME’s GSuite setup.
65+
- ACME’s allowed email domains: acme.com, acme.org.
66+
- A Redirect URL, where Supabase can redirect users attempting to sign in with `[email protected]` or `[email protected]` to log into GSuite.
67+
- A Single Log-Out URL where Supabase can send log-out requests by ACME’s employees.
68+
- A list of all attributes that ACME’s GSuite system will send to Supabase; specifically the attributes about the employee’s email, name, and groups (are they a developer or not).
69+
70+
### Summary
71+
72+
Both parties need to exchange almost the same information:
73+
74+
- X.509 certificates so that the systems trust each other.
75+
- Entity IDs so that the systems know each other.
76+
- URLs so that they can talk to each other.
77+
- Information about the structure of data passing between them (attribute mappings).
78+
79+
## SAML Metadata XML
80+
81+
Since much of this information is tricky to communicate and requires manual input, there exists the SAML Metadata XML document which exposes _most_ but not all of the information. Both systems, the Identity Provider (GSuite) and the Service Provider (Supabase) each have their own SAML Metadata that needs to be exchanged.
82+
83+
Often this document is available publicly at a URL. Note though, that sometimes Identity Providers (typically Microsoft Active Directory) may not be accessible over the internet (as they’re behind a VPN) so a URL can’t be used and a file needs to be exchanged in that case. Service Providers may also be isolated in their network, so a file exchange is necessary here too, albeit uncommon.
84+
85+
Inside this XML document, you can find most of the information required by Bob and Supabase:
86+
87+
- X.509 certificate
88+
- Entity ID
89+
- ACS, SLO, Site URLs
90+
91+
However, both parties still need to agree over email about the email domains of ACME, and about the attributes that they have in their system.
92+
93+
First, Supabase and Bob exchange some of the information over email. Then Bob goes to GSuite and creates a new SAML Application.
94+
95+
Finally, once Bob registers ACME’s Identity Provider (GSuite), the connection is established and ACME employees can access Supabase — directly by visiting Supabase’s site (SP-initiated) or by picking it in the GSuite Applications menu (IdP-initiated).
96+
97+
This is how the SAML SP-initiated authorization flow looks like when Alice visits Supabase and enters her email to sign in with SAML SSO.
98+
99+
<Img
100+
src={{
101+
dark: '/images/blog/what-is-saml/saml-authentication-flow_dark.png',
102+
light: '/images/blog/what-is-saml/saml-authentication-flow_light.png',
103+
}}
104+
alt="How the SAML SP-initiated authorization flow looks like when Alice visits Supabase and enters her email to sign in with SAML SSO"
105+
/>
106+
107+
In the IdP-initiated flow, the employee signs into GSuite first and selects the application to sign into from a list of allowed 3rd-party applications instead of being redirected from the service provider.
108+
109+
## SAML Authentication with Supabase
110+
111+
At Supabase, you can easily enable SAML for your project and use the signInWithSSO method to start the authentication flow. Both IdP-initiated and SP-initiated flows are supported. When a user signs in with SAML SSO, the JWT issued contains a unique ID to identify the identity provider. If you are already using Postgres on Supabase, this also ties in nicely with your existing row-level security (RLS) policies, since you can use that ID to restrict access to the data.
112+
113+
### SAML with Row Level Security
114+
115+
Combining SAML with Row-Level Security (RLS) allows for fine-grained control over data access, ensuring that users only interact with the specific data rows aligned with their roles or attributes. This improves security and helps meet regulatory requirements while allowing flexible adjustments to access permissions over time.
116+
117+
Since Supabase is “just Postgres”™, it enables us to easily leverage the power of RLS policies to restrict access to the data. You can access the user’s JWT claims by invoking the `auth.jwt()` function in your RLS policy. In the scenario provided above, this allows Supabase to restrict developers from ACME Inc. from inviting someone else outside of the company to join their Supabase organization.
118+
119+
For example, assuming we have a table to store all invited users in a Supabase organization:
120+
121+
```sql
122+
create table invited_users (
123+
id uuid not null primary key,
124+
sso_provider_id uuid,
125+
email text,
126+
name text
127+
);
128+
```
129+
130+
We can create an RLS policy to enforce that a developer in ACME Inc. can only invite someone who is also a developer in the same company:
131+
132+
```sql
133+
create policy "View "
134+
on invited_users
135+
as restrictive
136+
for insert
137+
with check (
138+
sso_provider_id = auth.jwt()#>>'{amr,0,provider}'
139+
);
140+
```
141+
142+
## Conclusion
143+
144+
In this post, we took a deep dive into SAML, from understanding how organizations centralize employee data using identity providers to illustrating SAML integration through a real-world use case and a practical implementation of SAML in conjunction with Row-Level Security (RLS).
145+
146+
Supabase Auth currently supports [authenticating with SAML](https://supabase.com/docs/guides/auth/sso/auth-sso-saml) easily, setting it up takes less than an hour, so you can focus on shipping the core features of your product.
147+
148+
## More from the Auth team
149+
150+
- [Supabase Auth: Identity Linking, Hooks, and HaveIBeenPwned integration](https://supabase.com/blog/supabase-auth-identity-linking-hooks)
151+
- [Supabase Auth: SSO, Mobile, and Server-side support](https://supabase.com/blog/supabase-auth-sso-pkce)
152+
- [Supabase Auth docs](https://supabase.com/docs/guides/auth)
153+
154+
## More from Supabase engineering
155+
156+
- [Elixir clustering using Postgres](https://supabase.com/blog/elixir-clustering-using-postgres)
Loading
Loading
31.8 KB
Loading
18.2 KB
Loading

Diff for: apps/www/public/planetpg-bo_lu-rss.xml

-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
<description>Supabase Wrappers v0.2 brings more Wrappers, query pushdown, remote subquery, and more</description>
1515
<pubDate>Wed, 13 Dec 2023 23:00:00 GMT</pubDate>
1616
</item>
17-
<item>
18-
<guid>https://supabase.com/blog/postgres-foreign-data-wrappers-rust</guid>
19-
<title>Supabase Wrappers, a Postgres FDW framework written in Rust</title>
20-
<link>https://supabase.com/blog/postgres-foreign-data-wrappers-rust</link>
21-
<description>A framework for building Postgres Foreign Data Wrappers which connects to Stripe, Firebase, Clickhouse, and more.</description>
22-
<pubDate>Wed, 14 Dec 2022 23:00:00 GMT</pubDate>
23-
</item>
2417

2518
</channel>
2619
</rss>

Diff for: apps/www/public/planetpg-oli_rice-rss.xml

-7
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@
4949
<description>Announcing the v1.0 release of pg_graphql</description>
5050
<pubDate>Thu, 15 Dec 2022 23:00:00 GMT</pubDate>
5151
</item>
52-
<item>
53-
<guid>https://supabase.com/blog/postgres-foreign-data-wrappers-rust</guid>
54-
<title>Supabase Wrappers, a Postgres FDW framework written in Rust</title>
55-
<link>https://supabase.com/blog/postgres-foreign-data-wrappers-rust</link>
56-
<description>A framework for building Postgres Foreign Data Wrappers which connects to Stripe, Firebase, Clickhouse, and more.</description>
57-
<pubDate>Wed, 14 Dec 2022 23:00:00 GMT</pubDate>
58-
</item>
5952
<item>
6053
<guid>https://supabase.com/blog/pg-jsonschema-a-postgres-extension-for-json-validation</guid>
6154
<title>pg_jsonschema: JSON Schema support for Postgres</title>

Diff for: apps/www/public/planetpg-paul_copplestone-rss.xml

-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
<description>Exploring history of Postgres pluggable storage and the possibility of landing it in the Postgres core.</description>
1515
<pubDate>Sun, 30 Apr 2023 22:00:00 GMT</pubDate>
1616
</item>
17-
<item>
18-
<guid>https://supabase.com/blog/postgres-foreign-data-wrappers-rust</guid>
19-
<title>Supabase Wrappers, a Postgres FDW framework written in Rust</title>
20-
<link>https://supabase.com/blog/postgres-foreign-data-wrappers-rust</link>
21-
<description>A framework for building Postgres Foreign Data Wrappers which connects to Stripe, Firebase, Clickhouse, and more.</description>
22-
<pubDate>Wed, 14 Dec 2022 23:00:00 GMT</pubDate>
23-
</item>
2417
<item>
2518
<guid>https://supabase.com/blog/postgres-crdt</guid>
2619
<title>pg_crdt - an experimental CRDT extension for Postgres</title>

Diff for: apps/www/public/rss.xml

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,30 @@
55
<link>https://supabase.com</link>
66
<description>Latest news from Supabase</description>
77
<language>en</language>
8-
<lastBuildDate>Mon, 08 Jan 2024 23:00:00 GMT</lastBuildDate>
8+
<lastBuildDate>Tue, 16 Jan 2024 23:00:00 GMT</lastBuildDate>
99
<atom:link href="https://supabase.com/rss.xml" rel="self" type="application/rss+xml"/>
1010
<item>
11+
<guid>https://supabase.com/blog/what-is-saml-authentication</guid>
12+
<title>What is SAML? A practical guide to the authentication protocol</title>
13+
<link>https://supabase.com/blog/what-is-saml-authentication</link>
14+
<description>Learn what is SAML authentication, how it differentiates from SSO, SAML with Postgres, and more.</description>
15+
<pubDate>Tue, 16 Jan 2024 23:00:00 GMT</pubDate>
16+
</item>
17+
<item>
18+
<guid>https://supabase.com/blog/ipv6</guid>
19+
<title>Brace yourself, IPv6 is coming</title>
20+
<link>https://supabase.com/blog/ipv6</link>
21+
<description>On February 1st 2024, AWS will start charging for IPv4 addresses. This is a big deal for the internet, and we&apos;re here to help you prepare.</description>
22+
<pubDate>Thu, 11 Jan 2024 23:00:00 GMT</pubDate>
23+
</item>
24+
<item>
25+
<guid>https://supabase.com/blog/react-query-nextjs-app-router-cache-helpers</guid>
26+
<title>Using React Query with Next.js App Router and Supabase Cache Helpers</title>
27+
<link>https://supabase.com/blog/react-query-nextjs-app-router-cache-helpers</link>
28+
<description>Learn how to use React Query in Next.js Client &amp; Server Components for data fetching with Supabase.</description>
29+
<pubDate>Thu, 11 Jan 2024 23:00:00 GMT</pubDate>
30+
</item>
31+
<item>
1132
<guid>https://supabase.com/blog/elixir-clustering-using-postgres</guid>
1233
<title>Elixir clustering using Postgres</title>
1334
<link>https://supabase.com/blog/elixir-clustering-using-postgres</link>

0 commit comments

Comments
 (0)