parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

The option "masterKeyIps" cannot be disabled

Open alljinx opened this issue 3 years ago • 61 comments

New Issue Checklist

Issue Description

Parse-server 6.0.0 allow to restrict IPs than can use the MasterKey using the option "masterKeyIps". The documentation says "Setting ['0.0.0.0/0'] means disabling the filter and the master key can be used from any IP address". In fact, even localhost is blocked.

Steps to reproduce

Juste install and configure Parse-Server v6 with the last Parse-Dashboard on your local machine. Try to launch without the "masterKeyIps" option. Parse dashboard should works well. Try with masterKeyIps: ['0.0.0.0/0'], after login, Parse Dashboard should display "Server not reachable: unauthorized: master key is required" and the node console should display "error: Request using master key rejected as the request IP address '::1' is not set in Parse Server option 'masterKeyIps'."

Actual Outcome

MasterKey is not usable anywhere with masterKeyIps: ['0.0.0.0/0']

Expected Outcome

MasterKey should be usable everywhere with masterKeyIps: ['0.0.0.0/0']

Environment

parse-server 6.0.0 parse-dashboard 5.0.0

Server

  • Parse Server version: 6.0.0
  • Operating system: Windows 10
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): Postgres
  • Database version: 15
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): JS
  • SDK version: 4.0.0

Logs

error: Request using master key rejected as the request IP address '::1' is not set in Parse Server option 'masterKeyIps'. Error: unauthorized: master key is required at handler (C:\GitProjects\jdm\node_modules\parse-server\src\middlewares.js:459:19) at C:\GitProjects\jdm\node_modules\parse-server\src\PromiseRouter.js:72:20 at processTicksAndRejections (node:internal/process/task_queues:95:5)

alljinx avatar Feb 03 '23 11:02 alljinx

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

parse-github-assistant avatar Feb 03 '23 11:02 parse-github-assistant

I guess you'd need to specify IPv6 ranges separately. Could you try to set masterKeyIps: ['::/0']? In theory you should be able to set masterKeyIps: ['0.0.0.0/0', '::/0'], but I'm not sure the features supports a mix of IPv4 and IPv6.

mtrezza avatar Feb 03 '23 19:02 mtrezza

@alljinx Were you able to resolve this issue?

mtrezza avatar Mar 01 '23 08:03 mtrezza

Oh sorry, forgot this topic. I was able to make it work using masterKeyIps: ['0.0.0.0/0', '::1']. So there is no bug and I can indeed close this issue. Maybe we should just update the documentation to add the IPv6. Thx !

alljinx avatar Mar 01 '23 08:03 alljinx

Thanks for reporting back. I reopened to find out where this is actually a bug or only a docs issue.

There should be 2 working solutions for the issue you described:

  • a) ['::1'] which is the IPv6 notation for localhost
  • b) ['::/0'] which allows any IPv6 address.
  • c) ['::'] which allows any IPv6 address, just a different notation from (b) with range omitted.

It seems you already verified that (a) works. Could you also verify (b), (c)?

mtrezza avatar Mar 01 '23 08:03 mtrezza

@mtrezza My original error was '::ffff:192.168.0.156' is not set in Parse Server option...

I was hosting the parse server on a LAN.

Adding masterKeyIps: ['::/0'] did not work for me. Adding masterKeyIps: ['0.0.0.0/0'] fixed it.

chillaxdev avatar Mar 04 '23 17:03 chillaxdev

Thanks, that's strange. It reports an IPv6 address to not be allow-listed, but then it required an IPv4 CIDR range to allow-list it.

If you don't mind trying it out:

  • Does masterKeyIps: ['::'] work?
  • Does masterKeyIps: ['::ffff:192.168.0.156'] work, or whatever is the IPv6 address that is logged in the server logs?

mtrezza avatar Mar 04 '23 23:03 mtrezza

'::' does not work. '::ffff:192.168.0.156' works.

Also, this is my serverURL: http://192.168.0.156:1337/parse

Server is running on Windows 10 x86_64 Pro.

For testing the API, I used the postman client locally to send a request with X-Parse-Master-Key set in the header.

chillaxdev avatar Mar 05 '23 08:03 chillaxdev

I'll leave this issue open as there seems to be a bug in the parsing of IP addresses in masterKeyIps.

mtrezza avatar Mar 05 '23 10:03 mtrezza

Hi!

I try to use parse-server 6.0.0 in docker, but have the same problem: Request using master key rejected as the request IP address '172.21.0.1' is not set in Parse Server option 'masterKeyIps'

which I can't resolve by adding maintenanceKeyIps: ['172.21.0.1'] to config.

Any other ideas?

VKlapan avatar Mar 20 '23 16:03 VKlapan

@VKlapan masterKey and maintenanceKey are not the same.

mtrezza avatar Mar 20 '23 22:03 mtrezza

@VKlapan masterKey and maintenanceKey are not the same.

Sorry, it is my misprint - of course, I had used masterKeyIps: [], but without effect. So, I need any help yet.

VKlapan avatar Mar 21 '23 09:03 VKlapan

Could you copy/paste the log entry and the respective config you've set for Parse Server? Just to make sure.

mtrezza avatar Mar 23 '23 09:03 mtrezza

Could you copy/paste the log entry and the respective config you've set for Parse Server? Just to make sure.

Useful hint! I have to check more carefully if a correct config are using, because a server works in docker container

VKlapan avatar Mar 23 '23 13:03 VKlapan

I understand that your issue has been resolved; we'll still keep this issue open since the OP issue still seems to exist.

mtrezza avatar Mar 23 '23 17:03 mtrezza

Do you mean we can close the issue?

Yes! Thanks. All is ok

VKlapan avatar Mar 23 '23 18:03 VKlapan

@mtrezza what would be the fix here? Is the issue with the package ip-range-check?

dblythy avatar Mar 29 '23 23:03 dblythy

It could be that the package doesn't interpret IPv6 ranges properly.

https://github.com/parse-community/parse-server/issues/8421#issuecomment-1454808608 shows the log error mentions ::ffff:192.168.0.156, an IPv6 address. Adding that exact address works, but the IPv6 ranges should also work.

  • Adding that exact IPv6 address to the options works.
  • Adding '0.0.0.0/0' fixed it for the OP, which is expected, as IPv4 and IPv6 should be usable interchangeably for this "allow all" IP address.
  • Adding ::/0 should work but doesn't.
  • Adding :: should (maybe) work but doesn't.
  • Not sure if adding ::1 should work as well, it's the IPv6 notation for "localhost", but we haven no evidence that ::ffff:192.168.0.156 is in fact localhost.

mtrezza avatar Apr 02 '23 15:04 mtrezza

@mtrezza ::ffff:192.168.0.156 is a localhost on my scenario as I ran the postman client on the same machine where the parse server is running.

chillaxdev avatar Apr 02 '23 16:04 chillaxdev

I'm using dockers for dashboard and server, I tried to change this value with those you give here. Set the env variable PARSE_SERVER_MASTER_KEY_IPS:

  • in docker-compose file of dashboard app: any effect (maybe normal)
  • in docker file of server app : error, indicate that the value that I put is not an IP adress. (I tried array, single IP but it doesn't work).
  • I finally change the value in the code. work following what you indicate here.

Artnforces avatar Apr 07 '23 02:04 Artnforces