Skip to content

Restrict shell .invoke, .redirect, addCommand, removeCommand and alias -p to admin role - #3153

Open
jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:restrict-shell-invoke-redirect
Open

jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:restrict-shell-invoke-redirect

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Problem

SecuredSessionFactoryImpl enforces RBAC checks on the shell:.invoke (reflective method invocation) and shell:.redirect (I/O redirection) pseudo-commands, but those ACL rules were only present in the integration test fixture (itests/test/src/test/filtered-resources/etc/feature.xml) and omitted from the shipped production shell feature (etc/org.apache.karaf.command.acl.shell.cfg) and child-instance templates.

Because Karaf command ACLs fail open on Specificity.NO_MATCH by default, any authenticated console user (including viewer) could execute arbitrary Java/OS commands via Gogo reflection and write arbitrary files (such as etc/users.properties) via shell redirection.

In addition, auditing the remaining shell:* commands found equivalent bypasses:

  • shell:addCommand wraps targets via Felix Gogo's CommandProxy, which calls Reflective.invoke directly and bypasses SecuredSessionFactoryImpl.invoke
  • shell:removeCommand removes registered commands from the shared CommandProcessorImpl
  • shell:alias -p / --persist appends directly to ${karaf.etc}/shell.init.script, which executes on subsequent admin logins

Fix

  1. Add .invoke = admin, .redirect = admin, addCommand = admin, removeCommand = admin, alias[/.*(-p|--persist).*/] = admin, and alias = viewer to org.apache.karaf.command.acl.shell:
    • assemblies/features/standard/src/main/feature/feature.xml
    • instance/src/main/resources/org/apache/karaf/instance/resources/etc/org.apache.karaf.command.acl.shell.cfg
    • itests/test/src/test/filtered-resources/etc/feature.xml
  2. Comment out the unused right-prompt reflection block (max_colors = ($.jline.terminal getNumericCapability max_colors) and SimpleDateFormat / Date) in assemblies/features/base/src/main/resources/resources/etc/shell.init.script, whose #rprompt assignment was already commented out, so non-admin SSH logins do not fail with Command not found: shell:.invoke.
  3. Update manual/src/main/asciidoc/user-guide/security.adoc.

Testing

  • Expanded ShellCommandSecurityTest (testShellReflectionAndRedirectSecurityViaSsh) to verify viewer and manager are denied reflection (.invoke), redirection (> / >>), shell:addCommand, shell:removeCommand, and shell:alias -p/--persist, while plain shell:alias remains available to viewer and admin (karaf) can use reflection and redirection.
  • Verified locally against the rebuilt apache-karaf distribution:
    • mvn test -pl shell/core: 27 passed, 0 failed
    • mvn test -pl instance: 36 passed, 0 failed
    • mvn test -pl itests/test -Dtest=ShellCommandSecurityTest: 2 passed, 0 failed
    • mvn test -pl itests/test -Dtest="*SecurityTest": 19 run, 0 failures, 0 errors, 2 pre-existing @Ignored skipped in JMXSecurityTest
    • mvn apache-rat:check on modified modules: passed

…s -p to admin role

SecuredSessionFactoryImpl enforces RBAC checks on shell:.invoke and shell:.redirect, but those rules were only added to the itest fixture and omitted from the shipped shell feature and child-instance templates. Also restrict shell:addCommand, shell:removeCommand, and shell:alias -p/--persist to admin, and comment out the unused max_colors/right-prompt reflection block in shell.init.script so non-admin logins succeed cleanly.
@github-actions

Copy link
Copy Markdown

Test Results

1 132 files  +  258  1 132 suites  +258   1h 24m 59s ⏱️ + 34m 33s
1 402 tests +    1  1 271 ✅ +    2  131 💤 ±  0  0 ❌  - 1 
5 608 runs  +1 194  5 082 ✅ +1 095  526 💤 +100  0 ❌  - 1 

Results for commit e53b67a. ± Comparison against base commit bff40bc.

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