Page MenuHomePhabricator

Ability for the code to apply different sets of rules depending on request
Closed, ResolvedPublic

Description

We want to apply different rules to different classes of traffic.

At the very least, we'll have:

  • HAProxy
    • General rules for non-trusted traffic
    • Rules for known clients
    • Moat-mode rules
  • Varnish
    • General rules for non-trusted traffic (both cache hit and misses)
    • Rules for known clients (both cache hit and misses)
    • Rules for known clients
    • Moat-mode rules

The easiest way to do this is to use the same strategy we've used for cache hits and misses:

  • Create a dsl object for each group of objects. We need to figure out how many will be dc-dependent
  • Add tags to haproxy/varnish actions, but not in the conftool sense of tags, but rather "where should this rule be applied", and we might have cases where we want to have more than a single tag.

Current status (2025-07-16):

Event Timeline

Joe triaged this task as High priority.Jul 15 2025, 6:45 AM

In order to do what we want, we will need to modify the action and haproxy_action schemas removing fields; that is currently not supported in conftool for simplicity, but I don't think we want to create bespoke migration scripts each time.

Change #1169621 had a related patch set uploaded (by Vgutierrez; author: Vgutierrez):

[operations/puppet@production] cache::haproxy: Provide X-Trusted-Request score

https://gerrit.wikimedia.org/r/1169621

Change #1169664 had a related patch set uploaded (by Vgutierrez; author: Vgutierrez):

[operations/puppet@production] varnish: Apply requestctl rules based on X-Trusted-Request

https://gerrit.wikimedia.org/r/1169664

Change #1169621 merged by Vgutierrez:

[operations/puppet@production] cache::haproxy: Provide X-Trusted-Request score

https://gerrit.wikimedia.org/r/1169621

Change #1170093 had a related patch set uploaded (by Vgutierrez; author: Vgutierrez):

[operations/puppet@production] cache::haproxy: Fix typo

https://gerrit.wikimedia.org/r/1170093

Change #1170093 merged by Vgutierrez:

[operations/puppet@production] cache::haproxy: Fix typo

https://gerrit.wikimedia.org/r/1170093

Change #1169664 merged by Vgutierrez:

[operations/puppet@production] varnish: Apply requestctl rules based on X-Trusted-Request

https://gerrit.wikimedia.org/r/1169664

Change #1170141 had a related patch set uploaded (by Vgutierrez; author: Vgutierrez):

[operations/puppet@production] cache::haproxy: Use trusted_request on silent-drops and bwlimits

https://gerrit.wikimedia.org/r/1170141

Change #1170141 merged by Vgutierrez:

[operations/puppet@production] cache::haproxy: Use trusted_request on silent-drops and bwlimits

https://gerrit.wikimedia.org/r/1170141

I will merge the change today. It involves a rather delicate schema change for both action types. The procedure I will follow is as follows:

  • Create a dump of the current state of requestctl on a puppetserver

sudo requestctl dump -f requestctl-data-YYYYMMDD-HH:MM.yaml

  • Warn everyone not to touch anything while we perform the schema change
  • Deploy the new version of the code; from a cumin server

sudo cookbook sre.deploy.hiddenparma -r 'Introduce selectors'

  • Run a schema upgrade; from alert1002:
# Upgrade pip, this will need to be added to the deploy commands in the future
sudo -u deploy-hiddenparma /srv/deployment/hiddenparma/venv/bin/pip install --upgrade pip
pushd /srv/deployment/hiddenparma/current/src
sudo -u deploy-hiddenparma /srv/deployment/hiddenparma/venv/bin/pip install -e .
sudo /srv/deployment/hiddenparma/venv/bin/requestctl-admin upgrade-schema --translate-fields scripts/migrate-site-to-selectors.yaml
popd
  • Ensure there are no commit differences
  • Finish the deployment and tell everyone they can edit again

In case we need a rollback: I think the best solution is to first rollback the code to the previous version via a deployment, then to run, from the puppetserver where we saved the backup:

sudo requestctl load -f requestctl-data-YYYYMMDD-HH:MM.yaml

If we want to be super certain, we can also run with --reset.

I have just tested the procedure by importing a dump of production data into my dev environment.

It works and results in zero committable differences.

I will proceed with the rollout at 08:00Z today.

Change #1173880 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/software/hiddenparma/deploy@main] Introduce selectors

https://gerrit.wikimedia.org/r/1173880

Change #1173880 merged by Giuseppe Lavagetto:

[operations/software/hiddenparma/deploy@main] Introduce selectors

https://gerrit.wikimedia.org/r/1173880

Change #1173889 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/software/hiddenparma/deploy@main] deploy: install the code so that cli scripts are available

https://gerrit.wikimedia.org/r/1173889

Change #1173889 merged by Giuseppe Lavagetto:

[operations/software/hiddenparma/deploy@main] deploy: install the code so that cli scripts are available

https://gerrit.wikimedia.org/r/1173889

I actually resolved the task by mistake: there's still some work to do on the varnish/haproxy side.

Change #1175841 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] varnish: refactor inclusion of requestctl rules

https://gerrit.wikimedia.org/r/1175841

Change #1179247 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] haproxy: allow having multiple requestctl scopes

https://gerrit.wikimedia.org/r/1179247

Change #1175841 merged by Giuseppe Lavagetto:

[operations/puppet@production] varnish: refactor inclusion of requestctl rules

https://gerrit.wikimedia.org/r/1175841

Change #1179247 merged by Giuseppe Lavagetto:

[operations/puppet@production] haproxy: allow having multiple requestctl scopes

https://gerrit.wikimedia.org/r/1179247