Skip to content

[4.4.x] Apply the JMX RBAC guard to MBean lifecycle operations - #2866

Merged
jbonofre merged 2 commits into
apache:karaf-4.4.xfrom
jbonofre:backport-2865-karaf-4.4.x
Sep 11, 2026
Merged

[4.4.x] Apply the JMX RBAC guard to MBean lifecycle operations#2866
jbonofre merged 2 commits into
apache:karaf-4.4.xfrom
jbonofre:backport-2865-karaf-4.4.x

Conversation

@jbonofre

@jbonofre jbonofre commented Sep 8, 2026

Copy link
Copy Markdown
Member

Backport of #2865 to karaf-4.4.x.

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

Cherry-picked from the main commit; one trivial conflict resolved (canBypassRBAC is not static on 4.4.x).

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).

(cherry picked from commit 87c1426)
@jbonofre
jbonofre force-pushed the backport-2865-karaf-4.4.x branch from 558dae1 to ac353f2 Compare September 8, 2026 17:42
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

  656 files  ±0    656 suites  ±0   1h 6m 10s ⏱️ + 5m 8s
1 009 tests +3    966 ✅ +3   43 💤 ±0  0 ❌ ±0 
2 759 runs  +9  2 639 ✅ +9  120 💤 ±0  0 ❌ ±0 

Results for commit 96ba904. ± Comparison against base commit 2880f87.

@jbonofre
jbonofre merged commit 6c8c156 into apache:karaf-4.4.x 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.

1 participant