OWASP / SecurityShepherd

Web and mobile application security training platform

Home Page:https://owasp.org/www-project-security-shepherd/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] mysql port is not changes. It is running on default port despite changing in docker-compose file.

spmishra121 opened this issue · comments

Describe the bug
Mysql db port is not changing. It is running on default port despite changing in docker-compose.

To Reproduce
Steps to reproduce the behavior:
After following all installation process. Change mysql port like 3312 and restart docker-compose. Validate docker ps and check the port on which it is running.

Hi @spmishra121 make sure you have the latest changes from the dev branch.

Then you just need to change the value DB_PORT in the .env file file to whatever you want e.g. DB_PORT=3312

Once you issue docker-compose up it'll expose the database on port 3312.

I've just tested and the output of docker ps is

CONTAINER ID   IMAGE                             COMMAND                  CREATED         STATUS         PORTS                       NAMES

ebc53c7fc3b0   owasp/security-shepherd_mariadb   "docker-entrypoint.s…"   6 seconds ago   Up 5 seconds 127.0.0.1:3312->3306/tcp     secshep_mariadb
mysql -u root -pCowSaysMoo  -P 3312
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.5-10.5.8-MariaDB-1:10.5.8+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Thanks @ismisepaul for your quick response. I am sharing all details about config along with docker ps...

In this configuration, I had used 9090 for tomcat and 3312 for

docker-compose file
version: '2'
services:
db:
image: ${IMAGE_MARIADB}
container_name: ${CONTAINER_MARIADB}
volumes:
- data:/var/lib/mysql
env_file:
- .env
build:
context: docker/mariadb
args:
DB_VERSION: ${DB_VERSION}
DB_BIND_ADDRESS: ${DB_BIND_ADDRESS}
CONTAINER_TOMCAT: ${CONTAINER_TOMCAT}
DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASS}
ports:
- "${DB_SERVER_IP}:${DB_PORT}:3312"
mongo:
image: ${IMAGE_MONGO}
container_name: ${CONTAINER_MONGO}
volumes:
- mongodata:/data/db
- mongoconfig:/data/configdb
env_file:
- .env
build:
context: ./docker/mongo
args:
MONGODB_VERSION: ${MONGODB_VERSION}
web:
image: ${IMAGE_TOMCAT}
container_name: ${CONTAINER_TOMCAT}
volumes:
- conf:/usr/local/tomcat/conf
env_file:
- .env
build:
context: .
args:
TOMCAT_DOCKER_VERSION: ${TOMCAT_DOCKER_VERSION}
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASS}
MARIADB_URI: jdbc:mysql://${CONTAINER_MARIADB}:3312
MONGO_HOST: ${CONTAINER_MONGO}
MONGO_PORT: 27017
MONGO_CONN_TIMEOUT: 1000
MONGO_SOCK_TIMEOUT: 0
MONGO_SVR_TIMEOUT: 30000
TLS_KEYSTORE_FILE: ${TLS_KEYSTORE_FILE}
TLS_KEYSTORE_PASS: ${TLS_KEYSTORE_PASS}
ALIAS: ${ALIAS}
HTTPS_PORT: ${HTTPS_PORT}
ports:
- $HTTP_PORT:9090
- $HTTPS_PORT:8443
depends_on:
- db
volumes:
data:
conf:
mongodata:
mongoconfig:

.env file
VERSION=3.1

TOMCAT_DOCKER_VERSION=8-jre8-openjdk
DB_VERSION=10.5.8
MONGODB_VERSION=4.1.13

IMAGE_TOMCAT=owasp/security-shepherd
IMAGE_MARIADB=owasp/security-shepherd_mariadb
IMAGE_MONGO=owasp/security-shepherd_mongo

CONTAINER_TOMCAT=secshep_tomcat
CONTAINER_MARIADB=secshep_mariadb
CONTAINER_MONGO=secshep_mongo

DB_USER=root
DB_PASS=CowSaysMoo
DB_SERVER_IP=127.0.0.1
DB_PORT=3312
DB_BIND_ADDRESS="*"

TLS_KEYSTORE_PASS=CowSaysMoo
TLS_KEYSTORE_FILE=shepherdKeystore.p12
ALIAS=tomcat
KEY_ALG=RSA
DNAME=cn=OwaspShepherd,ou=SecurityShepherd,o=OWASP,L=BaileÁthaCliath,ST=Laighin,C=IE
STORE_TYPE=pkcs12

HTTP_PORT=9090
HTTPS_PORT=443

DOCKER_NETWORK_NAME=securityshepherd_default

TEST_MYSQL_HOST=127.0.0.1
TEST_MYSQL_PORT=3312
TEST_MYSQL_PASSWORD=password

Docker ps....
image

In docker-compose log, I am getting below error...

secshep_tomcat | 17-Mar-2022 09:36:55.580 SEVERE [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-8443]]
secshep_tomcat | org.apache.catalina.LifecycleException: Protocol handler initialization failed
secshep_tomcat | at org.apache.catalina.connector.Connector.initInternal(Connector.java:1114)
secshep_tomcat | at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
secshep_tomcat | at org.apache.catalina.core.StandardService.initInternal(StandardService.java:571)
secshep_tomcat | at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
secshep_tomcat | at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:874)
secshep_tomcat | at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
secshep_tomcat | at org.apache.catalina.startup.Catalina.load(Catalina.java:646)
secshep_tomcat | at org.apache.catalina.startup.Catalina.load(Catalina.java:669)
secshep_tomcat | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
secshep_tomcat | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
secshep_tomcat | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
secshep_tomcat | at java.lang.reflect.Method.invoke(Method.java:498)
secshep_tomcat | at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:305)
secshep_tomcat | at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
secshep_tomcat | Caused by: java.lang.IllegalArgumentException: Invalid keystore format
secshep_tomcat | at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:100)
secshep_tomcat | at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:72)
secshep_tomcat | at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:205)
secshep_tomcat | at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1221)
secshep_tomcat | at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1234)
secshep_tomcat | at org.apache.tomcat.util.net.AbstractJsseEndpoint.init(AbstractJsseEndpoint.java:222)
secshep_tomcat | at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:633)
secshep_tomcat | at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:80)
secshep_tomcat | at org.apache.catalina.connector.Connector.initInternal(Connector.java:1111)
secshep_tomcat | ... 13 more
secshep_tomcat | Caused by: java.io.IOException: Invalid keystore format
secshep_tomcat | at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:666)
secshep_tomcat | at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:57)
secshep_tomcat | at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224)
secshep_tomcat | at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:71)
secshep_tomcat | at java.security.KeyStore.load(KeyStore.java:1445)
secshep_tomcat | at org.apache.tomcat.util.security.KeyStoreUtil.load(KeyStoreUtil.java:69)
secshep_tomcat | at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:214)
secshep_tomcat | at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:207)
secshep_tomcat | at org.apache.tomcat.util.net.SSLUtilBase.getKeyManagers(SSLUtilBase.java:280)
secshep_tomcat | at org.apache.tomcat.util.net.openssl.OpenSSLUtil.getKeyManagers(OpenSSLUtil.java:98)
secshep_tomcat | at org.apache.tomcat.util.net.SSLUtilBase.createSSLContext(SSLUtilBase.java:244)
secshep_tomcat | at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:98)
secshep_tomcat | ... 21 more

Hi @spmishra121 it looks like your doing things to the docker compose file that are beyond the function and design.

Are you aware of port mapping? https://docs.docker.com/config/containers/container-networking/

Imo you don't want to be changing the internal ports. What you need to do is revert your changes and use the .env file. That the only place you should be changing port numbers as they reference the externally exposed ports. Don't touch the docker compose or docker files. If you do that I cannot assist as it's beyond the design.

The other issue might be in relation to issue #595 you need Java 8 installed.

I am getting following response...
[root@ip-10-25-24-36 satyap]# docker exec -it feb5e5bcf23b java -version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM (build 25.322-b06, mixed mode)
[root@ip-10-25-24-36 satyap]#

Please let me know, if this is correct.

@spmishra121 its not the java version running in the docker image it's the java version on you host machine.

You need java 8 to build the war on your host machine before its put inside the docker image.

working as expected