Skip to content

ARTEMIS-6042 Improve ArtemisMBeanServerGuard.canInvoke implementation - #6946

Open
jbertram wants to merge 16 commits into
apache:mainfrom
jbertram:ARTEMIS-6042
Open

jbertram wants to merge 16 commits into
apache:mainfrom
jbertram:ARTEMIS-6042

Conversation

@jbertram

Copy link
Copy Markdown
Contributor

Rather than continuing to go back and forth on #6403 I decided to make the modifications I think are necessary to get this merged and send my own PR. This is an exceptional circumstance because (to my knowledge) we've never had a PR with this many individual commits.

All commits retain @GChuf as author. I rebased onto current main and folded fixes into the commits that introduced each issue.

Changes relative to #6403

  • Allow list cache moved from the guard into JMXAccessControlList and invalidated from addToAllowList. In the guard it was stale both when an allow list entry was added after first use and when setJMXAccessControlList swapped the whole list out. Invalidation is invalidateAll() rather than per-domain because isInAllowList falls back to the * domain, so a single new entry can change the answer for object names in every other domain.
  • Dropped userRolesCache. Keyed on Subject identity, it snapshotted a mutable Subject, so principals added after the first authorization call were invisible for that subject's lifetime. It bought no measurable throughput gain, only a small gain for allocation.
  • Preserved regex semantics for ACL keys. An access key is compiled and evaluated as a regex against the whole name=value string, so ., +, (, | and friends are live metacharacters. The bucketing split rules into exact matches vs regexes using an ad-hoc */?/[ test, which silently turned the rest into literals: key="address=foo.bar" stopped matching address=fooXbar. A rule now only takes the exact-match path when its key contains no regex metacharacter at all.
  • Same fix applied to prefix routing. A rule is only bucketed under a literal property name when the part before the = is itself a literal. Otherwise it may match more than one property name and goes to the wildcard bucket. Without this, key="ty.e=bar" would be bucketed under the literal name ty.e and never match anything.
  • objectNameCache is now an instance field rather than static, so it no longer outlives the broker that created it.
  • Removed the stray blank lines flagged in the review of ARTEMIS-6042 Improve ArtemisMBeanServerGuard.canInvoke implementation #6403, renamed defaultRoleClass to DEFAULT_ROLE_CLASS, and dropped the unused AccessEntry.rawPattern record component.
  • ArtemisMBeanServerGuard#currentUserHasRole is removed. It was public static but had no callers once canInvoke and handleInvoke both moved to the set-based path.
  • Seven total new tests in JMXAccessControlListTest and ArtemisMBeanServerGuardTest.
    • Allow list entry added after a lookup is honored, including when it is added under the * domain and affects object names in another domain
    • Regex metacharacters in an access key keep regex semantics (., (a|b), +), and a purely literal key still matches exactly
    • A regex metacharacter other than * in the key name portion still matches

GChuf and others added 16 commits November 25, 2026 08:25
Cover the case where a logged-in user's principal name happens to
collide with an unrelated configured role name, and the case where a
role is configured as a fully-qualified "class:name" principal
reference.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
isInAllowList is called on every guarded MBean operation and walks the
allow list rules each time. Cache the result per ObjectName.

The cache lives in JMXAccessControlList rather than in the guard so it
sits next to the state it derives from and can be invalidated by the
only mutator of that state, addToAllowList. Keeping it in the guard
would leave it stale both when a new allow list entry is added and when
setJMXAccessControlList swaps the whole list out.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Group a domain's access rules by the literal property name they apply
to, so a lookup only evaluates the rules that can possibly match
instead of walking every rule for every property of the ObjectName.

Rules whose key is a plain literal go into an exact-match map. A key
only counts as a literal when it holds no regex metacharacter at all:
the key is otherwise compiled and evaluated as a regex against the
whole "name=value" string, and bucketing must not quietly turn a
metacharacter such as '.' into a literal.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A rule can only be bucketed under a literal property name when the part
before the equal sign is itself a literal. Keys such as "*", "*=bar" or
"ty.e=bar" may match more than one property name, so they go into the
wildcard bucket and are tried against every property.

The wildcard bucket is merged into each property bucket and re-sorted
with the same comparator used elsewhere, so rules competing across
buckets keep the longest-match-wins priority they have without
bucketing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The bucketed domain cache was built on the first lookup and never
invalidated, so a role access key added for a domain afterwards was
silently ignored. Invalidate the domain's cache entry whenever a new
key is added. Updates to existing keys mutate the cached Access
objects in place and need no invalidation.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GChuf

GChuf commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@jbertram thanks!
If memory serves me right userRolesCache really didn't bring much, like you said. So I think that's a good call.
I ran your Allow list cache comments through Claude, it confirmed your scenarios about the cache becoming stale.

I was checking the regex code and - like you said:

A key is only safe to match by string equality when it has no regex metacharacters at all.

... there is the potential issue of key="address=foo.bar" matching the address fooxbar, though - unrelated to this PR.

I ran the JMH tests again on your branch just to make sure the numbers are still good. Same machine/same JVM as before.
There are some performance regressions (max 10-15% for throughput) but everything's still much better than on main.

LGTM.

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.

2 participants