[ 
https://issues.apache.org/jira/browse/TIKA-4864?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109983#comment-18109983
 ] 

ASF GitHub Bot commented on TIKA-4864:
--------------------------------------

dschmidt opened a new pull request, #3107:
URL: https://github.com/apache/tika/pull/3107

   Fixes https://issues.apache.org/jira/browse/TIKA-4864
   
   In the docker image (and any unpacked distribution) TikaServerProcess is 
loaded from lib/tika-server-core-4.0.0.jar, so the code-source probe looks for 
lib/plugins, which does not exist. The fallback then returns the relative 
literal "plugins", which the forked PipesServer resolves against its own 
working directory. As soon as an orchestrator starts the container with a 
different workdir (docker run -w, CI systems like Woodpecker do this for 
service containers), the plugin registry comes up empty and every parse fails 
with "Unknown fetcher type: 'file-system-fetcher' ... Available types: []".
   
   The fix keeps the code-source heuristic but also probes the parent of the 
jar directory (covers the lib/ layout) and always returns an absolute path, so 
parent and forked process agree on the same directory regardless of CWD.
   
   Note: the CWD fallback is an untrusted-search-path pattern (CWE-427 class): 
the server loads and instantiates jars from whatever directory it happens to be 
started in. This change narrows the exposure by preferring the install 
directory and absolutizing, but keeps the fallback since it is documented 
behavior. An explicit override (CLI flag or env var) might be a good follow-up.
   
   Adds unit tests for all three probe locations plus the absolute-path 
guarantee.




> Default plugins directory resolution depends on the working directory
> ---------------------------------------------------------------------
>
>                 Key: TIKA-4864
>                 URL: https://issues.apache.org/jira/browse/TIKA-4864
>             Project: Tika
>          Issue Type: Bug
>    Affects Versions: 4.0.0
>            Reporter: Dominik Schmidt
>            Priority: Major
>
> The 4.0.0 docker image (and any classpath-launched tika-server) loses all 
> pipes plugins when the process working directory is not the install 
> directory. The server starts fine, but the first parse fails:
> org.apache.tika.exception.TikaConfigException: Unknown fetcher type: 
> 'file-system-fetcher'
> for instance id '__tika-server'. Available types: []
> Reproduce with the released image; the only difference is the working 
> directory:
> docker run -p 9998:9998 apache/tika:4.0.0-full                 # parses fine
> docker run -w /somewhere -p 9998:9998 apache/tika:4.0.0-full   # first parse 
> fails as above
> This is not a synthetic case: any orchestrator that sets the container 
> working directory hits it, for example Woodpecker CI service containers 
> (workspace as workdir), Kubernetes workingDir, or compose working_dir.
> Cause, in TikaServerProcess.resolveDefaultPluginsDir() (introduced with 
> TIKA-4682):
> 1. It looks for plugins next to "the running jar", taken from the CodeSource 
> of TikaServerProcess. In the docker image that class lives in 
> lib/tika-server-core-4.0.0.jar, so the check probes 
> /opt/tika-server/lib/plugins, which does not exist. The actual plugins sit 
> next to the standard jar in /opt/tika-server/plugins.
> 2. It then falls back to plugins relative to the CWD. In the image that only 
> works because WORKDIR /opt/tika-server happens to match.
> 3. If neither exists, the literal relative string plugins is passed on, and 
> the forked PipesServer resolves it against its own CWD, ending with an empty 
> plugin registry and the error above.
> The javadoc says "The plugin-roots will default to a 'plugins' directory at 
> the same level as the server jar", which is what one would expect, but step 1 
> checks the level of the wrong jar. There is also no CLI or environment 
> override in 4.0.0, only the plugin-roots config key, so the image cannot be 
> fixed from the outside without shipping a config file.
> Suggested fix: also probe the parent of the code-source directory (covers the 
> lib/ layout), or resolve against the jar named on the command line rather 
> than the CodeSource, and resolve the final result to an absolute path before 
> handing it to the pipes fork so the fork's CWD stops mattering. 
> Independently, the docker image could pin plugin-roots absolutely instead of 
> relying on its WORKDIR.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to