Artifact Firewall Ruleset

Artifact Firewall Ruleset format.

Example:

- id: GHSA-8vvx-qvq9-5948
  match:
    - purl: pkg:npm/flowise
      version: vers:npm/<=2.2.7
  severity: 10
  reason: Flowise allows arbitrary file write to RCE

id

Type: String

Unique identifier for the ruleset. Mandatory.

title

Type: String

Human-readable title for the ruleset. Informational only. Optional.

date

Type: String

Date the ruleset was authored. Informational only. Optional.

description

Type: String

Description of the ruleset’s purpose. Informational only. Optional.

virtual_registries

id: my-ruleset
virtual_registries:
- name: npm-internal
rules: []

Type: List

List of registries this ruleset applies to, each given by its name: a Virtual Registry’s registry, or one of a standalone firewall’s registries. When set, rules in this ruleset are only evaluated for requests routed through the listed registries. When empty, the ruleset applies to all registries.

rules

Type: List

List of rules to evaluate. Rules are evaluated in order of priority value (higher priority takes precedence).

id: my-ruleset
rules:
- id: block-lodash
  match:
  - type: npm
    name: lodash
  action: deny
  reason: Unapproved package

id

Type: String

Unique identifier for the rule within the ruleset. Mandatory.

aliases

rules:
- id: CVE-2021-44228
  aliases:
  - Log4Shell
  - GHSA-jfh8-c2jp-hdp

Type: List

Alternative identifiers for the rule, such as CVE IDs or advisory references. Informational only.

priority

rules:
- id: my-rule
  priority: 10

Type: Integer

Default: 1

Priority for this rule. A higher numerical value means higher priority, and if multiple rules match at the highest priority level, the strongest rule applies: deny > hide > allow.

The lowest priority a rule can hold is 1. Zero and negative values are raised to 1, since priority 0 is reserved for the default action, which therefore never outranks a rule that matched.

action

rules:
- id: my-rule
  action: deny

Type: String

Action to take when the rule matches. The value is read in any case, so DENY is the same as deny. Any other value makes the ruleset fail to load.

Options:

  • allow: Pass the request through.
  • hide: Remove version from “latest” consideration.
  • deny: Return a 403 response.

severity

rules:
- id: my-rule
  severity: 8.5

Type: Number

Severity score for the rule, between 0.0 and 10.0. Used to determine the effective action when action is not set:

  • At or above severity_deny_threshold (default 9): resolves to deny.
  • At or below severity_allow_threshold (default 4): resolves to allow.
  • Between the two thresholds: resolves to hide.

reason

rules:
- id: my-rule
  reason: Package has a known critical vulnerability

Type: String

Informational. Human-readable explanation for the rule’s action, returned by the admin API. Audit log entries name the rule but do not include its reason.

When the firewall is integrated with a Virtual Registry, the 403 for a download blocked by the rule carries the reason. A standalone firewall sends it only to conda and RPM clients. To the others, its 403 names the rule and its ruleset.

quarantine_days

rules:
- id: new-packages
  quarantine_days: 1

Type: Integer

Overrides default_quarantine_days from the firewall configuration for packages matched by this rule.

disabled

rules:
- id: my-rule
  disabled: true

Type: Boolean

Default: false

Load the rule but skip it during evaluation. A disabled rule matches nothing and contributes no action, which leaves a rule in place, with its reason and its history, without enforcing it.

A rule can also be disabled at runtime through the admin API, which is the way to suspend one without editing a ruleset that is fetched from git. The value here is what the rule returns to on restart.

match

rules:
- id: my-rule
  match:
  - type: npm
    name: lodash

Type: List

List of selectors that must match for the rule to apply. A package must match at least one selector in the list.

exclude

rules:
- id: my-rule
  match:
  - type: npm
  exclude:
  - name: trusted-package

Type: List

List of selectors that exempt a package from this rule. A package matching any exclude selector is not subject to the rule, even if it also matches a match selector.

Selectors

Selectors are used in both match and exclude lists. All specified fields within a selector must match (AND logic). Multiple selectors in a list are combined with OR logic.

purl

- purl: pkg:npm/example@1.2.3

Type: String

Match by Package URL (PURL). Package type and name are mandatory for PURLs, namespace and version are optional.

PURL only support exact versions. When a version range is needed, use the version field with VERS notation.

A PURL with a qualifier unsupported by its package type, such as pkg:maven/org.example/lib?classifier=sources, fails to load the ruleset. Only oci and docker support one, tag, as described under OCI images. Before Artifact Firewall 0.9.0 the qualifier was ignored, so that selector matched every artifact of lib.

Mutually exclusive with type and name, and with qualifiers.

type

- type: npm
  name: example

Type: String

Match by package ecosystem type (e.g. npm, pypi).

When type is used, name is also mandatory. Mutually exclusive with purl

namespace

- type: npm
  namespace: angular
  name: example

Type: String

Match by package namespace (e.g. the npm scope). Simple glob patterns are supported.

name

- type: npm
  name: example

Type: String

Match by package name. Simple glob patterns are supported.

NuGet names match in any case, as NuGet package IDs are case-insensitive, so Newtonsoft.Json also matches a request for newtonsoft.json. This holds for a name given in a purl too.

A VS Code extension is identified in lowercase, its publisher as the namespace and its extension ID as the name, whatever case the Marketplace shows: pkg:vscode-extension/github/copilot. A rule has to be written in lowercase too, and one naming GitHub matches nothing.

From 0.12.0, Cargo crate names match in any case too, as crates.io refuses a name that differs from another only in case, so Inflector also matches a request for inflector.

Names in every other ecosystem match case-sensitively.

When name is used, type is also mandatory. Mutually exclusive with purl

version

- purl: pkg:npm/example
  version: vers:npm/1.2.3|>=2.0.0|<5.0.0

Type: String

Match by package version or version range.

Version ranges are supported with VERS notation, as vers:<scheme>/ followed by constraints separated by |, such as vers:npm/>=1.0.0|<2.0.0, or vers:<scheme>/* for every version. Leave version out to match every version.

A malformed range, or a range written as an exact version, fails to load the ruleset. Where a single version is expected, as the whole of an exact version or after the comparator of each VERS constraint, percent-encoded or not, a version that starts with !, ^, ~, *, [ or (, or contains <, >, =, |, , or whitespace, fails. So do a VERS range with no constraint and a blank version. Whitespace around a version is ignored.

version: vers:npm/>=1.0<2.0      # fails: two constraints need a | between them
version: vers:pypi/>=1.0,<2.0    # fails: the separator is |, not a comma
version: ^1.2.3                  # fails: an exact version, not a caret range
version: vers:npm/>=1.0|<2.0     # loads

qualifiers

- type: oci
  namespace: library
  name: nginx
  qualifiers:
    tag: "1.25.*"

Type: Map

Match by PURL qualifiers, each value a glob. An unsupported qualifier fails to load the ruleset, and only oci and docker support one, tag.

Mutually exclusive with qualifiers in a purl.

OCI images

A rule for container images uses type: oci. The repository is split at its last / into namespace and name, so ghcr.io/myorg/team/app is pkg:oci/myorg/team/app and Docker Hub’s nginx is pkg:oci/library/nginx. The registry host is not part of it, so the rule applies on each registry unless its ruleset sets virtual_registries.

A digest is the version, and a tag is the tag qualifier, which takes a glob. A selector names a tag or a digest, not both, and a version that is not a digest fails to load the ruleset:

match:
- purl: pkg:oci/library/redis?tag=6.0.5
- purl: pkg:oci/library/busybox@sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
- type: oci
  namespace: library
  name: nginx
  qualifiers:
    tag: "1.25.*"

The PURL specification keeps the repository path of an oci image in a repository_url qualifier, unsupported in a rule, so a PURL copied from an SBOM fails to load.

A rule can also use the docker type, which is read as oci. Its version is a tag or a digest, it takes the tag qualifier as well, and a tag is a glob either way. An image without a namespace is under library, so pkg:docker/nginx@1.25.3 is pkg:oci/library/nginx?tag=1.25.3. A leading Docker Hub host, such as docker.io, index.docker.io or registry-1.docker.io, is dropped. Any other registry host, as in pkg:docker/gcr.io/distroless/static, fails to load the ruleset, because a request does not name its registry.

A digest is compared with the manifest digest of a pull by digest. An image ID is the digest of the image’s config, so a rule pinned to one matches no pull, and a short ID such as dc437cc87d10 is read as a tag.

Enforcement by package type describes which rules a pull meets.

Load errors

A ruleset that fails a check is refused as a whole, and none of its rules are loaded. The error names the ruleset, the rule and the field that failed:

ruleset "npm-policy": rule "block-leftpad": severity: 11.0 must be between 0 and 10

A field inside a selector is named by its position, such as match[0].version. An entry under rules: with nothing in it is reported by position as well, as rules[0]: rule is empty. A field the format does not know is refused too.

A ruleset refused at startup stops the firewall. One refused on a reload leaves the rulesets already loaded in force, and a reload through /api/update returns 502 with the error.

Validating rulesets

varnish-artifact-firewall -validate-rulesets runs the same checks without starting a firewall, for example in the CI of a ruleset repository. It takes ruleset files and directories as arguments, prints every problem rather than the first, and exits with status 1 if it found one, or found no ruleset file at all. A directory is read as a path source reads it: the files directly in it, not its subdirectories.

docker run --rm -v "$PWD/rulesets:/rulesets:ro" varnish/artifact-firewall \
  varnish-artifact-firewall -validate-rulesets /rulesets
/rulesets/lab.yaml: ruleset "lab-policy": rule "hold-is-number-7": action: "block" is not a known action
/rulesets/maven.yaml: ruleset "maven-policy": rule "no-sources": match[0].qualifiers.classifier: not supported for type "maven"
2 problems in 2 ruleset files

®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203