[4.4.x] Apply the JMX RBAC guard to MBean lifecycle operations - #2866
Merged
Conversation
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
force-pushed
the
backport-2865-karaf-4.4.x
branch
from
September 8, 2026 17:42
558dae1 to
ac353f2
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #2865 to
karaf-4.4.x.Motivation
The
KarafMBeanServerGuard(viaMBeanInvocationHandler) only interceptsinvoke,getAttribute(s)andsetAttribute(s). The MBean lifecycle operations ofMBeanServer—createMBean,registerMBeanandunregisterMBean— are passed straight through to the delegateMBeanServerand 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
MBeanInvocationHandleraddscreateMBean,registerMBeanandunregisterMBeanto the guarded operation list.KarafMBeanServerGuardhandles them through a newhandleRegistration(...): required roles are resolved from thejmx.acl*configuration byObjectNameand operation name. The target MBean is not (or not yet) registered, so noMBeanInfointrospection is performed.createMBean/registerMBeanthe class name is passed as the operation argument, so ACL rules can match on it, e.g.nullObjectNamefalls back to the genericjmx.aclconfiguration.jmx.acl.cfg(standard feature +instanceresources) gets explicitcreateMBean/registerMBean/unregisterMBean= adminentries. The existing* = adminfallback already covered them; the explicit entries make the policy visible and overridable.KarafMBeanServerGuardTestgains coverage for the three operations (viewer denied / admin allowed,nullObjectName, and class-name matching).monitoring.adocupdated.Testing
Cherry-picked from the
maincommit; one trivial conflict resolved (canBypassRBACis notstaticon 4.4.x).