7. Policy as code
Test case 6: a firewall policy change is a file in a pull request, deployed to both regions.
What you will see
-
The policies in Terraform and the blocked-sites directory.
-
One new file that blocks a site, through review and deployment.
-
The block from your demo instance, and the web filter log on FortiAnalyzer.
7.1 Where the policies are
-
In the repository, open
fortinet/eu-west-1/:policy.tfholds the dynamic addresses and the tag policies,webfilter.tfthe web filter and certificate inspection,onboarding.tfthe policy packages. Both regions use these files. -
Open
config/blocked-sites/: one YAML file per blocked site. The files feed one static URL filter on the North-South policies, with certificate inspection: the FortiGate matches the TLS server name, and the client needs no extra CA.
7.2 Block a site
Each attendee blocks a different site.
| Attendee | File | Content |
|---|---|---|
| eu-west-1 | config/blocked-sites/chatgpt.yaml |
url: "*chatgpt.com" |
| ap-southeast-1 | config/blocked-sites/gemini.yaml |
url: "*gemini.google.com" |
-
In CloudShell, make sure your PROD instance may reach the internet:
aws ec2 create-tags --resources $PROD_ID --tags Key=Allow-To-Internet,Value=true -
In the PROD session, try both sites before the change:
curl -s -o /dev/null -m 5 -w '%{http_code}\n' https://chatgpt.com curl -s -o /dev/null -m 5 -w '%{http_code}\n' https://gemini.google.comBoth answer.
-
On your laptop, in the clone, add your file on a new branch.
Attendee 1 (eu-west-1):
git switch main && git pull git switch -c block/chatgpt printf 'url: "*chatgpt.com"\n' > config/blocked-sites/chatgpt.yaml git add config/blocked-sites/chatgpt.yaml git commit -m "feat: block chatgpt.com" git push -u origin block/chatgptAttendee 2 (ap-southeast-1):
git switch main && git pull git switch -c block/gemini printf 'url: "*gemini.google.com"\n' > config/blocked-sites/gemini.yaml git add config/blocked-sites/gemini.yaml git commit -m "feat: block gemini.google.com" git push -u origin block/gemini -
Open the link that
git pushprints and create the pull request. -
On the pull request, read the plan comment: the URL filter gains one entry, in each region.
-
After approval and merge, open Actions and follow the
deploy.ymlrun: each region's fortinet apply installs the change on its members.
7.3 Verify the block
-
In the PROD session, once the deployment has finished, try both sites again:
curl -s -o /dev/null -m 5 -w '%{http_code}\n' https://chatgpt.com curl -s -o /dev/null -m 5 -w '%{http_code}\n' https://gemini.google.comYour site fails. Once the other attendee's change is in, theirs fails too, in your region.
-
To read the block page, add
-k; the page is not served with the site's certificate:Attendee 1:
curl -sk https://chatgpt.com | head -20Attendee 2:
curl -sk https://gemini.google.com | head -20 -
Another host of the same provider still opens:
curl -s -o /dev/null -m 5 -w '%{http_code}\n' https://www.google.com -
On FortiAnalyzer, Log View, FortiGate, Web Filter: the blocked request.
-
On FortiManager, Policy & Objects, Object Configurations, Security Profiles: the web filter profile
<prefix>-block-sitesuses the URL filter<prefix>-blocked-sites, which lists the entry.
Check
-
One file in one pull request blocked a site in both regions.
-
The other attendee's block works in your region.
Limits
-
The filter matches the TLS server name. A site reached by another name, or through a proxy that hides the name, is not matched.
-
QUIC is blocked on the North-South policies, so browsers fall back to TCP, where the filter applies.
-
Both regions share the same policy packages. Production would separate stages and environments.
Where to look
| What | Where |
|---|---|
| Blocked sites | config/blocked-sites/ |
| Policy code | fortinet/eu-west-1/policy.tf, webfilter.tf |
| Deployment | GitHub, Actions, deploy.yml |
| Blocks | FortiAnalyzer, Log View, FortiGate, Web Filter |