Skip to content

Commit 004dd15

Browse files
committed
feat: add origin protection header
1 parent ea1ebd1 commit 004dd15

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

ansible/files/envoy_config/lds.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ resources:
3737
rules:
3838
action: DENY
3939
policies:
40+
origin_protection_key_missing:
41+
permissions:
42+
- any: true
43+
principals:
44+
- not_id:
45+
or_ids:
46+
ids:
47+
- header:
48+
name: x-sb-origin-protection-key
49+
present_match: true
50+
origin_protection_key_not_valid:
51+
permissions:
52+
- any: true
53+
principals:
54+
- not_id:
55+
or_ids:
56+
ids:
57+
# when rolling over the key add a new entry here, deploy, then remove the old key and deploy again
58+
- header:
59+
name: x-sb-origin-protection-key
60+
string_match:
61+
exact: origin_protection_key
4062
api_key_missing:
4163
permissions:
4264
- any: true

ansible/files/envoy_config/remove_apikey_query_parameter.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ function envoy_on_request(request_handle)
55
request_handle
66
:headers()
77
:replace(":path", path:gsub("([&?])apikey=[^&]+&?", "%1"):gsub("&$", ""))
8+
9+
-- Removes the x-sb-origin-protection-key as it can be inspected via PostgREST pre-request hook, etc.
10+
request_handle
11+
:headers()
12+
:replace("x-sb-origin-protection-key", "")
813
end

docker/all-in-one/init/configure-envoy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ sed -i -e "s|anon_key|${ANON_KEY}|g" \
4242
-e "s|service_key|${SERVICE_ROLE_KEY}|g" \
4343
-e "s|supabase_admin_key|${ADMIN_API_KEY}|g" \
4444
-e "s|c2VydmljZV9yb2xlOnNlcnZpY2Vfa2V5|$(echo -n "service_role:${SERVICE_ROLE_KEY}" | base64 --wrap 0)|g" \
45+
-e "s|origin_protection_key|${ORIGIN_PROTECTION_KEY}|g" \
4546
"${ENVOY_LDS_CONF}"
4647

4748
# Update Envoy ports

0 commit comments

Comments
 (0)