Skip to content

Commit 164a0c3

Browse files
Merge pull request #14 from creativecommons/bastion
Bastion Container Creation
2 parents b01ee24 + f4eb225 commit 164a0c3

File tree

8 files changed

+105
-69
lines changed

8 files changed

+105
-69
lines changed

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The aim of the project is to establish a robust and localized development enviro
3232
The [`docker-compose.yml`](docker-compose.yml) file defines the following
3333
containers:
3434

35-
- WIP: Bastion (SSH jump server)
35+
- **bastion-dev** - Bastion (SSH jump server)
3636
- **ansible-dev** - Ansible
3737
- **web-dev** - Web server (Apache2/WordPress)
3838
- **db-dev** - Database server (MariaDB)
@@ -89,6 +89,19 @@ The SSH setup has been established and is currently in use for the Ansible conta
8989
ssh -i ./sysadmin-ssh-keys/rsa_sysadmin -p 22001 sysadmin@localhost
9090
```
9191

92+
**SSH connection from bastion**:
93+
- ProxyJump allow you to use `ssh bastion` to connect to the bastion-dev host, and `ssh ansible-dev` or `ssh web-dev`, and SSH will automatically connect through the bastion jump host.
94+
- currently, db-dev is not handled through bastion
95+
- Execute the following command to confirm the bastion connection:
96+
97+
```shell
98+
ssh -J sysadmin@localhost:22222 sysadmin@web-dev
99+
```
100+
101+
```shell
102+
ssh -J sysadmin@localhost:22222 sysadmin@ansible-dev
103+
```
104+
92105
## Related Links
93106
- [Ansible Documentation](https://docs.ansible.com/)
94107
- [FrontPage - Debian Wiki](https://wiki.debian.org/FrontPage)

ansible/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ ENV ANSIBLE_CONFIG=/etc/ansible/ansible.cfg
5656
EXPOSE 22
5757

5858
# Start SSH service
59-
CMD ["/usr/sbin/sshd", "-D"]
60-
59+
CMD ["/usr/sbin/sshd", "-D"]

bastion/Dockerfile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# https://docs.docker.com/engine/reference/builder/
2+
# https://hub.docker.com/_/debian
3+
FROM debian:bookworm-slim
4+
5+
# Configure apt not to prompt during docker build
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
8+
# Configure apt to avoid installing recommended and suggested packages
9+
RUN apt-config dump \
10+
| grep -E '^APT::Install-(Recommends|Suggests)' \
11+
| sed -e 's/1/0/' \
12+
| tee /etc/apt/apt.conf.d/99no-recommends-no-suggests
13+
14+
# Resynchronize the package index files from their sources
15+
RUN apt-get update
16+
17+
# Install git
18+
RUN apt-get install -y \
19+
sed \
20+
openssh-client \
21+
openssh-server \
22+
vim
23+
24+
# Clean up packages: Saves space by removing unnecessary package files and lists
25+
RUN apt-get clean
26+
RUN rm -rf /var/lib/apt/lists/*
27+
28+
# Create sysadmin user and add to sudoers
29+
RUN useradd -m -s /bin/bash sysadmin && echo "sysadmin:sysadmin" | chpasswd && \
30+
usermod -aG sudo sysadmin
31+
32+
# Copy the sudoers file for sysadmin user to the appropriate directory
33+
COPY ./bastion/etc-sudoers.d/sysadmin_all_nopass /etc/sudoers.d/sysadmin_all_nopass
34+
35+
# Ensure SSH directory exists with correct permissions
36+
RUN mkdir -p /home/sysadmin/.ssh && \
37+
chown sysadmin:sysadmin /home/sysadmin/.ssh && \
38+
chmod 700 /home/sysadmin/.ssh
39+
40+
# Create privilege separation directory for SSH
41+
RUN mkdir -p /run/sshd
42+
43+
# Update SSH configuration to disable password authentication
44+
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && \
45+
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && \
46+
sed -i 's/#AllowTcpForwarding yes/AllowTcpForwarding yes/' /etc/ssh/sshd_config && \
47+
sed -i 's/#GatewayPorts no/GatewayPorts yes/' /etc/ssh/sshd_config
48+
49+
# Expose SSH port
50+
EXPOSE 22
51+
52+
# Start the SSH daemon
53+
CMD ["/usr/sbin/sshd", "-D"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# vim: ft=sudoers
2+
#
3+
# This file MUST be edited with `/usr/sbin/visudo -sf FILENAME`.
4+
5+
%sudo ALL =(ALL) NOPASSWD:ALL

bastion/sysadmin-.ssh-config/config

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Host bastion-dev
2+
HostName localhost
3+
User sysadmin
4+
Port 22222
5+
IdentityFile /home/sysadmin/.ssh/id_rsa
6+
7+
Host ansible-dev
8+
HostName ansible-dev
9+
User sysadmin
10+
Port 22
11+
IdentityFile /home/sysadmin/.ssh/id_rsa
12+
13+
Host web-dev
14+
HostName web-dev
15+
User sysadmin
16+
Port 22
17+
IdentityFile /home/sysadmin/.ssh/id_rsa

db/Dockerfile

-40
This file was deleted.

db/startupservice.sh

-15
This file was deleted.

docker-compose.yml

+15-11
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ services:
1717
- "22001:22"
1818
environment:
1919
- USER=sysadmin
20-
entrypoint: |
21-
sh -c "
22-
exec /usr/sbin/sshd -D
23-
"
2420

2521
web-dev:
2622
container_name: web-dev
@@ -65,22 +61,29 @@ services:
6561

6662
db-dev:
6763
container_name: db-dev
68-
build:
69-
context: .
70-
dockerfile: db/Dockerfile
7164
environment:
72-
USER: sysadmin
7365
MYSQL_DATABASE: wordpress
7466
MYSQL_ROOT_PASSWORD: root
7567
MYSQL_USER: root
68+
image: mariadb
7669
networks:
7770
- dev-backend
7871
restart: on-failure
79-
ports:
80-
- "3306:3306"
81-
- "22003:22"
8272
volumes:
8373
- db-data:/var/lib/mysql
74+
75+
bastion-dev:
76+
container_name: bastion-dev
77+
build:
78+
context: .
79+
dockerfile: bastion/Dockerfile
80+
networks:
81+
- dev-backend
82+
expose:
83+
- 22/tcp
84+
ports:
85+
- 22222:22/tcp
86+
volumes:
8487
- ./sysadmin-ssh-keys/rsa_sysadmin:/home/sysadmin/.ssh/id_rsa:ro
8588
- ./sysadmin-ssh-keys/rsa_sysadmin.pub:/home/sysadmin/.ssh/id_rsa.pub:ro
8689
- ./sysadmin-ssh-keys/rsa_sysadmin.pub:/home/sysadmin/.ssh/authorized_keys:ro
@@ -94,4 +97,5 @@ volumes:
9497
networks:
9598
dev-backend:
9699
name: dev-backend
100+
driver: bridge
97101

0 commit comments

Comments
 (0)