You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stephen Tenberg <st...@gmail.com> on 2024/06/19 17:55:46 UTC

Tomcat 9 symlinks ?

Hello I have scoured the web trying to get symlinks working for jsp pages
or folders in Tomcat 9 using Ubuntu 20.04. Here is how to repeat the issue,
and what I have tried.

1. Create a new folder in webapps, say "foo"

2. Put HelloWorld.jsp there

3. (I restarted Tomcat just in case) Verify it works at
localhost:8080/foo/HelloWorld.jsp

4. Put a soft symlink there: ln -s /opt/tomcat/webapps/foo/HelloWorld.jsp
/opt/tomcat/webapps/foo/Link.jsp

5. (restart) Verify that localhost:8080/foo/Link.jsp soft fails with
nothing in the log as if it does not exist.

WHAT I TRIED:

First I put this in the default host "localhost" in server.xml:

 <Context path="" reloadable="true" docBase="foo">
          <Resources allowLinking="true" cacheMaxSize="51200">
</Resources>
</Context>

      <Context path="/ROOT" docBase="ROOT"/>

This achieves the objective of making "foo" the default so now I can just
use localhost:8080/HelloWorld.jsp

However "allow linking" is silently ignored.  I also tried editing
context.xml and adding to the context:

 <Resources allowLinking="true" />
  <Resources cacheMaxSize="51200" />

Both of these solutions were gleaned from reading the documentation and
Google searches, and I seem to be stuck here.

For now I cannot install a later version of Tomcat (using Amazon Java 8
Coretto) or remove the symlinks as they are required by an existing
application.

Any thoughts are greatly appreciated.

Re: Tomcat 9 symlinks ?

Posted by Chuck Caldarale <n8...@gmail.com>.
Also take a look at this:

https://tomcat.apache.org/tomcat-9.0-doc/security-howto.html#Default_web_applications

  - Chuck


> On Jun 19, 2024, at 15:23, Robert Turner <rt...@e-djuster.ca.INVALID> wrote:
> 
> This page might be a useful resource to read if you haven't already:
> https://tomcat.apache.org/tomcat-9.0-doc/config/context.html
> 
> The short version is -- to publish an application in the "root" web url
> path (of http(s)://your.server-name.com/), you can name your WAR file
> "ROOT.war" and copy it to the <catalina-base>/webapps folder. Tomcat will
> extract it into a folder called "ROOT", but this is not a subfolder called
> "ROOT" when served to clients, it's served as "/".
> 
> Nothing else needs doing to map paths -- nothing really on your context, or
> any system config file, etc.
> 
> On Wed, Jun 19, 2024 at 4:17 PM Stephen Tenberg <st...@gmail.com>
> wrote:
> 
>> Thank you.  Do we just rename the existing ROOT to something else so the
>> admin stuff is available?  The path="" was appealing as we want this
>> existing large application to be available as "/". Is renaming ROOT a
>> better way of achieving this?
>> 
>> On Wed, Jun 19, 2024 at 3:50 PM Chuck Caldarale <n8...@gmail.com> wrote:
>> 
>>> 
>>>> On Jun 19, 2024, at 14:42, Stephen Tenberg <st...@gmail.com>
>>> wrote:
>>>> 
>>>> You asked why  path="" instead of path="foo" in context at server.xml?
>>>> 
>>>> That was our attempt to mount this application at "/" instead of at
>>> "/foo"
>>>> which is a requirement here.
>>> 
>>> 
>>> Just deploy the application as ROOT (case matters) rather than foo.
>>> 
>>>  - Chuck
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> 
>>> 
>> 


Re: Tomcat 9 symlinks ?

Posted by Robert Turner <rt...@e-djuster.ca.INVALID>.
This page might be a useful resource to read if you haven't already:
https://tomcat.apache.org/tomcat-9.0-doc/config/context.html

The short version is -- to publish an application in the "root" web url
path (of http(s)://your.server-name.com/), you can name your WAR file
"ROOT.war" and copy it to the <catalina-base>/webapps folder. Tomcat will
extract it into a folder called "ROOT", but this is not a subfolder called
"ROOT" when served to clients, it's served as "/".

Nothing else needs doing to map paths -- nothing really on your context, or
any system config file, etc.

On Wed, Jun 19, 2024 at 4:17 PM Stephen Tenberg <st...@gmail.com>
wrote:

> Thank you.  Do we just rename the existing ROOT to something else so the
> admin stuff is available?  The path="" was appealing as we want this
> existing large application to be available as "/". Is renaming ROOT a
> better way of achieving this?
>
> On Wed, Jun 19, 2024 at 3:50 PM Chuck Caldarale <n8...@gmail.com> wrote:
>
> >
> > > On Jun 19, 2024, at 14:42, Stephen Tenberg <st...@gmail.com>
> > wrote:
> > >
> > > You asked why  path="" instead of path="foo" in context at server.xml?
> > >
> > > That was our attempt to mount this application at "/" instead of at
> > "/foo"
> > > which is a requirement here.
> >
> >
> > Just deploy the application as ROOT (case matters) rather than foo.
> >
> >   - Chuck
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>

Re: Tomcat 9 symlinks ?

Posted by Chuck Caldarale <n8...@gmail.com>.
> On Jun 19, 2024, at 15:16, Stephen Tenberg <st...@gmail.com> wrote:
> 
> Thank you.  Do we just rename the existing ROOT to something else so the
> admin stuff is available?


The default ROOT application does not have any admin purpose itself, but it does have links to admin functions that are separate from the ROOT application. It’s safe to simply delete the existing ROOT directory. If you want to still have it available in production (some would argue doing so is a small security window), then renaming ROOT to something else is an option.


> The path="" was appealing as we want this
> existing large application to be available as "/“.


And also blocks access to the existing ROOT application.


> Is renaming ROOT a
> better way of achieving this?


Much better.

  - Chuck


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 9 symlinks ?

Posted by Stephen Tenberg <st...@gmail.com>.
Thank you.  Do we just rename the existing ROOT to something else so the
admin stuff is available?  The path="" was appealing as we want this
existing large application to be available as "/". Is renaming ROOT a
better way of achieving this?

On Wed, Jun 19, 2024 at 3:50 PM Chuck Caldarale <n8...@gmail.com> wrote:

>
> > On Jun 19, 2024, at 14:42, Stephen Tenberg <st...@gmail.com>
> wrote:
> >
> > You asked why  path="" instead of path="foo" in context at server.xml?
> >
> > That was our attempt to mount this application at "/" instead of at
> "/foo"
> > which is a requirement here.
>
>
> Just deploy the application as ROOT (case matters) rather than foo.
>
>   - Chuck
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Tomcat 9 symlinks ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Chuck,

On 6/19/24 15:49, Chuck Caldarale wrote:
> 
>> On Jun 19, 2024, at 14:42, Stephen Tenberg <st...@gmail.com> wrote:
>>
>> You asked why  path="" instead of path="foo" in context at server.xml?
>>
>> That was our attempt to mount this application at "/" instead of at "/foo"
>> which is a requirement here.
> 
> 
> Just deploy the application as ROOT (case matters) rather than foo.

+1

And this is trivial when the application is self-contained with a 
META-INF/context.xml which *should not specify the path* because all you 
have to do is re-name the directory or WAR file and you are done.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 9 symlinks ?

Posted by Chuck Caldarale <n8...@gmail.com>.
> On Jun 19, 2024, at 14:42, Stephen Tenberg <st...@gmail.com> wrote:
> 
> You asked why  path="" instead of path="foo" in context at server.xml?
> 
> That was our attempt to mount this application at "/" instead of at "/foo"
> which is a requirement here.


Just deploy the application as ROOT (case matters) rather than foo.

  - Chuck


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 9 symlinks ?

Posted by Stephen Tenberg <st...@gmail.com>.
Thanks very much for the comprehensive reply.  I tried as you suggested and
it worked fine, resolving symbolic links both inside and outside the tomcat
webapps directory.

You asked why  path="" instead of path="foo" in context at server.xml?

That was our attempt to mount this application at "/" instead of at "/foo"
which is a requirement here.  And that indeed worked, I was able to access
the jsp page at "/".  However, I will research that again and look at every
way of doing it - it's not germane to the real problem here which
is symlinks - which appears to be solved at least in initial
experimentation using your suggestion.

Thanks again.

On Wed, Jun 19, 2024 at 3:09 PM Christopher Schultz <
chris@christopherschultz.net> wrote:

> Stephen,
>
> On 6/19/24 13:55, Stephen Tenberg wrote:
> > Hello I have scoured the web trying to get symlinks working for jsp pages
> > or folders in Tomcat 9 using Ubuntu 20.04. Here is how to repeat the
> issue,
> > and what I have tried.
> >
> > 1. Create a new folder in webapps, say "foo"
> >
> > 2. Put HelloWorld.jsp there
> >
> > 3. (I restarted Tomcat just in case) Verify it works at
> > localhost:8080/foo/HelloWorld.jsp
> >
> > 4. Put a soft symlink there: ln -s /opt/tomcat/webapps/foo/HelloWorld.jsp
> > /opt/tomcat/webapps/foo/Link.jsp
> >
> > 5. (restart) Verify that localhost:8080/foo/Link.jsp soft fails with
> > nothing in the log as if it does not exist.
> >
> > WHAT I TRIED:
> >
> > First I put this in the default host "localhost" in server.xml:
> >
> >   <Context path="" reloadable="true" docBase="foo">
> >            <Resources allowLinking="true" cacheMaxSize="51200">
> > </Resources>
> > </Context>
>
> Why path="" instead of path="foo"?
>
> In fact... why bother with a <Context> element at all? The presence of
> the "foo" directory will automatically deploy an application on /foo.
> Yes, in order to "allow linking" you will need a <Context> to set it on,
> but that should be under webapps/foo/META-INF/context.xml and not in
> conf/server.xml. Yes, you can put it in server.xml, but you should not
> do that for a few reasons.
>
> >        <Context path="/ROOT" docBase="ROOT"/>
>
> Yuck. Now you have an application deployed into "/ROOT" as well as ""
> (the default ROOT application, mounted on /)
>
> > This achieves the objective of making "foo" the default so now I can just
> > use localhost:8080/HelloWorld.jsp
>
> I think you must have copy/pasted incorrectly, but nothing of what you
> put above would allow /HelloWorld.jsp to run the JSP in "foo".
>
> > However "allow linking" is silently ignored.  I also tried editing
> > context.xml and adding to the context:
> >
> >   <Resources allowLinking="true" />
> >    <Resources cacheMaxSize="51200" />
>
> This ... is confusing at best because you have two elements in there.
> I'm not sure what will happen if you define it twice. Maybe the second
> one overwrites the first? If that's true, it might explain why it
> wouldn't work.
>
> > Both of these solutions were gleaned from reading the documentation and
> > Google searches, and I seem to be stuck here.
> >
> > For now I cannot install a later version of Tomcat (using Amazon Java 8
> > Coretto) or remove the symlinks as they are required by an existing
> > application.
> >
> > Any thoughts are greatly appreciated.
>
> First: simplify. Put everything into your application and give it the
> name AND context-path you want, for example webapps/foo and everything
> is in there.
>
> There is really only one place where symlinking can be configured at
> all, which is <Resources>. Put your <Context> in
> webapps/foo/META-INF/context.xml and use a single <Resources> element
> with an appropriate configuration.
>
> Remove everything else.
>
> Restart and see what happens when you request /foo/Link.jsp
>
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Tomcat 9 symlinks ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Stephen,

On 6/19/24 13:55, Stephen Tenberg wrote:
> Hello I have scoured the web trying to get symlinks working for jsp pages
> or folders in Tomcat 9 using Ubuntu 20.04. Here is how to repeat the issue,
> and what I have tried.
> 
> 1. Create a new folder in webapps, say "foo"
> 
> 2. Put HelloWorld.jsp there
> 
> 3. (I restarted Tomcat just in case) Verify it works at
> localhost:8080/foo/HelloWorld.jsp
> 
> 4. Put a soft symlink there: ln -s /opt/tomcat/webapps/foo/HelloWorld.jsp
> /opt/tomcat/webapps/foo/Link.jsp
> 
> 5. (restart) Verify that localhost:8080/foo/Link.jsp soft fails with
> nothing in the log as if it does not exist.
> 
> WHAT I TRIED:
> 
> First I put this in the default host "localhost" in server.xml:
> 
>   <Context path="" reloadable="true" docBase="foo">
>            <Resources allowLinking="true" cacheMaxSize="51200">
> </Resources>
> </Context>

Why path="" instead of path="foo"?

In fact... why bother with a <Context> element at all? The presence of 
the "foo" directory will automatically deploy an application on /foo. 
Yes, in order to "allow linking" you will need a <Context> to set it on, 
but that should be under webapps/foo/META-INF/context.xml and not in 
conf/server.xml. Yes, you can put it in server.xml, but you should not 
do that for a few reasons.

>        <Context path="/ROOT" docBase="ROOT"/>

Yuck. Now you have an application deployed into "/ROOT" as well as "" 
(the default ROOT application, mounted on /)

> This achieves the objective of making "foo" the default so now I can just
> use localhost:8080/HelloWorld.jsp

I think you must have copy/pasted incorrectly, but nothing of what you 
put above would allow /HelloWorld.jsp to run the JSP in "foo".

> However "allow linking" is silently ignored.  I also tried editing
> context.xml and adding to the context:
> 
>   <Resources allowLinking="true" />
>    <Resources cacheMaxSize="51200" />

This ... is confusing at best because you have two elements in there. 
I'm not sure what will happen if you define it twice. Maybe the second 
one overwrites the first? If that's true, it might explain why it 
wouldn't work.

> Both of these solutions were gleaned from reading the documentation and
> Google searches, and I seem to be stuck here.
> 
> For now I cannot install a later version of Tomcat (using Amazon Java 8
> Coretto) or remove the symlinks as they are required by an existing
> application.
> 
> Any thoughts are greatly appreciated.

First: simplify. Put everything into your application and give it the 
name AND context-path you want, for example webapps/foo and everything 
is in there.

There is really only one place where symlinking can be configured at 
all, which is <Resources>. Put your <Context> in 
webapps/foo/META-INF/context.xml and use a single <Resources> element 
with an appropriate configuration.

Remove everything else.

Restart and see what happens when you request /foo/Link.jsp

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org