Back

[Solved] best way to load and query a IP block list

  • 0
  • Databases
  • Functions
  • General
punti_z
7 Apr, 2023, 15:08

Not really an issue but looking for suggestions on the best way to deal with the below use case.

I am trying to implement an IP whitelist allowing users to restrict access to, say a corporate network. Working on this got me thinking about the best way of implementing something like this for a large list of IP's. I know Appwrite DB (MariaDB) has full text search so

  1. I can create a single document that as part of a String field maintains a delimited IP address list and a cloud function that would validate and allow or reject requests
  2. Have a collection with each IP as a document in an indexed field.
  3. Save a CSV in storage and have function pull the file, read and validate IP against it.

Not sure what would be the right way, if there is one best way, of implementing something like this. Open to other ideas.

TL;DR
The user is seeking suggestions for the best way to load and query an IP block list. One suggestion is to use `databases.getDocument()` for fast lookup of a single IP address. However, for a large list of IP addresses, it is recommended to use ranges, subnet masks, or CIDR notation instead. The user can find a library that accepts these values and checks against an IP. Based on the library requirements, they can determine the best storage method. The user also mentions three possible approaches: creating a single document with a delimited IP address list, having each IP as a document in a collection, or saving a CSV file in
Drake
7 Apr, 2023, 15:50

For the fastest lookup of a single IP (1.2.3.4), I would have a collection where the ID is the IP and use databases.getDocument() because databases.getDocument() fetches the document from cache (if available).

That said, for your use case, it's common to have ranges or even subnet masks or CIDR notation rather than a list of IP Addresses. If you're going this route, I would suggest finding a library that will accept the values and check against an IP. Then, you would figure out the best storage method based on what your library requires

punti_z
7 Apr, 2023, 19:36

[Solved] best way to load and query a IP block list

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more