Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuxel authored Nov 5, 2021
1 parent e31f02c commit 833ac2a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions .devcontainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/openvpn-tmp
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# You can use any debian based image you want
FROM mcr.microsoft.com/vscode/devcontainers/base:0-bullseye

# Install openvpn client
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update \
&& apt-get -y install --no-install-recommends openvpn \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/library-scripts \
#
# Remove the OPENVPN_CONFIG variable since we don't neeed it after is written to a file
&& echo "unset OPENVPN_CONFIG" | tee -a /etc/bash.bashrc > /etc/profile.d/unset-openvpn-config.sh \
&& if [ -d "/etc/zsh" ]; then echo "unset OPENVPN_CONFIG" >> /etc/zsh/zshenv; fi
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "OpenVPN Sample",
"build": {
"dockerfile": "Dockerfile",
},

// Allow the container to interact with host networking
"runArgs": ["--cap-add=NET_ADMIN", "--cap-add=NET_RAW", "--device=/dev/net/tun"],

// Save the contents of the OPENVPN_CONFIG secret to disk - it lands in .devcontainer/openvpn-tmp
"initializeCommand": "bash .devcontainer/save-config.sh",

// [Optional] Once the dev container is running, automatically start up the VPN client
"postStartCommand": "bash .devcontainer/start-openvpn.sh",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
14 changes: 14 additions & 0 deletions .devcontainer/save-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e

# Switch to the .devcontainer folder
cd "$( dirname "${BASH_SOURCE[0]}" )"

# Create a temporary directory
mkdir -p openvpn-tmp
cd openvpn-tmp

# Save the configuration from the secret if it is present
if [ ! -z "${OPENVPN_CONFIG}" ]; then
echo "${OPENVPN_CONFIG}" > vpnconfig.ovpn
fi
21 changes: 21 additions & 0 deletions .devcontainer/start-openvpn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e

# Switch to the .devcontainer folder
cd "$( dirname "${BASH_SOURCE[0]}" )"

# Create a temporary directory
mkdir -p openvpn-tmp
cd openvpn-tmp

# Touch file to make sure this user can read it
touch openvpn.log

# If we are running as root, we do not need to use sudo
sudo_cmd=""
if [ "$(id -u)" != "0" ]; then
sudo_cmd="sudo"
fi

# Start up the VPN client using the config stored in vpnconfig.ovpn by save-config.sh
nohup ${sudo_cmd} /bin/sh -c "openvpn --config vpnconfig.ovpn --log openvpn.log &" | tee openvpn-launch.log
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# codespaces-openvpn
# Using the OpenVPN client from Codespaces

0 comments on commit 833ac2a

Please sign in to comment.