hasura / hasura/graphql-engine

x-hasura-role and x-hasura-user-id is passed to Hasura as remote schema making permission mixed up

Open
#8,040 1 comment 0 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: 2.1.1
CLI Version (for CLI related issue): 2.1.1

### Environment

OSS

I connect 2 hasura instances together, `Service` is added to `Gateway` via Remote Schema. When executing queries with JWT Authorization on `Gateway`, the `x-hasura-role` and `x-hasura-user-id` is passed to Service quite unintentionally making the `Service` returns the hasura's no permission error: `field \"extract_paper\" not found in type: 'query_root'`.

This is unexpected because the `Service` is configured with `Forward all headers from client` **unchecked**. As a workaround I have to configure permissions for the role in `x-hasura-role` session on `Service` which it isn't aware of such role.

Request Logs on `Gateway`

```
{"type":"http-log","timestamp":"2022-01-18T06:44:23.483+0000","level":"info","detail":{"operation":{"query_execution_time":6.19696e-3,"user_vars":{"x-hasura-role":"seller","x-hasura-user-id":"140"},"request_id":"168eff73-e06c-46df-8848-e6d21f3088ed","response_size":82,"query":{"variables":{"payload":{"s3_key":"cavet-1.jpeg","paper_type":"MotorbikeRegistration","s3_bucket":"papaya-document-validation"}},"query":"mutation($payload: jsonb) {\n extract_paper(payload: $payload)\n}"},"request_mode":"single","request_read_time":2.59e-6},"request_id":"168eff73-e06c-46df-8848-e6d21f3088ed","http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"118.69.77.148","method":"POST","content_encoding":"gzip"}}}
```

Logs on `Service`, notice `x-hasura-role` and `x-hasura-user-id` is the same as `Gateway`

```
{"type":"http-log","timestamp":"2022-01-18T06:44:23.496+0000","level":"info","detail":{"operation":{"query_execution_time":2.112049e-3,"user_vars":{"x-hasura-role":"seller","x-hasura-user-id":"140"},"request_id":"187d5ac0-c56b-47d6-a221-0ecd91a34c8e","response_size":82,"query":{"variables":{"hasura_json_var_1":{"s3_key":"cavet-1.jpeg","paper_type":"MotorbikeRegistration","s3_bucket":"papaya-document-validation"}},"query":"mutation ($hasura_json_var_1: jsonb) { extract_paper(payload: $hasura_json_var_1) }"},"request_mode":"single","request_read_time":2.34e-6},"request_id":"187d5ac0-c56b-47d6-a221-0ecd91a34c8e","http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"54.179.173.119","method":"POST","content_encoding":"gzip"}}}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the two-instance Gateway-to-Service Remote Schema request described for version 2.1.1, with “Forward all headers from client” unchecked, and compare the Gateway and Service request logs. Focus on whether x-hasura-role and x-hasura-user-id are forwarded; done means the Service does not receive those headers in this configuration and the mutation succeeds without adding the Gateway role to Service permissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.