Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic container image #54

Merged
merged 11 commits into from
Jun 13, 2024
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ However, please use `docker exec -it target bash` preferrebly to interact with t

When done, the container can be stopped with `docker stop target`.
## Available images & tags
- Generic (needs to be built manually, see [applications/generic](applications/generic/))
- [Home Assistant](https://ghcr.io/greenbone/vt-test-environments/home-assistant) (`home-assistant`, run with `--network host`, when requiring e.g. mDNS capabilities)
- `2023.5.2`
- [AlmaLinux](https://ghcr.io/greenbone/vt-test-environments/almalinux) (`almalinux`)
Expand Down
30 changes: 30 additions & 0 deletions applications/generic/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG BASEIMAGE
ARG TAG

FROM ghcr.io/greenbone/vt-test-environments/${BASEIMAGE}:${TAG}
ARG UPDATED=true
ARG TAG

# Install dependencies
RUN apt-get update \
&& if [ "$UPDATED" = true ]; then apt-get upgrade -y; fi \
&& apt-get install -y apache2 php mariadb-server samba \
&& rm -rf /var/lib/apt/lists/*

# Configure Apache and PHP
RUN sed -i "/^expose_php/s/=.*/= On/" /etc/php/*/apache2/php.ini \
&& sed -i "/^ServerTokens/s/ .*/ Full/" /etc/apache2/conf-enabled/security.conf \
&& echo '<?php echo("test"); ?>' > /var/www/html/index.php

# Configure MariaDB
RUN sed -i "/^bind-address/s/= .*/= */" /etc/mysql/mariadb.conf.d/50-server.cnf \
&& service mariadb start || service mysql start \
&& echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;" | mysql

# Configure Samba
RUN sed -i "/^\[global\]/a\ server min protocol = NT1" /etc/samba/smb.conf

ADD init.sh /
CMD [ "/init.sh" ]

EXPOSE 80 445 3306
36 changes: 36 additions & 0 deletions applications/generic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# vt-test-environments/applications/generic

This image contains generic services to test OS detection VTs. It's based on our Debian-based test images.

## Services installed

- `openssh-server` (port 22, inherited from the base image)
- `apache2` (port 80)
- `php`
- `mariadb-server` (port 3306)
- `samba` (port 445)

## Build

The Dockerfile requires two build arguments:
- `BASEIMAGE`: The name of the base image to build upon
- `TAG`: The tag of the base image to build upon

For example, to build the generic test image for Debian trixie (`ghcr.io/greenbone/vt-test-environments/debian:trixie`) and save under `generic:debian_trixie` run:

```
docker build --pull --build-arg BASEIMAGE=debian --build-arg TAG=trixie applications/generic -t generic:debian_trixie
```

You can use any Debian-based base image from [vt-test-environments](https://github.com/orgs/greenbone/packages?repo_name=vt-test-environments).


## Usage
For the example above, run:

```
docker run --rm -it -p 2222:22 -p 80:80 -p 445:445 -p 3306:3306 generic:debian_trixie
```

Note: In this example, I mapped all container ports to the host, except for port 22, which is mapped to port 2222 on the host.
22 changes: 22 additions & 0 deletions applications/generic/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

source /etc/os-release
# In Debian 10 and Ubuntu 20.10 or earlier the init file is called differently
if [ "$ID" = "debian" ] && dpkg --compare-versions "$VERSION_ID" le 10 \
|| [ "$ID" = "ubuntu" ] && dpkg --compare-versions "$VERSION_ID" le 20.10
then
service mysql start
else
service mariadb start
fi


for service in ssh apache2 smbd
do
service $service start
done

echo "Ready!"

sleep infinity
Loading