Skip to content

Commit a372a11

Browse files
authored
feat: replace Signal Bridge with Tailscale + SSH for secure iPhone access (#21)
Implements secure iPhone → OpenCode communication using official Tailscale and OpenSSH. Security improvements: - Official software only (no unofficial forks) - End-to-end encrypted via Tailscale VPN - SSH key-only authentication - Comprehensive security hardening - All critical vulnerabilities resolved Fixes #21
1 parent dc31801 commit a372a11

19 files changed

Lines changed: 1354 additions & 1477 deletions

‎Dockerfile.opencode-ssh‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# OpenCode Container with SSH Server
2+
# Debian-based container for running OpenCode CLI with SSH access
3+
# Uses official OpenSSH from Debian repositories
4+
5+
FROM node:20-slim
6+
7+
# Install OpenSSH server and essential development tools
8+
RUN apt-get update && apt-get install -y \
9+
openssh-server \
10+
git \
11+
bash \
12+
zsh \
13+
curl \
14+
unzip \
15+
vim \
16+
ca-certificates \
17+
python3 \
18+
python3-pip \
19+
sudo \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
# Create opencode user WITHOUT sudo privileges (security hardening)
23+
# Use UID 1001 to avoid conflict with node user (UID 1000)
24+
RUN useradd -m -u 1001 -s /bin/zsh opencode
25+
26+
# Set up SSH
27+
RUN mkdir -p /run/sshd && \
28+
ssh-keygen -A && \
29+
mkdir -p /home/opencode/.ssh && \
30+
chown -R opencode:opencode /home/opencode/.ssh && \
31+
chmod 700 /home/opencode/.ssh
32+
33+
# Configure SSH daemon for security (comprehensive hardening)
34+
RUN echo "PermitRootLogin no" >> /etc/ssh/sshd_config && \
35+
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config && \
36+
echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config && \
37+
echo "AllowUsers opencode" >> /etc/ssh/sshd_config && \
38+
echo "X11Forwarding no" >> /etc/ssh/sshd_config && \
39+
echo "MaxAuthTries 3" >> /etc/ssh/sshd_config && \
40+
echo "ClientAliveInterval 300" >> /etc/ssh/sshd_config && \
41+
echo "ClientAliveCountMax 2" >> /etc/ssh/sshd_config && \
42+
echo "PermitEmptyPasswords no" >> /etc/ssh/sshd_config && \
43+
echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config
44+
45+
# Create required directories for OpenCode
46+
RUN mkdir -p /home/opencode/.config/opencode \
47+
/home/opencode/.local/share/opencode \
48+
/home/opencode/.local/state && \
49+
touch /home/opencode/.zshrc && \
50+
chown -R opencode:opencode /home/opencode
51+
52+
# Install OpenCode CLI as opencode user
53+
USER opencode
54+
WORKDIR /home/opencode
55+
RUN curl -fsSL https://opencode.ai/install | bash
56+
57+
# Set up shell environment
58+
ENV SHELL=/bin/zsh
59+
ENV TERM=xterm-256color
60+
ENV PATH="/home/opencode/.opencode/bin:${PATH}"
61+
62+
# Copy OpenCode config
63+
COPY --chown=opencode:opencode opencode.container.json /config/opencode.container.json
64+
65+
# Switch back to root for entrypoint (SSH daemon requires root)
66+
USER root
67+
68+
# Copy entrypoint as root-executable
69+
COPY entrypoint-ssh.sh /entrypoint-ssh.sh
70+
RUN chmod +x /entrypoint-ssh.sh
71+
72+
WORKDIR /workspace
73+
74+
ENTRYPOINT ["/entrypoint-ssh.sh"]

‎README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,36 @@ Project Manager:
217217
- **Performance conscious** - N+1 query detection, bundle analysis
218218
- **Accessibility compliance** - WCAG 2.1 AA minimum
219219

220+
## 📱 Remote Access: iPhone Integration
221+
222+
### Tailscale + SSH: Secure Remote Access ⭐ RECOMMENDED
223+
224+
**Access OpenCode from your iPhone terminal over an encrypted Tailscale VPN connection.**
225+
226+
**Quick Setup:**
227+
```bash
228+
# 1. Get Tailscale auth key from https://login.tailscale.com/admin/settings/keys
229+
# 2. Run setup script
230+
cd ~/.config/opencode
231+
TS_AUTHKEY='tskey-auth-xxxxxxxxxxxxxxx' ./setup-tailscale-ssh.sh
232+
233+
# 3. Add your SSH public key
234+
./add-ssh-key.sh ~/.ssh/id_ed25519.pub
235+
236+
# 4. Test from Mac
237+
ssh opencode@$(docker exec opencode_tailscale tailscale ip -4)
238+
239+
# 5. Configure iPhone SSH app (Termius/Blink Shell) with container IP
240+
```
241+
242+
**Features:**
243+
- ✅ **Official Software Only**: Tailscale, OpenSSH, no third-party forks
244+
- ✅ **SSH Key Authentication**: Passwords disabled
245+
- ✅ **VPN Encryption**: WireGuard protocol via Tailscale
246+
- ✅ **Non-Root User**: Isolated execution
247+
- ✅ **Simple Setup**: Automated scripts handle configuration
248+
249+
**Documentation:** See [docs/tailscale-setup.md](docs/tailscale-setup.md) for complete setup guide.
220250
## 🐳 Sandboxed Usage (Recommended)
221251

222252
For maximum security and isolation, run OpenCode inside a Docker container. This setup:

‎add-ssh-key.sh‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Helper script to add SSH public key to OpenCode container
3+
4+
set -euo pipefail
5+
6+
if [ -z "$1" ]; then
7+
echo "Usage: ./add-ssh-key.sh <path-to-public-key>"
8+
echo ""
9+
echo "Example:"
10+
echo " ./add-ssh-key.sh ~/.ssh/id_ed25519.pub"
11+
echo ""
12+
echo "Or provide the key directly:"
13+
echo " ./add-ssh-key.sh 'ssh-ed25519 AAAA...'"
14+
exit 1
15+
fi
16+
17+
# Check if argument is a file or a key string
18+
if [ -f "$1" ]; then
19+
SSH_KEY=$(cat "$1")
20+
echo "Reading SSH key from file: $1"
21+
else
22+
SSH_KEY="$1"
23+
echo "Using provided SSH key string"
24+
fi
25+
26+
# Validate SSH key format to prevent command injection
27+
if [[ ! "$SSH_KEY" =~ ^(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp[0-9]+)[[:space:]][A-Za-z0-9+/=]+ ]]; then
28+
echo "ERROR: Invalid SSH key format"
29+
echo "Expected format: ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp[256|384|521] [base64-key] [optional-comment]"
30+
echo ""
31+
echo "Your key starts with: ${SSH_KEY:0:20}..."
32+
exit 1
33+
fi
34+
35+
# Check if container is running
36+
if ! docker ps | grep -q opencode_with_ssh; then
37+
echo "ERROR: opencode_with_ssh container is not running"
38+
echo "Run ./setup-tailscale-ssh.sh first"
39+
exit 1
40+
fi
41+
42+
echo ""
43+
echo "Adding SSH key to container..."
44+
# Use stdin to avoid shell interpolation and prevent command injection
45+
echo "$SSH_KEY" | docker exec -i opencode_with_ssh tee -a /home/opencode/.ssh/authorized_keys > /dev/null
46+
docker exec opencode_with_ssh chmod 600 /home/opencode/.ssh/authorized_keys
47+
docker exec opencode_with_ssh chown opencode:opencode /home/opencode/.ssh/authorized_keys
48+
49+
echo "✓ SSH key added successfully"
50+
echo ""
51+
52+
# Get Tailscale IP with error handling
53+
if ! TAILSCALE_IP=$(docker exec opencode_tailscale tailscale ip -4 2>/dev/null); then
54+
echo "⚠️ Could not retrieve Tailscale IP"
55+
echo " Container may still be connecting to Tailscale"
56+
echo ""
57+
else
58+
echo "You can now connect with:"
59+
echo " ssh opencode@${TAILSCALE_IP}"
60+
echo ""
61+
fi

‎check-tailscale.sh‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# Check Tailscale network status
3+
4+
set -euo pipefail
5+
6+
echo "=== Tailscale Network Status ==="
7+
echo ""
8+
9+
# Check Mac Tailscale
10+
echo "📱 Mac Tailscale:"
11+
if command -v tailscale &> /dev/null; then
12+
tailscale status 2>/dev/null || echo " ⚠️ Tailscale not running on Mac"
13+
else
14+
echo " ⚠️ Tailscale not installed on Mac"
15+
fi
16+
17+
echo ""
18+
19+
# Check if containers are running
20+
echo "🐳 Docker Containers:"
21+
if docker ps --format "table {{.Names}}\t{{.Status}}" | grep -E "(opencode_tailscale|opencode_with_ssh)"; then
22+
echo ""
23+
echo "📡 Container Tailscale Status:"
24+
docker exec opencode_tailscale tailscale status 2>/dev/null || echo " ⚠️ Tailscale not running in container"
25+
26+
echo ""
27+
echo "🌐 Container Tailscale IP:"
28+
if TAILSCALE_IP=$(docker exec opencode_tailscale tailscale ip -4 2>/dev/null); then
29+
# Validate Tailscale IP format (100.x.x.x range)
30+
if [[ "$TAILSCALE_IP" =~ ^100\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
31+
echo " IP: $TAILSCALE_IP"
32+
echo ""
33+
echo " SSH Command: ssh opencode@$TAILSCALE_IP"
34+
else
35+
echo " ⚠️ Invalid Tailscale IP format: $TAILSCALE_IP"
36+
echo " ⚠️ Expected 100.x.x.x range"
37+
fi
38+
else
39+
echo " ⚠️ No IP assigned yet (Tailscale still connecting?)"
40+
fi
41+
else
42+
echo " ⚠️ Containers not running"
43+
echo ""
44+
echo " Start with: ./setup-tailscale-ssh.sh"
45+
fi
46+
47+
echo ""
48+
echo "================================="

‎docker-compose.tailscale.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
services:
2+
# Tailscale VPN sidecar
3+
tailscale:
4+
image: tailscale/tailscale:latest
5+
container_name: opencode_tailscale
6+
hostname: opencode-server
7+
environment:
8+
- TS_AUTHKEY=${TS_AUTHKEY} # From user's Tailscale admin
9+
- TS_STATE_DIR=/var/lib/tailscale
10+
- TS_USERSPACE=false
11+
volumes:
12+
- tailscale-state:/var/lib/tailscale
13+
- /dev/net/tun:/dev/net/tun
14+
cap_add:
15+
- NET_ADMIN
16+
- SYS_MODULE
17+
networks:
18+
- remory_network
19+
restart: unless-stopped
20+
21+
# OpenCode with SSH server
22+
opencode:
23+
build:
24+
context: .
25+
dockerfile: Dockerfile.opencode-ssh
26+
container_name: opencode_with_ssh
27+
network_mode: "service:tailscale" # Share Tailscale's network
28+
depends_on:
29+
- tailscale
30+
volumes:
31+
- ~/git:/workspace
32+
- ~/.gitconfig:/home/opencode/.gitconfig:ro
33+
- opencode-ssh:/home/opencode/.ssh
34+
environment:
35+
- OPENCODE_CONFIG=/config/opencode.container.json
36+
restart: unless-stopped
37+
38+
volumes:
39+
tailscale-state:
40+
driver: local
41+
opencode-ssh:
42+
driver: local
43+
44+
networks:
45+
remory_network:
46+
external: true

0 commit comments

Comments
 (0)