WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9203691

Browse files
committed
feat: testing with docker-compose sshopk config
1 parent e1ec6a9 commit 9203691

File tree

8 files changed

+101
-19
lines changed

8 files changed

+101
-19
lines changed

Caddyfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
order coraza_waf first
3+
auto_https disable_redirects
34
}
45

56
# --- WAF for MinIO UI (port 8080) ---
@@ -60,7 +61,7 @@
6061
}
6162
}
6263

63-
# --- Keycloak Proxy (port 8082) ---
64+
# --- Keycloak Proxy HTTP (port 8082) ---
6465
:8082 {
6566
reverse_proxy keycloak:8080 {
6667
header_up Host localhost:8082
@@ -77,6 +78,25 @@
7778
}
7879
}
7980

81+
# --- Keycloak Proxy HTTPS (port 8443) ---
82+
localhost:8443 {
83+
tls internal
84+
85+
reverse_proxy keycloak:8080 {
86+
header_up Host localhost:8443
87+
header_up X-Real-IP {remote}
88+
header_up X-Forwarded-Proto https
89+
header_up X-Forwarded-Host localhost:8443
90+
header_up X-Forwarded-Port 8443
91+
}
92+
93+
log {
94+
output stdout
95+
format json
96+
level INFO
97+
}
98+
}
99+
80100
# --- WAF for MinIO API (port 8081) ---
81101
:8081 {
82102
handle /health {

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ RUN addgroup -g 1001 -S caddy && \
2525
adduser -u 1001 -S caddy -G caddy
2626

2727
# Create directories with proper permissions
28-
RUN mkdir -p /etc/caddy /var/lib/caddy /var/log/caddy && \
29-
chown -R caddy:caddy /etc/caddy /var/lib/caddy /var/log/caddy
28+
RUN mkdir -p /etc/caddy /var/lib/caddy /var/log/caddy /data/caddy && \
29+
chown -R caddy:caddy /etc/caddy /var/lib/caddy /var/log/caddy /data/caddy
3030

3131
# Copy Caddyfile template
3232
COPY Caddyfile /etc/caddy/Caddyfile

Dockerfile.ssh-server

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y \
55
wget \
66
curl \
77
ca-certificates \
8+
socat \
89
&& rm -rf /var/lib/apt/lists/*
910

1011
RUN wget -qO /usr/local/bin/opkssh https://github.com/openpubkey/opkssh/releases/latest/download/opkssh-linux-amd64 && \
@@ -25,6 +26,14 @@ RUN mkdir -p /etc/opk /home/testuser/.opk && \
2526
chown testuser:testuser /home/testuser/.opk && \
2627
chmod 700 /home/testuser/.opk
2728

29+
RUN echo '# Issuer Client-ID expiration-policy\nhttps://localhost:8443/realms/minio_realm opkssh-client 24h' > /etc/opk/providers && \
30+
echo '# principal email/sub issuer\ntestuser [email protected] https://localhost:8443/realms/minio_realm' > /etc/opk/auth_id && \
31+
chown opksshuser:opksshuser /etc/opk/providers /etc/opk/auth_id && \
32+
chmod 640 /etc/opk/providers /etc/opk/auth_id
33+
2834
EXPOSE 2222
2935

30-
CMD ["/usr/sbin/sshd", "-D", "-p", "2222"]
36+
COPY docker-entrypoint.sh /docker-entrypoint.sh
37+
RUN chmod +x /docker-entrypoint.sh
38+
39+
ENTRYPOINT ["/docker-entrypoint.sh"]

TESTING-OPKSSH.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
This guide shows you how to test SSH authentication using OpenID Connect (OIDC) via Keycloak.
44

5+
## ⚠️ Important: HTTPS Requirement
6+
7+
**opkssh requires HTTPS for the OIDC issuer.** The current setup uses HTTP for local testing which is not compatible with opkssh v0.10.0+.
8+
9+
### Options:
10+
11+
1. **Use a cloud Keycloak instance with HTTPS** (Recommended for real testing)
12+
2. **Wait for HTTP support** in future opkssh versions
13+
3. **Use an HTTPS proxy/tunnel** like ngrok or Cloudflare Tunnel
14+
15+
## Current Status
16+
17+
The setup is configured but **cannot be tested locally** due to the HTTPS requirement. The following files are ready:
18+
19+
- ✅ Keycloak OIDC client (`opkssh-client`) configured
20+
- ✅ SSH test server with opkssh installed
21+
- ✅ Authorization rules configured
22+
- ❌ HTTPS endpoint (required by opkssh)
23+
24+
## Alternative: Test with External SSH Server
25+
26+
If you have an external SSH server with a public IP, you can install opkssh there and use your local Keycloak with an HTTPS tunnel.
27+
28+
### Using ngrok (Quick Setup)
29+
30+
```bash
31+
# Install ngrok
32+
brew install ngrok # macOS
33+
# or download from https://ngrok.com/
34+
35+
# Create HTTPS tunnel to Keycloak
36+
ngrok http 8082
37+
```
38+
39+
Copy the HTTPS URL (e.g., `https://abc123.ngrok.io`) and use it as your issuer.
40+
541
## What is opkssh?
642

743
opkssh enables SSH authentication using OpenID Connect identities (like `[email protected]`) instead of traditional SSH keys. Your OIDC identity token is embedded in a temporary SSH certificate that expires after 24 hours.
@@ -61,19 +97,16 @@ docker-compose ps
6197

6298
### Step 1: Login with opkssh
6399

64-
Run this command to authenticate with Keycloak:
100+
**Note:** This step currently fails due to HTTPS requirement. Example command:
65101

66102
```bash
67-
opkssh login --provider="http://localhost:8082/realms/minio_realm,opkssh-client"
103+
opkssh login --provider="https://your-keycloak-with-https.com/realms/minio_realm,opkssh-client"
68104
```
69105

70-
**What happens:**
71-
1. Your browser opens to Keycloak login page
72-
2. Login with:
73-
- **Username:** `testuser`
74-
- **Password:** `password`
75-
3. opkssh generates an SSH certificate at `~/.ssh/id_ecdsa`
76-
4. The certificate contains your OIDC identity token from Keycloak
106+
Error you'll see with HTTP:
107+
```
108+
Error: invalid provider issuer value. Expected issuer to start with 'https://'
109+
```
77110

78111
### Step 2: SSH to the Test Server
79112

docker-compose.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ services:
6969
coraza-waf:
7070
image: coraza-waf-local:latest
7171
container_name: coraza-waf
72+
user: root
7273
volumes:
7374
- ./Caddyfile:/etc/caddy/Caddyfile
75+
- caddy-data:/data
7476
ports:
7577
- "8080:8080"
7678
- "8081:8081"
7779
- "8082:8082"
80+
- "8443:8443"
7881
depends_on:
7982
- minio
8083
- keycloak
@@ -88,9 +91,10 @@ services:
8891
container_name: ssh-test-server
8992
ports:
9093
- "2222:2222"
94+
extra_hosts:
95+
- "localhost:host-gateway"
9196
volumes:
92-
- ./opk-providers:/etc/opk/providers:ro
93-
- ./opk-auth_id:/etc/opk/auth_id:ro
97+
- caddy-data:/caddy-data:ro
9498
depends_on:
9599
- keycloak
96100
- coraza-waf
@@ -101,6 +105,7 @@ volumes:
101105
minio-data:
102106
postgres_data:
103107
keycloak-data:
108+
caddy-data:
104109

105110
networks:
106111
minio-net:

docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Wait for Caddy CA certificate and install it
4+
echo "Waiting for Caddy CA certificate..."
5+
for i in {1..30}; do
6+
if [ -f /caddy-data/caddy/pki/authorities/local/root.crt ]; then
7+
cp /caddy-data/caddy/pki/authorities/local/root.crt /usr/local/share/ca-certificates/caddy-root.crt
8+
update-ca-certificates
9+
echo "Caddy CA certificate installed"
10+
break
11+
fi
12+
sleep 1
13+
done
14+
15+
# Start socat to proxy localhost:8443 to coraza-waf:8443
16+
socat TCP-LISTEN:8443,bind=127.0.0.1,fork,reuseaddr TCP:coraza-waf:8443 &
17+
18+
# Start SSH daemon
19+
exec /usr/sbin/sshd -D -p 2222

opk-auth_id

Lines changed: 0 additions & 2 deletions
This file was deleted.

opk-providers

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)