A comprehensive Python toolset for managing NG WAF deployments on Fastly services, including provisioning, edge security object management, traffic ramping, backend synchronization, VCL upgrades, configuration updates, and Salt dashboard integration.
Before running any of the scripts, ensure the following are installed and set up:
- Python 3.x
- Requests library for Python (
pip3 install requests
) - Parsel library (
pip3 install parsel
) - Fastly API token and NGWAF token
- Cookie files:
.voltron_cookie
for Voltron access and.dashboard_cookie
for Salt Dashboard access.
To access Voltron for group management and certain NG WAF API calls, you need a .voltron_cookie
file with the full cookie value. Here’s how to set it up:
- Login to Voltron Dashboard: Open your browser, navigate to Voltron, and log in.
- Open Developer Tools: Right-click on the page, select "Inspect" (or press
F12
), and go to the Network tab. - Capture a cURL Request: Perform any action on the Voltron dashboard to trigger a request. Locate a Voltron request, right-click, and select "Copy as cURL."
- Extract the Cookie: From the copied cURL, find the
-H 'cookie: ...'
section, and copy the entire cookie string. - Create a
.voltron_cookie
File: In your project directory, create a.voltron_cookie
file that includes the cookie string.
Example .voltron_cookie
content:
_ga=GA1.2.184163117.1724087216; _gid=GA1.2.1553403690.1725903286; goth-session=MTcyNTk...
Similarly, for accessing the Salt dashboard, you need a .dashboard_cookie
file. Follow these steps:
- Login to Salt Dashboard: Open your browser, navigate to the Salt dashboard, and log in.
- Open Developer Tools: Right-click on the page, select "Inspect" (or press
F12
), and go to the Network tab. - Capture a cURL Request: Perform any action on the Salt dashboard to trigger a request. Locate a Salt dashboard request, right-click, and select "Copy as cURL."
- Extract the Cookie: From the copied cURL, find the
-H 'cookie: ...'
section, and copy the entire cookie string. - Create a
.dashboard_cookie
File: In your project directory, create a.dashboard_cookie
file that includes the cookie string.
Example .dashboard_cookie
content:
_ga=GA1.2.184163117.1724087216; _gid=GA1.2.1553403690.1725903286; session-token=xyz...
Both .voltron_cookie
and .dashboard_cookie
files are checked for expiration. If either file is older than one day, the user will be prompted to re-enter the cookie value to ensure up-to-date access.
The setup-env.zsh
script helps streamline setting up environment variables required by the scripts. Environment variables allow you to omit certain command-line arguments.
-
Make the script executable:
chmod +x setup-env.zsh
-
Run the script:
source setup-env.zsh --update-file
- The script will prompt you to enter values for
CORP_NAME
,NGWAF_TOKEN
, andFASTLY_TOKEN
. - If the
--update-file
flag is passed, it will also prompt forsite_name
andservice_id
and updatefile.csv
.
- The script will prompt you to enter values for
-
Reload the terminal environment: After running the script, reload your
.zshrc
:source ~/.zshrc
Once the environment variables are set, you can load them in future sessions using a custom function generated by the script:
setenv_<CORP_NAME>
Replace <CORP_NAME>
with the actual name you provided during the setup.
NGWAF_USER_EMAIL
: Your NG WAF user emailNGWAF_TOKEN
: NG WAF API tokenFASTLY_TOKEN
: Fastly API tokenCORP_NAME
: Your corporation nameSITE_NAME
: (Optional) Site name for individual operationsFASTLY_SID
: (Optional) Fastly Service ID for individual operations
These variables enable you to execute scripts without specifying all parameters on the command line.
The ngwafcli
toolset includes several scripts for managing NG WAF services on Fastly. Each script can be executed using command-line arguments for various functions, as described below.
This script handles core operations, including provisioning, edge security object management, adding corp groups, and backend synchronization.
python3 ngwafcli.py --csv_file file.csv --activate true --percent_enabled 100 --provision --dynamic-backend --premier
- Provisioning: Use
--provision
to create and map sites in Fastly. - Edge Security Management: Automatically creates an edge security object if not present.
- Traffic Control: Use
--percent_enabled
to control traffic routed to NG WAF. - Backend Synchronization: Use
--sync-backend
with a CSV file to synchronize origins. - Dynamic Backend and Premier Groups: Use
--dynamic-backend
to add tosigsci-edge-dynamic-backends
and--premier
to add to therate-limiting
group. - Retry Mechanism: Automatically retries API calls on network failures.
The upgrade-vcl-version.py
script updates the VCL version for NG WAF to the latest release. This ensures that your service benefits from the latest security and performance enhancements available for VCL.
python3 upgrade-vcl-version.py --ngwaf_user_email 'your_ngwaf_user_email' --ngwaf_token 'your_ngwaf_token' --fastly_token 'your_fastly_token' --corp_name 'your_corp_name'
The config-updater.py
script takes a .json
configuration file and applies it across multiple sites listed in file.csv
. This script is also useful for updating webhook site integrations and other configuration variables for each site.
python3 config-updater.py --config_file 'path/to/config.json' --csv_file 'path/to/file.csv' --ngwaf_user_email 'your_ngwaf_user_email' --ngwaf_token 'your_ngwaf_token' --fastly_token 'your_fastly_token' --corp_name 'your_corp_name'
- Config File: The JSON file should define any settings to be updated across sites, such as webhook URLs or integration variables.
- CSV File: The CSV file should contain
site_name
andfastly_sid
for each site to be updated.
The voltron.py
script manages adding corps to specific groups in NG WAF, such as sigsci-edge-dynamic-backends
or rate-limiting
. It uses the .voltron_cookie
file for authentication.
python3 voltron.py --corp 'your_corp_name' --action 'add' --groups 'sigsci-edge-dynamic-backends' 'rate-limiting'
All major scripts support batch processing using a CSV file containing site_name
and fastly_sid
columns.
Example CSV format:
site_name,fastly_sid
site1,serviceID1
site2,serviceID2
Use this format when specifying --csv_file
.
For additional guidance, please refer to the following walkthroughs:
- Project Walkthrough: https://www.loom.com/share/88977b2ac2d747fd89b842ece5ee06e3
- Batch Deployment Update: https://www.loom.com/share/5aa133387d1e4872be216b235b98941c
Sina Siar - @ssiar - [email protected]