Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort out WAF baseline on public LBs #1588

Merged
merged 3 commits into from May 12, 2022
Merged

Sort out WAF baseline on public LBs #1588

merged 3 commits into from May 12, 2022

Conversation

sihugh
Copy link
Contributor

@sihugh sihugh commented May 11, 2022

This PR has three sections:

  • converting the existing "classic" WAF to WAFv2 and applying it to the public cache LB as an example
  • converting the other LBs that use the existing WAF to use the new WAF (and removing the old one)
  • adding the new WAF to the public LBs that did not have anything applied

This is a stepping stone to make it easier to configure specific WAF configurations to each LB that needs it. The next step is to configure separate WebACLs for each LB that needs different configuration.

There is further context in each commit.

https://trello.com/c/IvZrVCL3/2869-setting-rate-limits-within-aws-waf

Copy link
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 I've suggested a couple of tweaks to make the commit messages slightly more useful.

We want to add some other WAFs to this configuration, so start by updating
the existing one to the latest version.

This rule is used by Smokey to verify that a WAF is applied. My approach
will be to build more comprehensive WAFs for each public end point, and
include this rule in each of the new web ACLs. This will allow us to continue
to check that WAFs are applied.

The classic WAF's name had become a bit misleading after a bit, because although
it's called `CachePublicWebACL` it's now also applied to a bunch of other things that
are nothing to do with the cache LB.

You have to assign a capacity to `aws_wafv2_rule_group`s which is calculated
by adding up all the elements you use from [the rules statement list](https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-statements-list.html).
It's not super easy to figure out, but it allows users of your rule group
to ensure that their [rules come in under the maximum capacity](https://docs.aws.amazon.com/waf/latest/developerguide/how-aws-waf-works.html#aws-waf-capacity-units).

It's possible to modify rule groups, however the capacity is immutable because
consumers rely on it to be able to remain within limits. I've therefore set the
capacity at a bit more than it's using, so we can have some flexibility.

We're going to reuse the existing log stream, as it seems fit for purpose.
There's a [lambda that filters out logs](https://github.com/alphagov/govuk-aws/blob/main/terraform/lambda/WAFLogTrimmer/lambda.js)
that are generated by the `Default_Action`
(as these are requests that don't match any rule and will not be interesting).
This field is still good for [current WAF logs](https://docs.aws.amazon.com/waf/latest/developerguide/logging-fields.html),
so we'll continue to use this method.

I've only moved the public cache LB over to the new web ACL for now, but
will do the others soon.
In the previous commit we built a copy of the existing WAF using the newer
option in AWS - WAFv2.

In this commit, we migrate the remaining load balancers from the old version
to the new version and delete the old configuration.

The next step will be to build separate rule groups for the differing needs
of each load balancer and apply them individually. It's easier to do this
once we've moved everything over to the new version.

There is still a [Smokey check to check that a firewall](https://github.com/alphagov/smokey/blob/main/features/waf.feature)
using this rule exists and this still passes.
Many of these have other ACLs applied in front of them, however it's useful
to start by applying basic configuration, as it's then easier to iterate.
@sihugh sihugh merged commit b7bb7a1 into main May 12, 2022
@sihugh sihugh deleted the waf-baseline branch May 12, 2022 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants