Can you help me understand the right way to solve this?
<context> I have a request that is actually a question because it might already exist..The Verve firewall is really useful but we need a better api for it, here are some use cases that would benefit a lot of projects and I’m not sure if they’re currently supported:
programmatically block IP addresses
programmatically block access or allow access to set of countries (whitelist or blacklist)
allow to programmatically set the different rules on specific paths of the project, so for example in this path ‘/tenant-1/* * / * ’ they would be able to block certain IPs and countries and on ‘/tenant-2/* * / *’ these IPs and countries wouldn’t be blocked and other IPs and countries might be blocked based on the tenants’ preferences in my app that is facing them and I will apply the rules programmatically on Vercel based on their selections
also path based human challenge like the above example
Basically I want to be able to set any and all available firewall rules and settings programmatically with the ability to set them only on certain paths of the app
u/lrobinson2011 This should be doable today, have you seen the Firewall API?
u/no-uname-idea avatar I was reading over it now and I can’t figure out how to only apply in a specific path the rules that I’m upsertting with the PUT endpoint..
So for example /tenant-1/…all-sub-paths… would have certain IPs blocked but /tenant-2/…all-sub-paths… would have different IPs blocked, all in the same multi-tenant project.. </context>
To address your question about applying different firewall rules to specific paths within a multi-tenant project, you can indeed use the Vercel Firewall API to achieve this. Here's how you can approach this using the available endpoints:
In this example, we've created two rules: one for /tenant-1/
and another for /tenant-2/
. Each rule specifies different IP addresses to block for the respective tenant paths.
Remember to handle authentication securely and not expose your Vercel API token in client-side code. Instead, create a server-side API in your application that handles the communication with the Vercel API.
This approach allows you to dynamically update firewall rules for different paths and tenants in your multi-tenant application. However, keep in mind that frequent updates to firewall rules may have performance implications, so it's best to batch updates when possible.
Is there any specific part of this process you'd like me to explain further?
I'll provide you with JavaScript fetch calls to interact with the Vercel Firewall API for the scenarios you described. These calls will allow you to programmatically update firewall rules for different tenants and paths.
Here are the JavaScript fetch calls to interact with the Vercel Firewall API:
firewall-api-calls.js
This script demonstrates how to:
To use this script:
Create a .env
file in the same directory as your script with the following content:
VERCEL_API_TOKEN=your_vercel_api_token
PROJECT_ID=your_project_id
your_vercel_api_token
with your actual Vercel API token and your_project_id
with your Vercel project ID.node firewall-api-calls.js
.This script provides a foundation for programmatically managing your Vercel Firewall rules. You can extend it to create more dynamic rules based on your application's needs, such as reading tenant preferences from a database and updating the rules accordingly.
Remember to handle these API calls securely, preferably on your server-side, to keep your Vercel API token confidential. Also, consider implementing rate limiting and error handling in a production environment to manage API usage and handle potential issues gracefully.
Is there anything specific about these API calls or the firewall configuration that you'd like me to explain further?
No Output
Run the code to generate an output.