Konfiguracja Tomcat 9

0

Cześć, mam kłopot z konfiguracją Tomcat. Chciałem zrobić deploy z Jenkinsa na Tomcat ale jest problem z uprawnieniami

Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403)

Skonfigurowałem Tomcata ale nadal nic to nie dało. Nawet jak wchodzę przez stronę to też nie mam dostępu

403 Access Denied
You are not authorized to view this page.

By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.

If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.

If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.

manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only
The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.
For more information - please see the Manager App How-To.

contex.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
        <Valve className="org.apache.catalina.valves.RemoteAddrValve"
                         allow=".*" />

  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|Stri$

</Context>

tomacat-users.xml

Last login: Thu Mar 12 17:22:41 on ttys000

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Piotrs-MBP:~ Piotr$ ssh [email protected]
[email protected]'s password: 
Linux server291692 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u2 (2019-11-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Mar 12 17:54:07 2020 from 91.231.25.56
root@server291692:~#  curl tomcat-host:8090/manager/text/list -u 
-bash: curl: command not found
root@server291692:~# cd ..
root@server291692:/# ls
bin   etc	  initrd.img.old  lost+found  opt   run   sys  var
boot  home	  lib		  media       proc  sbin  tmp  vmlinuz
dev   initrd.img  lib64		  mnt	      root  srv   usr  vmlinuz.old
root@server291692:/# cd opt/tomcat/conf/
root@server291692:/opt/tomcat/conf# sudo vim tomcat-users.xml 
root@server291692:/opt/tomcat/conf# cd ../bin/
root@server291692:/opt/tomcat/bin# ./shutdown.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-amd64
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
root@server291692:/opt/tomcat/bin# ./startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-amd64
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
root@server291692:/opt/tomcat/bin# cd ../conf/
root@server291692:/opt/tomcat/conf# ls
Catalina	     context.xml	   logging.properties  tomcat-users.xsd
catalina.policy      jaspic-providers.xml  server.xml	       web.xml
catalina.properties  jaspic-providers.xsd  tomcat-users.xml
root@server291692:/opt/tomcat/conf# sudo vim tomcat-users.x
root@server291692:/opt/tomcat/conf# sudo vim tomcat-users.xml 
root@server291692:/opt/tomcat/conf# cd ../bin/
root@server291692:/opt/tomcat/bin# ./shutdown.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-amd64
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
root@server291692:/opt/tomcat/bin# ./startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-amd64
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
root@server291692:/opt/tomcat/bin# cd ../conf/
root@server291692:/opt/tomcat/conf# sudo vim tomcat-users.xml 
root@server291692:/opt/tomcat/conf# cd ../bin/
root@server291692:/opt/tomcat/bin# ./shutdown.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-amd64
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
root@server291692:/opt/tomcat/bin# ./startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-amd64
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
root@server291692:/opt/tomcat/bin# cd ../conf/
root@server291692:/opt/tomcat/conf# sudo vim tomcat-users.xml 
root@server291692:/opt/tomcat/conf# sudo vim tomcat-users.xml 
root@server291692:/opt/tomcat/conf# nano tomcat-users.xml 

  GNU nano 2.7.4                File: tomcat-users.xml                          

  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->

  <role rolename="manager-gui"/>
  <role rolename="role1"/>
  <role rolename="manager-script"/>
  <user username="tomcat" password="test" roles="manager-gui"/>
  <user username="both" password="test" roles="tomcat,role1"/>
  <user username="role1" password="test" roles="role1"/>

<user username="jenkins" password="jenkins" role="manager-script"/>
</tomcat-users>

0

a jaką komendą robisz deploy z jenkinsa?

1

a próbowałeś "z palca", a dopiero jak zadziała to przez wtyczkę?

0
javafxdev napisał(a):

a próbowałeś "z palca", a dopiero jak zadziała to przez wtyczkę?
Nawet jak próbuje wejść np na http://xxxx.pl:8080/manager/html
Dostaję

403 Access Denied
You are not authorized to view this page.

By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.

If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.

If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.

manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only
The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.
For more information - please see the Manager App How-To.

Więc raczej coś po stronie Tomcata jest że nie wycztuje mi userów, bo powinien poprosić o hasło wchodząc pod ten link

0

ale u siebie nie masz manager-gui chyba ustawionego, to dlaczego próbujesz wchodzić przez www?

0

Jeszcze spróbuj nadać admina temu userowi w tomcacie.

e; nie zobaczyłem tego wcześniej, masz tam napisane, że:
manager-script - allows access to the text interface and the status pages
The username you provided is not allowed to use the text-based Tomcat Manager.

Więc musisz dodać mu jeszcze takową rolę.

1

Mam nadzieje, ze to jakas aplikacja legacy, bo jesli to cos nowego to zacznij od wywalenia tego Tomcata

0

nowa aplikacja. Skonfigurować od nowa Tomcata czy zastąpić go innym kontenerem?

Nie chciałem tego pisać bo wyjdę na upierdliwego radykała czy coś podobnego, ale już się nie tworzy nowych aplikacji jako wary i nie umieszcza się ich w kontenerach.
Teraz tworzy się fat jary w które używają kontenerów embedded jak embedded Tomcat lub Jetty

0

ktoś chyba starego tutoriala przeczytał...

0

Docelowo będzie to Jetty ale potrzebuje Tomcata dla celów testowych. Głownie dlatego że zacząłem ogarniać Jenkinsa i to co znalazłem o deploy to głownie na Tomcata. Myślałem że łatwiej będzie od tego zacząć ale jak widać mam problem i chciałbym go rozwiązć

0
Programmer10111 napisał(a):

Docelowo będzie to Jetty ale potrzebuje Tomcata dla celów testowych. Głownie dlatego że zacząłem ogarniać Jenkinsa i to co znalazłem o deploy to głownie na Tomcata. Myślałem że łatwiej będzie od tego zacząć ale jak widać mam problem i chciałbym go rozwiązć

Nie, nie będzie łatwiej, bo teraz rozwiązujesz problemy, które dla Jetty nie istnieją.
W przypadku wbudowania Jetty w jara, czyli zrobieniu fat jara, deploy polega na przesłaniu jara i wywołaniu java -jar nazwa-fat-jara.jar

0

ktoś tu chyba nie czyta ze zrozumieniem...

0

Tak pobierze z repo SVN, zbuduje javą 1.4EE, odpali ANTa, ściągine sterowniki do bazy danych .jar do folderu i wszystko będzie pięknie.

0

@javafxdev: hahah :)
A tak na poważne. Nigdy jeszcze nie korzystałem z Jetty, zresztą sam nie konfigurowałem zewnetrznego serwera. Zazwyczaj moim zadaniem było wypchnięcie tego do repo. Tym bardziej że ostatnie lata spędziłem nad Xamrinem i teraz chce powrócić do Javy to jest mi trochę cięzko połapać się ze zmianami. Aplikacja będzie pisana w Spring Boot dla własnych celów. Jeżeli chodzi o zmianę samego serwera z Tomacta na Jetty w Springu to nie problem. Ale chciałbym dowiedzieć się jak to mogę deployować i uruchamiać na zewnętrznym serwerze ? Najlepiej również aby to działało na zasadzie w kiedy wypchnę kod do repo to idzie również deploy na serwer. Czy muszę używac do tego Jenkinsa albo Dockera ? Czy mogę to zrobić tylko przy użyciu Mavena ? Z góry dziękuje

1 użytkowników online, w tym zalogowanych: 0, gości: 1