Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

Commit 833ac2a

Browse files
authored
Initial
1 parent e31f02c commit 833ac2a

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

.devcontainer/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/openvpn-tmp

.devcontainer/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# You can use any debian based image you want
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:0-bullseye
3+
4+
# Install openvpn client
5+
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update \
6+
&& apt-get -y install --no-install-recommends openvpn \
7+
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/library-scripts \
8+
#
9+
# Remove the OPENVPN_CONFIG variable since we don't neeed it after is written to a file
10+
&& echo "unset OPENVPN_CONFIG" | tee -a /etc/bash.bashrc > /etc/profile.d/unset-openvpn-config.sh \
11+
&& if [ -d "/etc/zsh" ]; then echo "unset OPENVPN_CONFIG" >> /etc/zsh/zshenv; fi

.devcontainer/devcontainer.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "OpenVPN Sample",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
},
6+
7+
// Allow the container to interact with host networking
8+
"runArgs": ["--cap-add=NET_ADMIN", "--cap-add=NET_RAW", "--device=/dev/net/tun"],
9+
10+
// Save the contents of the OPENVPN_CONFIG secret to disk - it lands in .devcontainer/openvpn-tmp
11+
"initializeCommand": "bash .devcontainer/save-config.sh",
12+
13+
// [Optional] Once the dev container is running, automatically start up the VPN client
14+
"postStartCommand": "bash .devcontainer/start-openvpn.sh",
15+
16+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
17+
"remoteUser": "vscode"
18+
}

.devcontainer/save-config.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Switch to the .devcontainer folder
5+
cd "$( dirname "${BASH_SOURCE[0]}" )"
6+
7+
# Create a temporary directory
8+
mkdir -p openvpn-tmp
9+
cd openvpn-tmp
10+
11+
# Save the configuration from the secret if it is present
12+
if [ ! -z "${OPENVPN_CONFIG}" ]; then
13+
echo "${OPENVPN_CONFIG}" > vpnconfig.ovpn
14+
fi

.devcontainer/start-openvpn.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Switch to the .devcontainer folder
5+
cd "$( dirname "${BASH_SOURCE[0]}" )"
6+
7+
# Create a temporary directory
8+
mkdir -p openvpn-tmp
9+
cd openvpn-tmp
10+
11+
# Touch file to make sure this user can read it
12+
touch openvpn.log
13+
14+
# If we are running as root, we do not need to use sudo
15+
sudo_cmd=""
16+
if [ "$(id -u)" != "0" ]; then
17+
sudo_cmd="sudo"
18+
fi
19+
20+
# Start up the VPN client using the config stored in vpnconfig.ovpn by save-config.sh
21+
nohup ${sudo_cmd} /bin/sh -c "openvpn --config vpnconfig.ovpn --log openvpn.log &" | tee openvpn-launch.log

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# codespaces-openvpn
1+
# Using the OpenVPN client from Codespaces
2+

0 commit comments

Comments
 (0)