Spaces:
Paused
Paused
Gemini Assistant commited on
Commit ·
d391ffa
1
Parent(s): 720325e
Initial project upload
Browse files- Dockerfile +23 -0
- Help.md +70 -0
- README.md +17 -6
- docker-entrypoint.sh +11 -0
- entrypoint.sh +28 -0
- sshd_config +4 -0
- stunnel.conf +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base image
|
| 2 |
+
FROM alpine:latest
|
| 3 |
+
|
| 4 |
+
# Install packages - only stunnel and openssh-client are needed
|
| 5 |
+
RUN apk add --no-cache stunnel openssh-client iperf3
|
| 6 |
+
|
| 7 |
+
# Create a non-root user with UID 1000
|
| 8 |
+
RUN addgroup -g 1000 user && adduser -u 1000 -G user -h /home/user -s /bin/sh -D user
|
| 9 |
+
|
| 10 |
+
# Copy configs
|
| 11 |
+
COPY stunnel.conf /etc/stunnel/stunnel.conf
|
| 12 |
+
|
| 13 |
+
# Copy entrypoint and make it executable
|
| 14 |
+
COPY entrypoint.sh /entrypoint.sh
|
| 15 |
+
RUN chmod +x /entrypoint.sh
|
| 16 |
+
|
| 17 |
+
# Switch to the new user
|
| 18 |
+
WORKDIR /home/user
|
| 19 |
+
|
| 20 |
+
# Expose the port that will be mapped by Hugging Face
|
| 21 |
+
EXPOSE 2222
|
| 22 |
+
|
| 23 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
Help.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Help: Architecture of the Advanced Tunnel
|
| 2 |
+
|
| 3 |
+
This document describes the components, configurations, and data flow of the advanced tunneling solution.
|
| 4 |
+
|
| 5 |
+
## 1. Overview
|
| 6 |
+
|
| 7 |
+
The primary goal of this setup is to create a stable, secure, and multi-purpose connection between a sandboxed environment (like Google Cloud Shell or a Hugging Face Space, referred to as **cs**) and a publicly accessible Virtual Dedicated Server (**vds1**).
|
| 8 |
+
|
| 9 |
+
This is achieved by running a specialized Docker container within **cs** that initiates a persistent, reverse SSH tunnel to **vds1**.
|
| 10 |
+
|
| 11 |
+
## 2. Participating Hosts (Nodes)
|
| 12 |
+
|
| 13 |
+
There are three main components in this architecture:
|
| 14 |
+
|
| 15 |
+
1. **Cloud Shell (cs) / Hugging Face Space**
|
| 16 |
+
* **Role**: The host environment where the Docker container runs.
|
| 17 |
+
* **Characteristics**: Can have a dynamic IP address, may have restricted inbound traffic.
|
| 18 |
+
|
| 19 |
+
2. **Docker Container (tunnel-container)**
|
| 20 |
+
* **Role**: The core of the solution. It runs all the necessary software to establish and maintain the tunnels.
|
| 21 |
+
* **Runs On**: **cs**
|
| 22 |
+
|
| 23 |
+
3. **VDS1 (vds1.iri1968.dpdns.org)**
|
| 24 |
+
* **Role**: The public-facing anchor point and remote server.
|
| 25 |
+
* **Characteristics**: Has a static IP address and open ports. It runs a service on port `143` that `stunnel` from the container connects to.
|
| 26 |
+
|
| 27 |
+
## 3. Container Configuration
|
| 28 |
+
|
| 29 |
+
The container is built from the `Dockerfile` and runs the following key software:
|
| 30 |
+
|
| 31 |
+
* **`stunnel`**: Runs as a client. It connects to **vds1** on port `143` and creates a secure TLS tunnel, which is then exposed locally within the container on `127.0.0.1:2222`.
|
| 32 |
+
* **`ssh` (client)**: This is the final and most critical piece. It connects to the local `stunnel` endpoint (`127.0.0.1:2222`) and authenticates on **vds1** as the `root` user. Once connected, it establishes several **reverse tunnels** (`-R`) back to **vds1**.
|
| 33 |
+
* **`iperf3`**: A network performance testing tool.
|
| 34 |
+
|
| 35 |
+
## 4. Data Flow and Relationships
|
| 36 |
+
|
| 37 |
+
The connection is established in a "reverse" direction, from the inside (**cs**) to the outside (**vds1**).
|
| 38 |
+
|
| 39 |
+
```mermaid
|
| 40 |
+
graph TD
|
| 41 |
+
subgraph "Cloud Shell (cs) / Hugging Face Space"
|
| 42 |
+
A[Container: ssh client] -- "connects to" --> B[local stunnel endpoint: 127.0.0.1:2222]
|
| 43 |
+
end
|
| 44 |
+
|
| 45 |
+
subgraph "Internet"
|
| 46 |
+
C(vds1.iri1968.dpdns.org)
|
| 47 |
+
end
|
| 48 |
+
|
| 49 |
+
B -- "TLS Tunnel" --> C[:143]
|
| 50 |
+
C -- "Reverse Tunnels Established" --> A
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
**Step-by-step flow:**
|
| 55 |
+
|
| 56 |
+
1. The `entrypoint.sh` script starts inside the container.
|
| 57 |
+
2. `stunnel` connects to `vds1:143`, creating a secure link. This link is presented as `localhost:2222` inside the container.
|
| 58 |
+
3. The `ssh` client inside the container connects to `localhost:2222`, using the private key for **vds1** (`id_rsa_vds1`) and authenticating as `root`. The traffic is routed through the `stunnel` tunnel to the `stunnel` server on `vds1`, which in turn forwards it to the main `sshd` server on `vds1`.
|
| 59 |
+
4. Once this SSH session is active, the `-R` flags create the pathways back from `vds1` to the container. For example, `-R 0.0.0.0:2222:localhost:22` on `vds1` would forward traffic to port 22 inside the container's network.
|
| 60 |
+
|
| 61 |
+
This architecture effectively makes services running inside the sandboxed **cs** container accessible from the public **vds1** server.
|
| 62 |
+
|
| 63 |
+
## 5. Hugging Face Deployment
|
| 64 |
+
|
| 65 |
+
To deploy this container on a Hugging Face Space, you must configure one **Space Secret**:
|
| 66 |
+
|
| 67 |
+
* **Name**: `ID_RSA_VDS1`
|
| 68 |
+
* **Value**: The entire content of your private SSH key file (`id_rsa_vds1`), including the `-----BEGIN OPENSSH PRIVATE KEY-----` and `-----END OPENSSH PRIVATE KEY-----` lines.
|
| 69 |
+
|
| 70 |
+
The `entrypoint.sh` script will read this secret and create the necessary key file for the SSH connection to work.
|
README.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: red
|
| 6 |
sdk: docker
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: mit
|
| 3 |
+
title: Advanced Tunnel Container
|
|
|
|
|
|
|
| 4 |
sdk: docker
|
| 5 |
+
emoji: 🚀
|
| 6 |
+
colorFrom: gray
|
| 7 |
+
colorTo: indigo
|
| 8 |
+
pinned: true
|
| 9 |
+
app_port: 2222
|
| 10 |
+
persistent_storage: true
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Advanced Tunnel Container
|
| 14 |
+
|
| 15 |
+
## Overview
|
| 16 |
+
|
| 17 |
+
This container provides a multi-purpose tunneling and network testing environment designed to establish a secure and robust connection between a local environment (like Google Cloud Shell) and a remote server (VDS).
|
| 18 |
+
|
| 19 |
+
It uses a combination of `stunnel` and `SSH` to create a primary tunnel and then establishes multiple reverse tunnels for various services.
|
| 20 |
+
|
| 21 |
+
See **Help.md** for a detailed description of the architecture, setup, and data flow.
|
docker-entrypoint.sh
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
# This wrapper script runs as root.
|
| 3 |
+
|
| 4 |
+
set -e
|
| 5 |
+
|
| 6 |
+
# 1. Generate SSH host keys
|
| 7 |
+
/usr/bin/ssh-keygen -A
|
| 8 |
+
|
| 9 |
+
# 2. Switch to the "user" and execute the main entrypoint script.
|
| 10 |
+
# su-exec is a lightweight sudo/gosu alternative common in Alpine.
|
| 11 |
+
exec su-exec user /entrypoint.sh
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
# 1. Create private key from secret in the user's home directory
|
| 4 |
+
if [ -z "$ID_RSA_VDS1" ]; then
|
| 5 |
+
echo "Error: ID_RSA_VDS1 secret is not set."
|
| 6 |
+
exit 1
|
| 7 |
+
fi
|
| 8 |
+
mkdir -p /home/user/.ssh
|
| 9 |
+
echo "$ID_RSA_VDS1" > /home/user/.ssh/id_rsa_vds1
|
| 10 |
+
chmod 600 /home/user/.ssh/id_rsa_vds1
|
| 11 |
+
chown -R user:user /home/user/.ssh
|
| 12 |
+
|
| 13 |
+
# 2. Start stunnel client in the background
|
| 14 |
+
stunnel /etc/stunnel/stunnel.conf &
|
| 15 |
+
|
| 16 |
+
# Give stunnel a moment to connect
|
| 17 |
+
sleep 3
|
| 18 |
+
|
| 19 |
+
# 3. Execute the reverse SSH tunnel command in the foreground
|
| 20 |
+
# This will keep the container alive
|
| 21 |
+
ssh -v -N -g \
|
| 22 |
+
-o "StrictHostKeyChecking=no" \
|
| 23 |
+
-o "UserKnownHostsFile=/dev/null" \
|
| 24 |
+
-R 0.0.0.0:1080:localhost:1080 \
|
| 25 |
+
-R 0.0.0.0:2222:localhost:22 \
|
| 26 |
+
-R 0.0.0.0:5201:localhost:5201 \
|
| 27 |
+
-p 2222 root@127.0.0.1 \
|
| 28 |
+
-i /home/user/.ssh/id_rsa_vds1
|
sshd_config
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Port 22
|
| 2 |
+
PermitRootLogin yes
|
| 3 |
+
PubkeyAuthentication yes
|
| 4 |
+
AuthorizedKeysFile /home/user/.ssh/authorized_keys
|
stunnel.conf
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
foreground = yes
|
| 2 |
+
client = yes
|
| 3 |
+
|
| 4 |
+
[imaps-ssh]
|
| 5 |
+
accept = 127.0.0.1:2222
|
| 6 |
+
connect = vds1.iri1968.dpdns.org:143
|