22name : setup-mocksaml
33description : Set up MockSAML as a local SAML IdP for testing SSO flows (grant migration, invite enforcement). Run when setting up a fresh local env or after `supabase db reset`.
44disable-model-invocation : true
5- allowed-tools : Bash(*), Read
65---
76
87# Set Up MockSAML for Local SSO Testing
@@ -50,6 +49,18 @@ If `GOTRUE_SAML_ENABLED=true` is already set, skip to step 6.
5049openssl genrsa 2048 > /tmp/saml_key.pem
5150```
5251
52+ GoTrue requires PKCS #1 format. Check the header of the generated key:
53+
54+ ``` bash
55+ head -1 /tmp/saml_key.pem
56+ ```
57+
58+ - ` BEGIN RSA PRIVATE KEY ` → PKCS #1 , good to go.
59+ - ` BEGIN PRIVATE KEY ` → PKCS #8 (OpenSSL 3.x default). Convert it:
60+ ``` bash
61+ openssl rsa -traditional -in /tmp/saml_key.pem -out /tmp/saml_key.pem
62+ ```
63+
5364Strip to raw base64 (no PEM headers, no newlines):
5465
5566``` bash
@@ -67,10 +78,28 @@ Capture the current container's env vars, image, and network:
6778< docker-prefix> docker inspect supabase_auth_flow --format ' {{json .NetworkSettings.Networks}}'
6879```
6980
70- Stop and remove the old container, then recreate with all original env vars
71- plus the SAML vars. ** Important:** override ` API_EXTERNAL_URL ` to include the
72- ` /auth/v1 ` prefix — GoTrue uses this to generate the SAML ACS callback URL,
73- and without the prefix Kong won't route the callback correctly.
81+ Build an env file for the new container. Using ` --env-file ` avoids shell
82+ parsing issues with values that contain template syntax (e.g.
83+ ` GOTRUE_SMS_TEMPLATE=Your code is {{ .Code }} ` ).
84+
85+ ``` bash
86+ grep -v -E ' ^(PATH=|API_EXTERNAL_URL=)' /tmp/auth_env.txt > /tmp/auth_env_filtered.txt
87+ echo " GOTRUE_SAML_ENABLED=true" >> /tmp/auth_env_filtered.txt
88+ echo " GOTRUE_SAML_PRIVATE_KEY=$SAML_KEY_B64 " >> /tmp/auth_env_filtered.txt
89+ echo " API_EXTERNAL_URL=http://127.0.0.1:5431/auth/v1" >> /tmp/auth_env_filtered.txt
90+ ```
91+
92+ ** Important:** the ` API_EXTERNAL_URL ` override includes the ` /auth/v1 ` prefix —
93+ GoTrue uses this to generate the SAML ACS callback URL, and without the prefix
94+ Kong won't route the callback correctly.
95+
96+ If using Lima, copy the env file into the VM before running docker:
97+
98+ ``` bash
99+ limactl copy /tmp/auth_env_filtered.txt < vm> :/tmp/auth_env_filtered.txt
100+ ```
101+
102+ Stop and remove the old container, then recreate:
74103
75104``` bash
76105< docker-prefix> docker stop supabase_auth_flow && < docker-prefix> docker rm supabase_auth_flow
@@ -79,10 +108,7 @@ and without the prefix Kong won't route the callback correctly.
79108 --name supabase_auth_flow \
80109 --network < network-name> \
81110 --restart always \
82- -e GOTRUE_SAML_ENABLED=true \
83- -e GOTRUE_SAML_PRIVATE_KEY=$SAML_KEY_B64 \
84- -e API_EXTERNAL_URL=http://127.0.0.1:5431/auth/v1 \
85- < all original -e flags from /tmp/auth_env.txt, excluding PATH= and API_EXTERNAL_URL=> \
111+ --env-file /tmp/auth_env_filtered.txt \
86112 < image> auth
87113```
88114
@@ -102,6 +128,15 @@ supabase status --output json
102128
103129Extract ` SERVICE_ROLE_KEY ` from the output.
104130
131+ If ` supabase status ` fails (e.g. Docker runs inside a Lima VM), read the key
132+ from Kong's config instead — it's always accessible since Kong handles routing:
133+
134+ ``` bash
135+ < docker-prefix> docker exec supabase_kong_flow cat /home/kong/kong.yml
136+ ```
137+
138+ Look for the ` service_role ` JWT in the authorization header rewriting rules.
139+
105140### 7. Check if MockSAML is already registered
106141
107142``` bash
@@ -114,14 +149,20 @@ register a new one. If reusing, skip to step 9.
114149
115150### 8. Register MockSAML as an SSO provider
116151
152+ Ask the user which email domain to associate with the SSO provider (default:
153+ ` example.com ` ). This controls which email addresses are routed through SAML
154+ login. MockSAML's default test user is ` jackson@example.com ` , so ` example.com `
155+ works out of the box — but the user may want a different domain to match their
156+ test data.
157+
117158``` bash
118159curl -X POST ' http://127.0.0.1:5431/auth/v1/admin/sso/providers' \
119160 -H ' Authorization: Bearer <SERVICE_ROLE_KEY>' \
120161 -H ' Content-Type: application/json' \
121162 -d ' {
122163 "type": "saml",
123164 "metadata_url": "https://mocksaml.com/api/saml/metadata",
124- "domains": ["example.com "]
165+ "domains": ["<DOMAIN> "]
125166 }'
126167```
127168
0 commit comments