跳至主要內容
進階

Commando & Runes CLN 遠程控制

了解 Core Lightning 的 Commando 插件和 Runes 認證系統,實現安全的遠程節點控制。

10 分鐘

什麼是 Commando?

Commando 是 Core Lightning 的內建插件,允許通過閃電網路本身遠程控制節點。 結合 Runes 認證系統,提供安全的無服務器遠程訪問。

無需額外連接: Commando 使用閃電網路的洋蔥訊息傳輸命令,不需要開放額外端口或 VPN。

Runes 認證系統

Runes vs Macaroons

Similarities:
兩者都是:
  • 可委託的認證令牌
  • 支援添加限制(restrictions)
  • 不能移除已有限制
  • 密碼學驗證完整性

Runes 特點:
  • 專為 CLN 設計
  • 更簡潔的格式
  • 支援複雜的條件表達式
  • 原生整合 Commando

Rune Structure:
rune = base64(
  sha256(secret + restrictions) +
  restrictions_string
)

Restriction Examples:
  method=listpeers       // 只允許 listpeers 命令
  method^list            // 允許所有 list* 命令
  time<1700000000        // 時間限制
  rate=10                // 每分鐘最多 10 次

使用 Commando

Commando Operations

Creating a Rune:

# 創建無限制的 rune(危險!)
lightning-cli commando-rune

# 創建只讀 rune
lightning-cli commando-rune restrictions='["method^list"]'

# 創建有時間限制的 rune
lightning-cli commando-rune restrictions='["time<1700000000"]'

Remote Command Execution:

# 從另一個節點執行命令
lightning-cli commando \
  peer_id=<target_node_id> \
  rune=<rune_string> \
  method=listpeers

# 使用 lnmessage(Python 庫)
from lnmessage import LNMessage
ln = LNMessage(node_id, rune)
result = ln.call("listpeers")

安全考量

Rune Security Best Practices

Least Privilege:

# 只允許特定命令
restrictions='["method=getinfo|method=listfunds"]'

# 限制參數
restrictions='["method=pay", "pmsatoshi<1000000"]'

Time and Rate Limits:

# 24 小時後過期
restrictions='["time<'$(( $(date +%s) + 86400 ))'"]'

# 限制調用頻率
restrictions='["rate=10"]'  // 每分鐘 10 次

優點

無需開放端口、使用閃電網路加密、靈活的權限控制。

用途

移動錢包後端、監控工具、自動化腳本。

Rune 保管: Rune 是敏感的認證令牌,應像密碼一樣妥善保管。洩漏的 Rune 應立即撤銷。

相關資源

已複製連結
已複製到剪貼簿