Welcome to the SSH Demo with Certificates repo! The purpose of this repository is to allow a user to access an isolated node using a bastion or proxy host.
We will be leveraging Docker containers for both the proxy and application nodes.
Instead of using SSH Keys for accessing the application node we will generate a short-lived SSH certificate and use that to access the node! How cool is that?
Contact Allen Vailliencourt ~ allenv@goteleport.com ~ for any questions/comments or feel free to open up an issue here on GitHub!
- Docker & Docker Compose installed locally
- Shell/Terminal access
- Potential
rootpriviledges (if needed, depending on your system Docker may or may not require root priviledge) - Internet access to pull upstream images
-
configs- Stores basic configuration files and templates that will be copied to the container on build timeapp_issue- Optional SSH MOTDbastion_issue- Optional SSH MOTDapp.motd- Simple MOTD file for app nodebastion.motd- Simple MOTD file for bastion node (not really used as users cannot SSH into the bastion node)app_sshd_config- SSHD configuration file for app nodebastion_sshd_config- SSHD configuration file for bastion nodeapp_startup.sh- This sets and starts the UFW firewall rules and then the SSHD service.sshd_config- Default SSHD config (not used)user_cshrc_config- Default shell settingsuser_logout_config- Default.profilesettings
-
app.Dockerfile- Dockerfile for the Application node -
bastion.Dockerfile- Dockerfile for the Bastion node -
docker-compose.yml- Docker Compose file to start all containers -
copy_keys.sh- Bash script to copy SSL certificates and keys to local system -
LICENSE- Standard Apache License -
README.md- What you're reading now! :) -
.dockerignore&.gitignore- Standard ignore files
-
Git clone this repo via HTTPS, SSH, or GH CLI.
-
Open a terminal/shell and
cdinto the repository's main folder (ssh-certificate-demotypically). -
Run
docker-compose build --build-arg PASSWORD=<PASSWORD>- this will take a few minutes to build out the two containers. Use the--build-argto input a user password at build time. It can be anything. The password is just for theappuserandbastionusers when initially created. SSH doesn't like users with blank passwords in/etc/shadow(that I've found).note: With the recent changes to the public Docker hub, you might have to login with your Docker username/password in order to download upstream images for the build.
-
Run
docker-compose up -dto start the containers once the build completes. The-dflag detaches and runs the containers in the background. You can run adocker psordocker-compose psto see the status of the running containers. -
Run
chmod +x copy_keys.shto make the shell script executable (needed for next step). -
Run
./copy_keys.sh. This bash script will copy the certs, pub keys, set up a custom config file, and modify your~/.ssh/known_hostsfile. Note: if you arerootyou might have to manually create the/root/.ssh/directory so that the script can write out theconfigfile. Dig into the script for details on what it does if you are curious. The files will be added to your/tmp/ssh_filesfolder. There is no error checking in the bash script for this demo. In a production environment you would want your bash script to be a little more robust. -
Run
ssh -F /tmp/ssh_files/config app-node. After a few seconds your terminal should drop into theapp_node. You can also runssh -F /tmp/ssh_files/config -J bastion-node app-nodeas another option. What this command does is leverage yourconfigfile to ProxyJump from thebastion-nodeto theapp-node. If you want to see some verbose logging you can put in the-vvflag in the ssh command. -
Congrats! You have successfully connected to a docker container via a bastion host leveraging SSH certificates!
-
Type in
exitto disconnect anddocker-compose downto stop the running containers.
-
Additional info:
- View the certificate(s):
ssh-keygen -L -f /tmp/ssh_files/app-user-key-cert.pub(replace the app with thebastionto see that certificate) - Verify that a cert is being used to authenticate:
ssh -F config app-node -vv 2>&1 | grep certificate
- View the certificate(s):
- OSX - Big Sur, 11.5.2 - docker version 20.10.7 (August 2021)
- Vagrant - Ubuntu 20.04 - docker verion 20.10.2 (January/February 2021)
- Much of the inspiration came from multiple open-source repositories, blog posts, and gists of various ways of tackling this project. Google & StackOverflow are your friends. :)
- Want to see more SSH cert awesomeness? Check out Teleport!
- Or our main site www.goteleport.com