core icon indicating copy to clipboard operation
core copied to clipboard

OSGI Framework - Fix in OSGIAJAX to support Felix Load folder as Symbolic Link for a Clustered Environment

Open agomez-dotcms opened this issue 9 years ago • 3 comments

During a dotCMS upgrade for a specific Client, OSGI framework was unable to deploy dynamic plugins targeted to a Felix Load folder defined as symbolic link (for a clustered environment). This problem was fixed via hotfix mechanism but it may be fixed at dotCMS core level: dotCMS core's OSGIAJAX is not properly validating Felix Load directory when defined as a symbolic link to a directory that is to be shared by all nodes in the cluster.

Expected Behavior

dotCMS should successfully be able to deploy dynamic plugins into Tomcat's Felix Load directory defined as symbolic link to a directory shared by all nodes in a cluster

/<THE_TOMCAT_DIRECTORY>/webapps/ROOT/WEB-INF/felix
 |
 |_ load -> /<THE_SHARED_DIRECTORY>/felix/load
 |
 |_ undeployed -> /<THE_SHARED_DIRECTORY>/felix/undeployed

Current Behavior

dotCMS is not currently able to deploy dynamic plugins into Tomcat's Felix Load directory defined as symbolic link because of wrong validation performed by OSGIAJAX at the moment that plugin is uploaded. Instead, it fails with following error in dotcms.log:

[15/03/17 16:04:12:262 CST]  INFO AJAX.OSGIAJAX: class com.dotmarketing.portlets.osgi.AJAX.OSGIAJAX : Invalid OSGI Upload request:/Users/anibalgomez/Development/Workspace/dotCMS/3.7.1/work/felix/load/com.dotcms.unlockcontentlets-1.0.0.jar from:0:0:0:0:0:0:0:1

Possible Solution

Following fix may be made in OSGIAJAX class's add method (package com.dotmarketing.portlets.osgi.AJAX), which may be incorporated as part of dotCMS's core (Replaced condition "!osgiJar.getCanonicalPath().startsWith(felixFolder.getCanonicalPath())" by "!osgiJar.getCanonicalPath().startsWith(new File(felixFolder.getAbsolutePath() + File.separator + "load").getCanonicalPath())"): https://github.com/dotCMS/core/blob/3.7.1/src/com/dotmarketing/portlets/osgi/AJAX/OSGIAJAX.java#L146

public class OSGIAJAX extends OSGIBaseAJAX {
   ...
   public void add ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
      ...
      try {
         ...
         while ( iterator.hasNext() ) {
            ...
            if ( !felixFolder.exists()
                    ||   !osgiJar.getCanonicalPath().startsWith(new File(felixFolder.getAbsolutePath() + File.separator + "load").getCanonicalPath())) {
                response.sendError(403);
                SecurityLogger.logInfo(this.getClass(),  "Invalid OSGI Upload request:" + osgiJar.getCanonicalPath() + " from:" +request.getRemoteHost() + " " );
                return;
            }
            ...
         }
      } catch ( FileUploadException e ) {
         ...
      }
   }
   ...
}

Context

Reproduced during client setup on dotCMS cloud after migration/upgrade to dotCMS 3.7.1. https://my.dotcms.com/tickets/detail.dot?id=8ec9cd6d-d829-4533-9f6f-9c7d68b6d2dd

Your Environment

  • dotCMS version used: 3.7.1.
  • Browser Name and version: Any Browser
  • Operating System and version: Amazon Linux
  • Application Server and version: Apache Tomcat
  • Database and version: Postgres

agomez-dotcms avatar Mar 15 '17 23:03 agomez-dotcms

The fix for this issue may be borrowed from hot-fix at https://github.com/dotCMS/support/tree/master/hotfixes/hotfix-GIT-11062_v3.7.1. Also, the original Support ticket may be accessed at https://my.dotcms.com/tickets/detail.dot?id=b91a61f0-66bf-49b9-9cd0-b9f5ed26eb16

agomez-dotcms avatar Mar 15 '17 23:03 agomez-dotcms

I think #10370 is the proper way to config felix

wezell avatar Mar 31 '17 12:03 wezell

you can also turn on symbolic links in Tomcat which will make it work. BUT still the real issue is the ability to properly configure as @wezell already said

FWIW see here https://tomcat.apache.org/tomcat-8.0-doc/config/resources.html that is the issue and will fix it.

jtesser avatar Mar 31 '17 12:03 jtesser