Fred808 commited on
Commit
f7d0167
·
verified ·
1 Parent(s): 10efb44

Upload 12 files

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -5
  2. entrypoint.sh +2 -2
  3. huggingface_fixes.md +73 -0
Dockerfile CHANGED
@@ -7,6 +7,7 @@ RUN apt-get update && apt-get install -y \
7
  iproute2 \
8
  net-tools \
9
  curl \
 
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  # Configure SSH
@@ -18,11 +19,6 @@ RUN useradd -m -s /bin/bash tunneluser
18
 
19
  WORKDIR /app
20
 
21
- RUN chmod -R 777 /app
22
-
23
- # Ensure the app runs as the same user as the Space UI
24
-
25
-
26
  COPY . /app
27
 
28
  RUN chmod +x entrypoint.sh
 
7
  iproute2 \
8
  net-tools \
9
  curl \
10
+ sudo \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
  # Configure SSH
 
19
 
20
  WORKDIR /app
21
 
 
 
 
 
 
22
  COPY . /app
23
 
24
  RUN chmod +x entrypoint.sh
entrypoint.sh CHANGED
@@ -16,7 +16,7 @@ fi
16
  echo "Detected public IP: $PUBLIC_IP"
17
 
18
  # Configure SSH server
19
- sudo /app/ssh-config/sshd_config /etc/ssh/sshd_config
20
  chmod 600 /etc/ssh/sshd_config
21
 
22
  # Generate SSH host keys if they don't exist
@@ -30,7 +30,7 @@ fi
30
  echo "SSH server started."
31
 
32
  # Configure Dante SOCKS5 server
33
- sudo /app/socks5-config/danted.conf /etc/danted.conf
34
  chmod 644 /etc/danted.conf
35
 
36
  # Start Dante SOCKS5 server
 
16
  echo "Detected public IP: $PUBLIC_IP"
17
 
18
  # Configure SSH server
19
+ sudo cp /app/ssh-config/sshd_config /etc/ssh/sshd_config
20
  chmod 600 /etc/ssh/sshd_config
21
 
22
  # Generate SSH host keys if they don't exist
 
30
  echo "SSH server started."
31
 
32
  # Configure Dante SOCKS5 server
33
+ sudo cp /app/socks5-config/danted.conf /etc/danted.conf
34
  chmod 644 /etc/danted.conf
35
 
36
  # Start Dante SOCKS5 server
huggingface_fixes.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Environment Fixes
2
+
3
+ ## Issues Encountered and Resolutions
4
+
5
+ ### 1. Read-only File System Error for IP Forwarding
6
+
7
+ **Error:**
8
+ ```
9
+ ./entrypoint.sh: line 8: /proc/sys/net/ipv4/ip_forward: Read-only file system
10
+ ```
11
+
12
+ **Root Cause:**
13
+ In containerized environments like Hugging Face Spaces, the `/proc` filesystem might be mounted as read-only for security reasons, preventing direct writes to system parameters.
14
+
15
+ **Resolution:**
16
+ - Commented out the direct write to `/proc/sys/net/ipv4/ip_forward` in `entrypoint.sh`
17
+ - Removed `sysctl` commands from the Dockerfile
18
+ - Rely on Docker's default networking capabilities for IP forwarding, which is typically handled by the Docker daemon or host system
19
+
20
+ **Changes Made:**
21
+ ```bash
22
+ # In entrypoint.sh - commented out:
23
+ # echo 1 > /proc/sys/net/ipv4/ip_forward
24
+
25
+ # In Dockerfile - removed:
26
+ # RUN echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
27
+ # RUN sysctl -p
28
+ ```
29
+
30
+ ### 2. Permission Denied Error for SSH Configuration
31
+
32
+ **Error:**
33
+ ```
34
+ cp: cannot create regular file '/etc/ssh/sshd_config': Permission denied
35
+ ```
36
+
37
+ **Root Cause:**
38
+ The user running the `entrypoint.sh` script within the Docker container does not have write permissions to the `/etc/ssh/` directory, which is a system directory requiring elevated privileges.
39
+
40
+ **Resolution:**
41
+ - Added `sudo` prefix to the `cp` commands in `entrypoint.sh` for copying configuration files to system directories
42
+ - This ensures the script has the necessary permissions to modify system configuration files
43
+
44
+ **Changes Made:**
45
+ ```bash
46
+ # In entrypoint.sh - changed from:
47
+ cp /app/ssh-config/sshd_config /etc/ssh/sshd_config
48
+ cp /app/socks5-config/danted.conf /etc/danted.conf
49
+
50
+ # To:
51
+ sudo cp /app/ssh-config/sshd_config /etc/ssh/sshd_config
52
+ sudo cp /app/socks5-config/danted.conf /etc/danted.conf
53
+ ```
54
+
55
+ ## Additional Considerations for Hugging Face Spaces
56
+
57
+ 1. **Container Security:** Hugging Face Spaces may run containers with restricted privileges for security reasons. Using `sudo` helps bypass permission restrictions for necessary system operations.
58
+
59
+ 2. **Networking Limitations:** Some networking features might be restricted in cloud environments. The application should gracefully handle cases where certain network operations are not permitted.
60
+
61
+ 3. **File System Permissions:** System directories like `/etc/` typically require elevated privileges to modify. Always use `sudo` when copying configuration files to system locations.
62
+
63
+ ## Testing Recommendations
64
+
65
+ When deploying to Hugging Face Spaces:
66
+
67
+ 1. Monitor container logs for permission-related errors
68
+ 2. Verify that SSH and SOCKS5 services start successfully
69
+ 3. Test connectivity from external clients
70
+ 4. Ensure the application handles restricted environments gracefully
71
+
72
+ These fixes should resolve the common issues encountered when running the SSH/SOCKS5 NAT Gateway application in Hugging Face Spaces or similar containerized environments.
73
+