Skip to content

Bastion Container Creation #14

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

Merged
merged 25 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5d6942d
add basic bastion container
amandayclee Jul 16, 2024
7386b3e
Remove the prebuilt bastion image and add a custom Dockerfile
amandayclee Jul 19, 2024
47380dd
add create sysadmin user and add to sudoers
amandayclee Jul 19, 2024
ff0272f
add bastion hosts config
amandayclee Jul 24, 2024
bfd9310
add sysadmin no password config for bastion server
amandayclee Jul 24, 2024
15dd011
revise docker compose for no password config
amandayclee Jul 24, 2024
e731e75
change the order of commands to get ssh start
amandayclee Jul 24, 2024
2ec280d
update bastion/dockerfile and dockercomose
Shafiya-Heena Jul 25, 2024
22a8e1d
update bastion config file and location
Shafiya-Heena Jul 25, 2024
6b11dc1
update db files to start the ssh service
Shafiya-Heena Jul 25, 2024
0d48777
adjust spacing
Shafiya-Heena Jul 25, 2024
a790822
correcting the space
Shafiya-Heena Jul 25, 2024
bf9bdcd
remove db folder and update docker compose as SSH is no longer needed…
amandayclee Jul 30, 2024
e7d883b
Merge branch 'bastion' of github.com:creativecommons/ansible-dev into…
amandayclee Jul 30, 2024
7a45bbf
fix typo in docker compose file
amandayclee Jul 31, 2024
a2de11a
remove duplicate command for ansible-dev
amandayclee Jul 31, 2024
ce8eeec
run ansible playbook command in dockerfile
amandayclee Jul 31, 2024
3066249
add ProxyJump config and remove db-dev in sysadmin ssh config for bas…
amandayclee Aug 8, 2024
3fd6a8d
revert the ENTRYPOINT change in ansible Dockerfile
amandayclee Aug 8, 2024
436b70d
update README.MD for bastion and ssh config
amandayclee Aug 12, 2024
a603592
correct ProxyJump in ssh config
amandayclee Aug 12, 2024
8b7a388
correct contaniner port in ssh config
amandayclee Aug 12, 2024
fcbdf61
update README.md
Shafiya-Heena Aug 15, 2024
afc2079
update README.md
Shafiya-Heena Aug 15, 2024
f4eb225
update README.md
Shafiya-Heena Aug 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The aim of the project is to establish a robust and localized development enviro
The [`docker-compose.yml`](docker-compose.yml) file defines the following
containers:

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

**SSH connection from bastion**:
- 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.
- currently, db-dev is not handled through bastion
- Execute the following command to confirm the bastion connection:

```shell
ssh -J sysadmin@localhost:22222 sysadmin@web-dev
```

```shell
ssh -J sysadmin@localhost:22222 sysadmin@ansible-dev
```

## Related Links
- [Ansible Documentation](https://docs.ansible.com/)
- [FrontPage - Debian Wiki](https://wiki.debian.org/FrontPage)
Expand Down
3 changes: 1 addition & 2 deletions ansible/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ ENV ANSIBLE_CONFIG=/etc/ansible/ansible.cfg
EXPOSE 22

# Start SSH service
CMD ["/usr/sbin/sshd", "-D"]

CMD ["/usr/sbin/sshd", "-D"]
53 changes: 53 additions & 0 deletions bastion/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# https://docs.docker.com/engine/reference/builder/
# https://hub.docker.com/_/debian
FROM debian:bookworm-slim

# Configure apt not to prompt during docker build
ARG DEBIAN_FRONTEND=noninteractive

# Configure apt to avoid installing recommended and suggested packages
RUN apt-config dump \
| grep -E '^APT::Install-(Recommends|Suggests)' \
| sed -e 's/1/0/' \
| tee /etc/apt/apt.conf.d/99no-recommends-no-suggests

# Resynchronize the package index files from their sources
RUN apt-get update

# Install git
RUN apt-get install -y \
sed \
openssh-client \
openssh-server \
vim

# Clean up packages: Saves space by removing unnecessary package files and lists
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

# Create sysadmin user and add to sudoers
RUN useradd -m -s /bin/bash sysadmin && echo "sysadmin:sysadmin" | chpasswd && \
usermod -aG sudo sysadmin

# Copy the sudoers file for sysadmin user to the appropriate directory
COPY ./bastion/etc-sudoers.d/sysadmin_all_nopass /etc/sudoers.d/sysadmin_all_nopass

# Ensure SSH directory exists with correct permissions
RUN mkdir -p /home/sysadmin/.ssh && \
chown sysadmin:sysadmin /home/sysadmin/.ssh && \
chmod 700 /home/sysadmin/.ssh

# Create privilege separation directory for SSH
RUN mkdir -p /run/sshd

# Update SSH configuration to disable password authentication
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && \
sed -i 's/#AllowTcpForwarding yes/AllowTcpForwarding yes/' /etc/ssh/sshd_config && \
sed -i 's/#GatewayPorts no/GatewayPorts yes/' /etc/ssh/sshd_config

# Expose SSH port
EXPOSE 22

# Start the SSH daemon
CMD ["/usr/sbin/sshd", "-D"]
5 changes: 5 additions & 0 deletions bastion/etc-sudoers.d/sysadmin_all_nopass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# vim: ft=sudoers
#
# This file MUST be edited with `/usr/sbin/visudo -sf FILENAME`.

%sudo ALL =(ALL) NOPASSWD:ALL
17 changes: 17 additions & 0 deletions bastion/sysadmin-.ssh-config/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Host bastion-dev
HostName localhost
User sysadmin
Port 22222
IdentityFile /home/sysadmin/.ssh/id_rsa

Host ansible-dev
HostName ansible-dev
User sysadmin
Port 22
IdentityFile /home/sysadmin/.ssh/id_rsa

Host web-dev
HostName web-dev
User sysadmin
Port 22
IdentityFile /home/sysadmin/.ssh/id_rsa
40 changes: 0 additions & 40 deletions db/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions db/startupservice.sh

This file was deleted.

26 changes: 15 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ services:
- "22001:22"
environment:
- USER=sysadmin
entrypoint: |
sh -c "
exec /usr/sbin/sshd -D
"

web-dev:
container_name: web-dev
Expand Down Expand Up @@ -65,22 +61,29 @@ services:

db-dev:
container_name: db-dev
build:
context: .
dockerfile: db/Dockerfile
environment:
USER: sysadmin
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
image: mariadb
networks:
- dev-backend
restart: on-failure
ports:
- "3306:3306"
- "22003:22"
volumes:
- db-data:/var/lib/mysql

bastion-dev:
container_name: bastion-dev
build:
context: .
dockerfile: bastion/Dockerfile
networks:
- dev-backend
expose:
- 22/tcp
ports:
- 22222:22/tcp
volumes:
- ./sysadmin-ssh-keys/rsa_sysadmin:/home/sysadmin/.ssh/id_rsa:ro
- ./sysadmin-ssh-keys/rsa_sysadmin.pub:/home/sysadmin/.ssh/id_rsa.pub:ro
- ./sysadmin-ssh-keys/rsa_sysadmin.pub:/home/sysadmin/.ssh/authorized_keys:ro
Expand All @@ -94,4 +97,5 @@ volumes:
networks:
dev-backend:
name: dev-backend
driver: bridge