Skip to content

Commit 54d0a4f

Browse files
committed
新增 GitHub Action ssh-keyscan not found 問題修復筆記,分析根本原因並提供解決方案
1 parent d76a165 commit 54d0a4f

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: "[踩雷筆記] GitHub Action ssh-keyscan not found 問題修復"
3+
date: 2025/07/22 13:42:30
4+
tags:
5+
- 踩雷筆記
6+
---
7+
8+
9+
## 前情提要
10+
11+
GitHub Action `marsen/[email protected]` 之前運行正常,但最近開始失敗,錯誤訊息:
12+
13+
```text
14+
/usr/app/entrypoint.sh: 9: /usr/app/entrypoint.sh: ssh-keyscan: not found
15+
```
16+
17+
## 問題分析
18+
19+
### 初步檢查
20+
21+
檢查 entrypoint.sh 第9行:
22+
23+
```bash
24+
ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts
25+
```
26+
27+
檢查 Dockerfile 套件安裝:
28+
29+
```dockerfile
30+
FROM node:20-buster-slim
31+
RUN apt-get install -y git openssh-client
32+
```
33+
34+
明明有安裝 `openssh-client`,為什麼找不到 `ssh-keyscan`
35+
36+
### 根本原因
37+
38+
**Debian Buster 生命週期結束**
39+
40+
- `node:20-buster-slim` 基於 Debian 10 (Buster)
41+
- Debian 10 於 2024年8月達到 End of Life
42+
- 套件庫不再維護,套件結構可能變化
43+
44+
**OpenSSH 套件重組**
45+
46+
- 2024年 OpenSSH 多個版本發布 (9.7, 9.9)
47+
- `ssh-keyscan` 可能從 `openssh-client` 移到其他套件
48+
49+
**Docker 映像自動更新**
50+
51+
- Docker Hub 會自動重建映像
52+
- 新版本移除不必要工具以減少攻擊面
53+
54+
## 解決方案
55+
56+
### 快速修復(不推薦)
57+
58+
```dockerfile
59+
RUN apt-get install -y git openssh-client openssh-server
60+
```
61+
62+
雖然可行,但安裝 SSH 伺服器會增加攻擊面。
63+
64+
### 正確解法
65+
66+
升級基底映像到支援版本:
67+
68+
```dockerfile
69+
# 從過期版本
70+
FROM node:20-buster-slim
71+
72+
# 升級到安全版本
73+
FROM node:20-bookworm-slim
74+
```
75+
76+
完整的 Dockerfile 修改:
77+
78+
```dockerfile
79+
FROM node:20-bookworm-slim
80+
81+
LABEL version="1.0.12"
82+
LABEL repository="https://github.com/marsen/hexo-action"
83+
LABEL homepage="https://blog.marsen.me"
84+
LABEL maintainer="marsen.lin <[email protected]>"
85+
86+
WORKDIR /usr/app
87+
88+
COPY entrypoint.sh /usr/app/entrypoint.sh
89+
COPY sync_deploy_history.js /usr/app/sync_deploy_history.js
90+
91+
# 安全且最佳化的套件安裝
92+
RUN apt-get update > /dev/null && \
93+
apt-get install -y git openssh-client > /dev/null && \
94+
apt-get clean && \
95+
rm -rf /var/lib/apt/lists/* && \
96+
chmod +x /usr/app/entrypoint.sh
97+
98+
ENTRYPOINT ["/usr/app/entrypoint.sh"]
99+
```
100+
101+
## 關鍵改進
102+
103+
1. **基底映像升級**:buster-slim → bookworm-slim
104+
- Debian 12 取代已 EOL 的 Debian 10
105+
- 更好的安全性和長期支援
106+
107+
2. **最小權限原則**:只安裝 openssh-client
108+
- 包含所需的 ssh-keyscan 工具
109+
- 不安裝 SSH 伺服器,減少攻擊面
110+
111+
3. **Docker 最佳實踐**
112+
- 清理 apt 快取減少映像大小
113+
- 使用 && 合併 RUN 指令減少層數
114+
115+
## 預防措施
116+
117+
- 使用具體版本標籤而非 latest
118+
- 定期檢查基底映像的生命週期
119+
- 建立自動化測試驗證依賴可用性
120+
121+
## 小結
122+
123+
這次問題的核心是基底映像過期導致的連鎖反應。在容器化開發中,外部依賴的變化往往會影響既有系統。解決方案不是快速修復,而是從根本上升級到安全的長期支援版本。
124+
125+
除錯關鍵思路:分析「為什麼之前可以,現在不行」,往往能找到外部環境變化的線索。
126+
127+
(fin)

0 commit comments

Comments
 (0)