I have recently added the --auth flag to make my instance of SurrealDB production ready as suggested in the documentation.
Upon doing so, my users can no longer view their data as this error is returned when authenticating with JWT tokens: {"code":403,"details":"Forbidden","description":"Not allowed to do this.","information":"There was a problem with the database: IAM error: Not enough permissions to perform this action"}
Removing the --auth flag allows this authentication, but this goes against the production ready recommendation.
SAMPLE JWT TOKEN CONTENT
{
"ns": "Test",
"db": "Test",
"sc": "account",
"tk": "user_tkn",
"id": "users:test_user",
"iat": 1703421361,
"exp": 1703424961
}
SAMPLE REQUEST
curl -X POST "https://database.com/sql" \
-H "Content-Type: text/plain" \
-H "Accept: application/json" \
-H "Token: <HS256 TOKEN HERE>" \
-H "NS: Test" \
-H "DB: Test" \
-H "SC: account" \
-d "SELECT * FROM users:⟨+44XXXXXXXXXX⟩"
For testing purposes, I have given PERMISSIONS FULL to the users table.
INFO FOR SCOPE
{
"tokens": {
"user_tkn": "DEFINE TOKEN user_tkn ON SCOPE account TYPE HS256 VALUE 'example123456'"
}
}
Additional Info
Start Command: surreal start --auth --deny-guests --no-banner
Protocol: HTTPS
SurrealDB Version: 1.0.2 for linux on x86_64
You are correct that the
--authargument is indeed very recommended for production deployments and it is not necessarily to remove it to solve your problem. Your issue happens because you are providing the token in theTokenheader, whereas you should provide it in theAuthorizationheader in the formatBearer $token. Assuming that the JWT is being constructed and signed correctly, this should solve your issue.Here is how I would reproduce what I understand is your intended use case:
surreal start --auth -u root -p root --deny-guests --no-banner. Remember to change the root credentials in your deployment.surreal sql -u root -p rootand run the following statements:example123456as the signature secret. Do not check the box to encode the secret. The token payload should contain the following:Following the instructions above, you should get the following response:
I hope this was helpful! Feel free to let me know if you need any other help.
PS: I work in SurrealDB.