Skip to content

Apply the JMX RBAC guard to MBean lifecycle operations - #2865

Merged
jbonofre merged 2 commits into
apache:mainfrom
jbonofre:jmx-rbac-guard-lifecycle-ops
Sep 11, 2026
Merged

Apply the JMX RBAC guard to MBean lifecycle operations#2865
jbonofre merged 2 commits into
apache:mainfrom
jbonofre:jmx-rbac-guard-lifecycle-ops

Conversation

@jbonofre

@jbonofre jbonofre commented Sep 8, 2026

Copy link
Copy Markdown
Member

Motivation

The KarafMBeanServerGuard (via MBeanInvocationHandler) only intercepts invoke, getAttribute(s) and setAttribute(s). The MBean lifecycle operations of MBeanServercreateMBean, registerMBean and unregisterMBean — are passed straight through to the delegate MBeanServer and are therefore not subject to any RBAC check, which is inconsistent with the rest of the guarded API exposed over the remote JMX connector.

Changes

  • MBeanInvocationHandler adds createMBean, registerMBean and unregisterMBean to the guarded operation list.
  • KarafMBeanServerGuard handles them through a new handleRegistration(...): required roles are resolved from the jmx.acl* configuration by ObjectName and operation name. The target MBean is not (or not yet) registered, so no MBeanInfo introspection is performed.
    • For createMBean / registerMBean the class name is passed as the operation argument, so ACL rules can match on it, e.g.
      createMBean(java.lang.String)[/javax\.management\.loading\..*/] = admin
      
    • A null ObjectName falls back to the generic jmx.acl configuration.
  • Default jmx.acl.cfg (standard feature + instance resources) gets explicit createMBean / registerMBean / unregisterMBean = admin entries. The existing * = admin fallback already covered them; the explicit entries make the policy visible and overridable.
  • KarafMBeanServerGuardTest gains coverage for the three operations (viewer denied / admin allowed, null ObjectName, and class-name matching).
  • monitoring.adoc updated.

Testing

mvn -pl management/server -am test -Dtest=KarafMBeanServerGuardTest

The KarafMBeanServerGuard only intercepted invoke, getAttribute(s) and
setAttribute(s). createMBean, registerMBean and unregisterMBean went
straight to the delegate MBeanServer, so they were not subject to any
role check and behaved inconsistently with the rest of the guarded API.

Route these three operations through the guard as well:

* MBeanInvocationHandler adds them to the guarded operation list.
* KarafMBeanServerGuard resolves the required roles from the jmx.acl*
  configuration by ObjectName and operation name (the target MBean is
  not, or not yet, registered so no MBeanInfo introspection is done).
  For createMBean/registerMBean the class name is passed as the
  operation argument so ACL rules can match on it, e.g.
  createMBean(java.lang.String)[/javax\.management\.loading\..*/] = admin
* A null ObjectName falls back to the generic jmx.acl configuration.
* The default jmx.acl.cfg maps createMBean/registerMBean/unregisterMBean
  to the admin role (the existing "* = admin" already covered them).
The ACL regex example in the handleRegistration Javadoc contained the
literal sequence */ (from \..*/]), which closed the block comment early
and broke compilation of org.apache.karaf.management.server. Escape the
trailing slash as &apache#47; so the comment terminates where intended.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017MZQYyrYzSQHdHeD6AEGXT
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Test Results

  705 files  ±0    705 suites  ±0   1h 19m 28s ⏱️ + 1m 41s
  949 tests +3    901 ✅ +3   48 💤 ±0  0 ❌ ±0 
2 847 runs  +9  2 703 ✅ +9  144 💤 ±0  0 ❌ ±0 

Results for commit 78bbd6b. ± Comparison against base commit 6e40475.

@jbonofre
jbonofre merged commit f14236a into apache:main Sep 11, 2026
7 checks passed
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