darkfire514 commited on
Commit
6af0519
·
verified ·
1 Parent(s): cf4f9f7

Upload 2 files

Browse files
Files changed (2) hide show
  1. oauth2-proxy.cfg +4 -3
  2. start.sh +16 -6
oauth2-proxy.cfg CHANGED
@@ -4,11 +4,9 @@
4
  http_address = "127.0.0.1:4180"
5
 
6
  # Email Domains
7
- # We restrict access using authenticated_emails_file, so email_domains can be "*"
8
  email_domains = ["*"]
9
 
10
  # Authenticated Emails File
11
- # Only emails listed in this file will be allowed to login
12
  authenticated_emails_file = "/etc/oauth2-proxy/authenticated_emails.txt"
13
 
14
  # Cookie Settings
@@ -22,11 +20,14 @@ cookie_expire = "168h"
22
  provider = "github"
23
 
24
  # Upstreams
 
 
25
  upstreams = [
26
- "http://127.0.0.1:4180/static"
27
  ]
28
 
29
  # Logging
30
  request_logging = true
31
  auth_logging = true
32
  standard_logging = true
 
 
4
  http_address = "127.0.0.1:4180"
5
 
6
  # Email Domains
 
7
  email_domains = ["*"]
8
 
9
  # Authenticated Emails File
 
10
  authenticated_emails_file = "/etc/oauth2-proxy/authenticated_emails.txt"
11
 
12
  # Cookie Settings
 
20
  provider = "github"
21
 
22
  # Upstreams
23
+ # Point to ttyd, although Nginx handles the actual proxying
24
+ # This prevents startup errors if no upstream is defined
25
  upstreams = [
26
+ "http://127.0.0.1:7681"
27
  ]
28
 
29
  # Logging
30
  request_logging = true
31
  auth_logging = true
32
  standard_logging = true
33
+ show_debug_on_error = true
start.sh CHANGED
@@ -1,5 +1,8 @@
1
  #!/bin/bash
2
 
 
 
 
3
  # 确保必要的环境变量已设置
4
  if [ -z "$OAUTH2_PROXY_CLIENT_ID" ] || [ "$OAUTH2_PROXY_CLIENT_ID" == "your_client_id" ]; then
5
  echo "Error: OAUTH2_PROXY_CLIENT_ID is not set in Hugging Face Secrets!"
@@ -16,15 +19,12 @@ if [ -z "$OAUTH2_PROXY_COOKIE_SECRET" ]; then
16
  fi
17
 
18
  # 生成白名单文件
19
- # 我们从环境变量 ALLOWED_USERS 中读取邮箱列表(逗号分隔)
20
- # 并将其写入 oauth2-proxy 期望的文件格式(每行一个邮箱)
21
  mkdir -p /etc/oauth2-proxy
22
  if [ -n "$ALLOWED_USERS" ]; then
23
  echo "Generating allowed users list..."
24
  echo "$ALLOWED_USERS" | tr ',' '\n' > /etc/oauth2-proxy/authenticated_emails.txt
25
  else
26
- echo "Warning: ALLOWED_USERS is not set! Anyone with a GitHub account can login."
27
- # 创建一个空文件,或者允许所有(取决于配置,但为了安全建议留空或报错)
28
  touch /etc/oauth2-proxy/authenticated_emails.txt
29
  fi
30
 
@@ -32,14 +32,24 @@ fi
32
  echo "Starting ttyd on 127.0.0.1:7681..."
33
  ttyd -p 7681 -i 127.0.0.1 -W bash &
34
 
 
 
 
35
  # 2. 启动 oauth2-proxy (本地监听)
36
- # 我们直接在命令行传递 Client ID 和 Secret,确保它们被正确读取
37
  echo "Starting oauth2-proxy on 127.0.0.1:4180..."
 
38
  oauth2-proxy \
39
  --config=oauth2-proxy.cfg \
40
  --client-id="$OAUTH2_PROXY_CLIENT_ID" \
41
  --client-secret="$OAUTH2_PROXY_CLIENT_SECRET" \
42
- --cookie-secret="$OAUTH2_PROXY_COOKIE_SECRET" &
 
 
 
 
 
 
 
43
 
44
  # 3. 启动 Nginx (对外监听 7860)
45
  echo "Starting Nginx on port 7860..."
 
1
  #!/bin/bash
2
 
3
+ # 打印所有命令,方便调试
4
+ set -x
5
+
6
  # 确保必要的环境变量已设置
7
  if [ -z "$OAUTH2_PROXY_CLIENT_ID" ] || [ "$OAUTH2_PROXY_CLIENT_ID" == "your_client_id" ]; then
8
  echo "Error: OAUTH2_PROXY_CLIENT_ID is not set in Hugging Face Secrets!"
 
19
  fi
20
 
21
  # 生成白名单文件
 
 
22
  mkdir -p /etc/oauth2-proxy
23
  if [ -n "$ALLOWED_USERS" ]; then
24
  echo "Generating allowed users list..."
25
  echo "$ALLOWED_USERS" | tr ',' '\n' > /etc/oauth2-proxy/authenticated_emails.txt
26
  else
27
+ echo "Warning: ALLOWED_USERS is not set! Creating empty whitelist."
 
28
  touch /etc/oauth2-proxy/authenticated_emails.txt
29
  fi
30
 
 
32
  echo "Starting ttyd on 127.0.0.1:7681..."
33
  ttyd -p 7681 -i 127.0.0.1 -W bash &
34
 
35
+ # 等待 ttyd 启动
36
+ sleep 2
37
+
38
  # 2. 启动 oauth2-proxy (本地监听)
 
39
  echo "Starting oauth2-proxy on 127.0.0.1:4180..."
40
+ # 将日志重定向到标准输出,以便在 Space Logs 中查看
41
  oauth2-proxy \
42
  --config=oauth2-proxy.cfg \
43
  --client-id="$OAUTH2_PROXY_CLIENT_ID" \
44
  --client-secret="$OAUTH2_PROXY_CLIENT_SECRET" \
45
+ --cookie-secret="$OAUTH2_PROXY_COOKIE_SECRET" \
46
+ --email-domain="*" \
47
+ --upstream="http://127.0.0.1:7681" \
48
+ --http-address="127.0.0.1:4180" \
49
+ 2>&1 &
50
+
51
+ # 等待 oauth2-proxy 启动
52
+ sleep 2
53
 
54
  # 3. 启动 Nginx (对外监听 7860)
55
  echo "Starting Nginx on port 7860..."