Skip to content

Support inverted tag matching in policy scope - #7176

Merged
nscuro merged 1 commit into
DependencyTrack:mainfrom
arjavdongaonkar:feat/policy-invert-tag-match
Aug 31, 2026
Merged

nscuro merged 1 commit into
DependencyTrack:mainfrom
arjavdongaonkar:feat/policy-invert-tag-match

Conversation

@arjavdongaonkar

Copy link
Copy Markdown
Contributor

Description

Policies can be limited to projects carrying specific tags, but there is no way to express the opposite, applying a policy to everything except projects with a given tag. Doing that today means tagging every project the policy should apply to and keeping that up to date as projects get added.

This adds an INVERT_TAG_MATCH flag on POLICY. When set, the policy applies to every project that does not share a tag with it.

Addressed Issue

Fixes #5042

Additional Details

The applicability query already selects policies through three branches, global policies with no restrictions, project restricted ones, and ones sharing a tag with the project. The existing tag branch now only picks up non-inverted policies, and inverted ones are selected by a separate branch.

Keeping them separate matters for one case. An inverted policy with no tags at all would otherwise match every project, which is not what someone setting up an exclusion would expect, so the inverted branch requires the policy to actually have tags.

This replaces #5041, which was raised against master before the v5 restructure. The frontend side is #1275 on the frontend repo, also against master, I will re-raise that against main once this is agreed.

Checklist

  • I have read and understand the contributing guidelines
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have updated the migration changelog accordingly
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

The documentation box is unchecked, the policy docs live in the docs repo. Will raise a PR there once this is agreed.

Policies can be restricted to projects carrying specific tags, but there is
no way to express the opposite, applying a policy to everything except
projects with a given tag. Doing that today means tagging every project the
policy should apply to, and keeping that up to date as projects are added.

Add an INVERT_TAG_MATCH flag to POLICY. When set, the policy applies to
every project that does not share a tag with it. The existing tag branch of
the applicability query is left to non-inverted policies, and inverted
policies are selected by a separate branch, so an inverted policy without
tags stays out of scope rather than silently applying everywhere.

Fixes DependencyTrack#5042

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>
@owasp-dt-bot

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codacy-production

codacy-production Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 1 medium

Results:
1 new issue

Category Results
Performance 1 medium

View in Codacy

🟢 Coverage 100.00% diff coverage · -0.01% coverage variation

Metric Results
Coverage variation ✅ -0.01% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage (70.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (33923d9) 44404 38791 87.36%
Head commit (df611d1) 44409 (+5) 38793 (+2) 87.35% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7176) 5 5 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@nscuro nscuro added this to the 5.2 milestone Aug 31, 2026
@nscuro nscuro added the enhancement New feature or request label Aug 31, 2026
@nscuro
nscuro merged commit a52a9c5 into DependencyTrack:main Aug 31, 2026
22 checks passed
nscuro pushed a commit to DependencyTrack/frontend that referenced this pull request Sep 2, 2026
* Add tag exclusion toggle to policy scope

DependencyTrack/dependency-track#7176 added invertTagMatch, which applies a
policy to every project that does not carry its tags. Expose it as a switch
next to the existing scope switches, and swap the tag list label so it is
clear whether the tags include or exclude.

Frontend side of DependencyTrack/dependency-track#5042.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Add tag exclusion translations for remaining locales

The i18n check requires every locale to carry the keys. ko, ru, uk-UA, zh-TW
and zh were added after the translations this change reused were written.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Trigger a policy update when the tag exclusion toggle changes

The other scope toggles each have a watcher calling updatePolicy, this one did
not, so flipping it changed nothing until some other field happened to trigger
a save.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

---------

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>
nissessenap pushed a commit to nissessenap/dt-frontend that referenced this pull request Oct 5, 2026
* Add tag exclusion toggle to policy scope

DependencyTrack/dependency-track#7176 added invertTagMatch, which applies a
policy to every project that does not carry its tags. Expose it as a switch
next to the existing scope switches, and swap the tag list label so it is
clear whether the tags include or exclude.

Frontend side of DependencyTrack/dependency-track#5042.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Add tag exclusion translations for remaining locales

The i18n check requires every locale to carry the keys. ko, ru, uk-UA, zh-TW
and zh were added after the translations this change reused were written.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Trigger a policy update when the tag exclusion toggle changes

The other scope toggles each have a watcher calling updatePolicy, this one did
not, so flipping it changed nothing until some other field happened to trigger
a save.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

---------

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Tag Exclusion in Policy Scope

3 participants