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

7.1 Where the policies are

  1. In the repository, open fortinet/eu-west-1/: policy.tf holds the dynamic addresses and the tag policies, webfilter.tf the web filter and certificate inspection, onboarding.tf the policy packages. Both regions use these files.

  2. 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"
  1. 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
    
  2. 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.com
    

    Both answer.

  3. 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/chatgpt
    

    Attendee 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
    
  4. Open the link that git push prints and create the pull request.

  5. On the pull request, read the plan comment: the URL filter gains one entry, in each region.

  6. After approval and merge, open Actions and follow the deploy.yml run: each region's fortinet apply installs the change on its members.

7.3 Verify the block

  1. 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.com
    

    Your site fails. Once the other attendee's change is in, theirs fails too, in your region.

  2. 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 -20
    

    Attendee 2:

    curl -sk https://gemini.google.com | head -20
    
  3. Another host of the same provider still opens:

    curl -s -o /dev/null -m 5 -w '%{http_code}\n' https://www.google.com
    
  4. On FortiAnalyzer, Log View, FortiGate, Web Filter: the blocked request.

  5. On FortiManager, Policy & Objects, Object Configurations, Security Profiles: the web filter profile <prefix>-block-sites uses the URL filter <prefix>-blocked-sites, which lists the entry.

Check

Limits

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
← 6. Scaling8. Upgrade →