Jake Hazelke
03/31/2022, 2:34 PMpost
request), I'm getting the following error:
Access to XMLHttpRequest at '<http://localhost:4120/api/check>' from origin '<http://localhost:4200>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
http://localhost:4200 is my angular app, http://localhost:4120/ is my Cerbos server. While reading through the Cerbos docs, it looks like CORS should be enabled by default.
I also tried setting up a proxy (similar to this) to route http://localhost:4200/proxy/api/check -> http://localhost:4120/api/check, but when I do that, I get a connection refused:
[webpack-dev-server] [HPM] Error occurred while proxying request localhost:4200/api/server_info to <http://localhost:4120/> [ECONNREFUSED] (<https://nodejs.org/api/errors.html#errors_common_system_errors>)
Any thoughts?Alex Olivier (Cerbos)
Jake Hazelke
03/31/2022, 2:44 PM---
server:
httpListenAddr: ":4120"
adminAPI:
enabled: true
adminCredentials:
username: cerbos
passwordHash: JDJ5JDEwJGI5d2k0QWNxT0RsSzFib1A2T0M1WXVzRC5pcHprTlFaMWxzVno0ZFB6MllmSlFwY29ycXFhCgo=
storage:
driver: "postgres"
postgres:
url: "<postgresql://cerbos_user:[password]@localhost:5432/Cerbos?sslmode=disable&search_path=cerbos>"
connPool:
maxLifeTime: 5m
maxIdleTime: 3m
maxOpen: 10
maxIdle: 5
Jake Hazelke
03/31/2022, 2:46 PMget
request to <http://localhost:4120/api/server_info>
returns a valid response.Alex Olivier (Cerbos)
/api/check
request I can use to try and replicate?
You can right-click the failing call in Chrome devtools and ‘copy as cURL’Alex Olivier (Cerbos)
allowedHeaders
config: https://docs.cerbos.dev/cerbos/latest/configuration/server.html#_corsJake Hazelke
03/31/2022, 2:58 PMcurl '<http://localhost:4120/api/check>' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"' \
-H 'Referer: <http://localhost:4200/>' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'Content-Type: application/json' \
--data-raw '{"requestId":"095b8b64-9524-4cea-8b82-a9efc54b4576","principal":{"policyVersion":"default","id":"123","roles":["admin"],"attr":{}},"resource":{"policyVersion":"default","kind":"user","instances":{"test_admin":{"attr":{}}}},"actions":["create","read","update","delete"]}' \
--compressed
Jake Hazelke
03/31/2022, 3:00 PMconst cerbosEngine = new Cerbos(hostname);
const authorization = await cerbosEngine.check(data);
Alex Olivier (Cerbos)
Jake Hazelke
03/31/2022, 3:05 PMJake Hazelke
03/31/2022, 3:05 PMsec-ch-ua
, sec-ch-ua-mobile
, etc?Alex Olivier (Cerbos)
Jake Hazelke
03/31/2022, 3:14 PMAlex Olivier (Cerbos)
Jake Hazelke
03/31/2022, 3:15 PMcors:
allowedHeaders:
- Content-Type
- Referer
- sec-ch-ua
- sec-ch-ua-mobile
- sec-ch-ua-platform
- User-Agent
and then retried the SDK call cerbosEngine.check(data)
and can see the 200 response in Chrome DEV toolsAlex Olivier (Cerbos)
Alex Olivier (Cerbos)
Jake Hazelke
03/31/2022, 3:18 PMGET
and POST
requests look good. Going to try out a PUT
request to try to add in some rules.Jake Hazelke
03/31/2022, 3:40 PMPUT
requests work the same way? With the following request, I'm getting the same CORS error (with <http://localhost:4120/admin/policy>
as the url):
curl '<http://localhost:4120/admin/policy>' \
-X 'PUT' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Referer: <http://localhost:4200/>' \
-H 'Content-Type: application/json' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36' \
-H 'sec-ch-ua-platform: "macOS"' \
--data-raw '{"policies":[{"apiVersion":"api.cerbos.dev/v1","resourcePolicy":{"version":"default","resource":"user","rules":[{"roles":["admin"],"actions":["*"],"effect":"EFFECT_ALLOW"},{"roles":["user"],"actions":["create","read"],"effect":"EFFECT_ALLOW"}]}}]}' \
--compressed
Jake Hazelke
03/31/2022, 3:42 PMcors:
allowedHeaders:
- Content-Type
- Referer
- sec-ch-ua
- sec-ch-ua-mobile
- sec-ch-ua-platform
- User-Agent
- Accept
Charith (Cerbos)
Jake Hazelke
03/31/2022, 4:26 PMCharith (Cerbos)
Jake Hazelke
04/04/2022, 1:37 PM