build proper dockerized example

This commit is contained in:
Dominic Breuker
2018-02-18 14:03:59 +01:00
parent a31224ff21
commit c56430d8c4
13 changed files with 111 additions and 32 deletions

View File

@@ -1,15 +0,0 @@
FROM golang:1.9-stretch
RUN apt-get update && apt-get -y install cron sudo
COPY docker/etc/cron.d /etc/cron.d
COPY docker/scripts /scripts
RUN useradd -ms /bin/bash myuser && \
adduser myuser sudo && \
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER myuser
WORKDIR /go/src/github.com/dominicbreuker

View File

@@ -0,0 +1,20 @@
FROM golang:1.10-stretch
RUN apt-get update && apt-get -y install cron python3 sudo procps
# install root cronjob
COPY docker/var/spool/cron/crontabs /var/spool/cron/crontabs
RUN chmod 600 /var/spool/cron/crontabs/root
COPY docker/root/scripts /root/scripts
# set up unpriviledged user
# allows passwordless sudo to start cron as root on startup
RUN useradd -ms /bin/bash myuser && \
adduser myuser sudo && \
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER myuser
# drop into bash shell
COPY docker/entrypoint-development.sh /entrypoint.sh
RUN sudo chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]

25
docker/Dockerfile.example Normal file
View File

@@ -0,0 +1,25 @@
FROM debian:stretch
RUN apt-get update && apt-get -y install cron python3 sudo procps
# install root cronjob
COPY docker/var/spool/cron/crontabs /var/spool/cron/crontabs
RUN chmod 600 /var/spool/cron/crontabs/root
COPY docker/root/scripts /root/scripts
# install pspy
COPY bin/pspy64 /usr/bin/pspy
# set up unpriviledged user
# allows passwordless sudo to start cron as root on startup
RUN useradd -ms /bin/bash myuser && \
adduser myuser sudo && \
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER myuser
# deploy startup script
COPY docker/entrypoint-example.sh /entrypoint.sh
RUN sudo chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]

View File

@@ -0,0 +1,13 @@
#!/bin/bash
set -e
sudo cron -f &
sleep 1
sudo ps | grep cron 1>/dev/null
echo "[+] cron started"
echo "[+] Running as user `id`"
echo "[+] Dropping into shell..."
exec /bin/bash

View File

@@ -0,0 +1,13 @@
#!/bin/bash
set -e
sudo cron -f &
sleep 1
sudo ps | grep cron 1>/dev/null
echo "[+] cron started"
echo "[+] Running as user `id`"
echo "[+] Starting pspy now..."
pspy 2>/dev/null

View File

@@ -0,0 +1 @@
* * * * * root python /root/scripts/password_reset.py

View File

@@ -1 +0,0 @@
* * * * * root echo 'this is some text' >> /tmp/myjob.log

View File

@@ -1 +0,0 @@
* * * * * root python /scripts/print_stuff.py >> /tmp/print.log

View File

@@ -0,0 +1,12 @@
#!/usr/bin/python
import string
import random
from subprocess import call
new_password = ''.join(random.SystemRandom()
.choice(string.ascii_uppercase + string.digits)
for _ in range(16))
call("/bin/echo -e \"{}\\n{}\" | passwd myuser"
.format(new_password, new_password), shell=True)

View File

@@ -1,9 +0,0 @@
#!/usr/bin/python
user = "myusername"
password = "thepw"
for i in range(100):
print("a"*i)
print("done")

View File

@@ -0,0 +1 @@
* * * * * python3 /root/scripts/password_reset.py