test-cerbos-nestjs
08/14/2024, 7:55 AMAlex Olivier (Cerbos)
Alex Olivier (Cerbos)
npm run cerbos:start
then in another npm run test:e2e
And getting
~/projects/cerbos/repos/nestjs-cerbos main ❯ npm run test:e2e
> project@0.0.1 test:e2e
> jest --config ./test/jest-e2e.json
PASS test/app.e2e-spec.ts
AppController (e2e)
/ (GET)
✓ Succesfully return content (57 ms)
/document/1 - Admin
✓ Return 403 (forbitten), when accessed with incorrect header (23 ms)
✓ Return 403 (forbitten), when accessed with role of "user". (5 ms)
✓ Return 200 (success), when accessed with role of "admin". (5 ms)
Test Suites: 1 passed, 1 total
Tests: 4 passed, 4 total
Snapshots: 0 total
Time: 0.952 s, estimated 2 s
Ran all test suites.
test-cerbos-nestjs
08/14/2024, 10:46 AMAlex Olivier (Cerbos)
test-cerbos-nestjs
08/14/2024, 11:01 AMtest-cerbos-nestjs
08/14/2024, 12:44 PMimport { HTTP } from '@cerbos/http';
Currently i use this library to check authorization in FE
Do you have any idea with this error?
Uncaught (in promise) _NotOK: gRPC error 2 (UNKNOWN): Request failed: NetworkError when attempting to fetch resource.
Alex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 8:12 AMtest-cerbos-nestjs
08/15/2024, 8:13 AMtest-cerbos-nestjs
08/15/2024, 8:13 AMAlex Olivier (Cerbos)
Alex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 8:30 AMAlex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 8:38 AMcerbos:
image: <http://ghcr.io/cerbos/cerbos:latest|ghcr.io/cerbos/cerbos:latest>
container_name: cerbos
ports:
- "3592:3592"
- "3593:3593"
volumes:
- ./../../cerbos:/policies
restart: unless-stopped
i use docker to run cerbos and yes I run my application on localhostAlex Olivier (Cerbos)
services:
app:
build: .
container_name: app
ports:
- "3000:3000"
cerbos:
image: <http://ghcr.io/cerbos/cerbos:latest|ghcr.io/cerbos/cerbos:latest>
container_name: cerbos
ports:
- "3592:3592"
- "3593:3593"
volumes:
- ./cerbos:/policies
restart: unless-stopped
I'm not getting any errors which would suggest there is something else happening in the request pipeline in the enviroment you are running. Is there anything like a loadbalancer or such in between which could be modifying the headers?test-cerbos-nestjs
08/15/2024, 8:49 AMAlex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 8:52 AMtest-cerbos-nestjs
08/15/2024, 8:55 AMdocker run --rm --name cerbos -v $(pwd)/cerbos/policies:/policies -p 3592:3592 -p 3593:3593 <http://ghcr.io/cerbos/cerbos:latest|ghcr.io/cerbos/cerbos:latest>
and i still get the same error
I suspect it depends on browser(currently I am using mozilla)test-cerbos-nestjs
08/15/2024, 8:57 AMtest-cerbos-nestjs
08/15/2024, 8:59 AMtest-cerbos-nestjs
08/15/2024, 9:00 AMAlex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 9:06 AMdocker run --rm --name cerbos -d -v $(pwd)/cerbos:/policies -p 1592:1592 -p 1593:1593 <http://ghcr.io/cerbos/cerbos:0.19.0|ghcr.io/cerbos/cerbos:0.19.0>
I still get the same error with this version 0.19.0test-cerbos-nestjs
08/15/2024, 9:07 AMtest-cerbos-nestjs
08/15/2024, 9:09 AMAlex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 9:21 AMtest-cerbos-nestjs
08/15/2024, 9:22 AMtest-cerbos-nestjs
08/15/2024, 9:23 AMAlex Olivier (Cerbos)
Alex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 9:28 AMtest-cerbos-nestjs
08/15/2024, 10:36 AMdocker run --rm --name cerbos -d -v $(pwd):/cerbos-dev -p 3592:3592 <http://ghcr.io/cerbos/cerbos:0.38.1|ghcr.io/cerbos/cerbos:0.38.1> server --config=/cerbos-dev/cerbos/.cerbos.yaml
Hey my mozilla browser still gets this error after I setup the cerbos server config and run this docker commandtest-cerbos-nestjs
08/15/2024, 10:36 AMtest-cerbos-nestjs
08/15/2024, 10:37 AMserver:
httpListenAddr: ":3592"
storage:
driver: "disk"
disk:
directory: /cerbos-dev/policies
watchForChanges: true
cors:
allowedOrigins:
- <http://localhost:3000>
- <http://localhost:3001>
- <http://localhost:3002>
Alex Olivier (Cerbos)
server:
httpListenAddr: ":3592"
cors:
allowedOrigins:
- "*"
allowedHeaders:
- "*"
storage:
driver: "disk"
disk:
directory: /cerbos-dev/policies
watchForChanges: true
Alex Olivier (Cerbos)
test-cerbos-nestjs
08/15/2024, 11:08 AMtest-cerbos-nestjs
08/15/2024, 11:14 AMAlex Olivier (Cerbos)
server:
httpListenAddr: ":3592"
cors:
allowedOrigins:
- localhost:3000
allowedHeaders:
- "*"
storage:
driver: "disk"
disk:
directory: /policies
watchForChanges: true
Alex Olivier (Cerbos)
May I know why it is recommended to use Cerbos Hub's Embedded PDP?In the current setup you have to expose your PDP service to the internet and then do extract API calls to check permisions. With the embedded PDP the policies are evaluated directly in the browser.
test-cerbos-nestjs
08/15/2024, 11:21 AMtest-cerbos-nestjs
08/15/2024, 11:25 AMserver:
httpListenAddr: ":3592"
cors:
allowedOrigins:
- localhost:3000
allowedHeaders:
- "*"
storage:
driver: "disk"
disk:
directory: /cerbos-dev/policies
watchForChanges: true
i changed the allowedOrigins as suggested, then I get the CORS error again with firefox👀Alex Olivier (Cerbos)
http
off
server:
httpListenAddr: ":3592"
cors:
allowedOrigins:
- "<http://localhost:3000>"
allowedHeaders:
- "*"
storage:
driver: "disk"
disk:
directory: /policies
watchForChanges: true
test-cerbos-nestjs
08/28/2024, 7:56 AMoguzhan
const cerbosCheck = await cerbos.checkResource(cerbosRequest)
with time functions instead. Ex:
console.time('cerbos.checkResource');
const cerbosCheck = await cerbos.checkResource(cerbosRequest);
console.timeEnd('cerbos.checkResource');
test-cerbos-nestjs
08/28/2024, 8:38 AMoguzhan
cerbos
server is when you call the cerbos.checkResources()
function.
All cerbosCheck.isAllowed(action)
does is iterate over the response to find what is the result for the given action. (I wouldn’t expect it to be taking time at all, but still)test-cerbos-nestjs
08/28/2024, 8:50 AM