# Blockchain Node Hardening

> 🛡️ 区块链节点安全加固 (Blockchain Node Hardening)

- Skill: `yufeifeio/blockchain-node-hardening` (Agent Skill)
- Install (CLI): `npx get-skill add yufeifeio/blockchain-node-hardening`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yufeifeio/blockchain-node-hardening/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: Yufeifeio (https://skillmd.com/u/yufeifeio)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/yufeifeio/blockchain-node-hardening

---


# 🛡️ 区块链节点安全加固 (Blockchain Node Hardening)
# 🛡️ 区块链节点安全加固 (Blockchain Node Hardening)

## 概述
对区块链节点进行全面安全加固，包括节点配置安全、P2P网络安全、API防护、密钥管理和监控告警。

## 核心技能

### 1. Geth (Ethereum执行层) 加固

```bash
# Geth安全启动配置
geth \
  --mainnet \
  --datadir /data/ethereum \
  --http \
  --http.addr 127.0.0.1 \          # ✅ 仅绑定localhost
  --http.port 8545 \
  --http.api eth,net,web3 \        # ❌ 避免: personal, admin, debug
  --http.vhosts localhost \        # ✅ 虚拟主机限制
  --http.corsdomain "" \           # ✅ 禁用CORS（API模式）
  --ws \
  --ws.addr 127.0.0.1 \
  --ws.port 8546 \
  --ws.api eth,net \               # 最小API
  --ws.origins "http://localhost" \
  --authrpc.addr 127.0.0.1 \       # ✅ 执行层-共识层通信
  --authrpc.port 8551 \
  --authrpc.jwtsecret /data/jwt.hex \  # ✅ JWT认证
  --txpool.accountslots 16 \       # 交易池限制
  --txpool.globalslots 4096 \
  --cache 4096 \
  --maxpeers 50 \                  # 最大Peers数
  --syncmode snap                  # ✅ Snap同步（安全高效）

# ❌ 不安全配置示例
geth --http --http.addr 0.0.0.0 --http.api personal,admin --allow-insecure-unlock
# 上述配置会暴露管理API并允许远程解锁账户！
```

### 2. 节点API安全

```bash
# Nginx反向代理 - API保护
cat << 'NGINX' > /etc/nginx/sites-available/eth-node
server {
    listen 8545 ssl;
    server_name api.yournode.com;
    
    ssl_certificate /etc/ssl/certs/node.crt;
    ssl_certificate_key /etc/ssl/private/node.key;
    
    # API Key验证
    location / {
        if ($http_x_api_key != $API_KEY) {
            return 401;
        }
        
        proxy_pass http://127.0.0.1:8545;
        proxy_set_header Host $host;
    }
    
    # 速率限制
    limit_req zone=apilimit burst=20 nodelay;
}
NGINX

# 使用iptables保护
# 仅允许特定IP访问RPC
iptables -A INPUT -p tcp --dport 8545 -s 192.168.1.0/24 -j ACCEPT
iptables -A INPUT -p tcp --dport 8545 -j DROP

# P2P端口限制
iptables -A INPUT -p tcp --dport 30303 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport 30303 -m state --state ESTABLISHED -j ACCEPT
```

### 3. 验证器节点安全

```bash
# Lighthouse验证器安全配置
# 使用远程签名
lighthouse vc \
  --network mainnet \
  --beacon-nodes http://127.0.0.1:5052 \
  --builder http://127.0.0.1:8662 \
  --validators-dir /data/validators \
  --graffiti "NodeName"

# 使用Web3Signer远程签名
# 运行Web3Signer
docker run -d --name web3signer \
  -p 9000:9000 \
  -v /data/web3signer:/data \
  consensys/web3signer:latest \
  eth2 \
  --chain-id=1 \
  --keystore-path=/data/keystores \
  --slashing-protection-db-url=jdbc:postgresql://db:5432/slashing \
  --slashing-protection-db-username=user \
  --slashing-protection-db-password=password

# 验证器密钥安全
# 1. 使用BIP39助记词生成密钥
# 2. 助记词离线存储（硬件钱包/纸钱包）
# 3. 密钥加密存储并定期备份

# 撤回地址设置
# 0x01: 智能合约撤回地址（推荐）
# 0x00: BLS撤回地址（基本）
```

### 4. 节点监控与告警

```yaml
# Prometheus + Grafana节点监控
# 节点指标采集
scrape_configs:
  - job_name: 'ethereum-node'
    static_configs:
      - targets: ['localhost:6060']  # Geth metrics
  - job_name: 'beacon-node'
    static_configs:
      - targets: ['localhost:5052']  # Lighthouse metrics

# 关键监控指标
# Geth:
# - eth_syncing: 同步状态
# - p2p_peers: 连接对等节点数
# - eth_blockNumber: 当前区块高度
# - chain_head_header: 最新区块头

# Lighthouse:
# - validator_count: 验证器数量
# - slot: 当前slot
# - epoch: 当前epoch
# - finalized_epoch: 最终性epoch

# 告警规则示例
groups:
  - name: eth-node-alerts
    rules:
      - alert: NodeNotSyncing
        expr: eth_syncing == 1
        for: 30m
        labels:
          severity: critical
        annotations:
          description: "Ethereum节点同步异常 {{ $labels.instance }}"
      
      - alert: PeerCountLow
        expr: p2p_peers < 5
        for: 15m
        labels:
          severity: warning
```

### 5. 节点安全基线

| # | 安全项 | 建议配置 | 严重程度 |
|:---:|:---|:---|:---:|
| 1 | HTTP-RPC绑定地址 | 127.0.0.1 | 🔴 严重 |
| 2 | 暴露的API | eth,net,web3 (最小) | 🔴 严重 |
| 3 | JWT认证 | 必须配置 | 🔴 严重 |
| 4 | 防火墙规则 | 限制P2P和RPC端口 | 🟠 高危 |
| 5 | TLS证书 | API端口使用HTTPS | 🟠 高危 |
| 6 | 速率限制 | 配置RPC速率限制 | 🟡 中危 |
| 7 | 日志审计 | 启用详细日志 | 🟡 中危 |
| 8 | 磁盘加密 | 数据目录LUKS加密 | 🟡 中危 |
| 9 | 自动更新 | 关注安全更新 | 🟠 高危 |
| 10 | 备份策略 | 密钥和数据库定期备份 | 🟠 高危 |

## 常用工具

| 工具 | 用途 | 链接 |
|:---|:---|:---|
| Geth | Ethereum执行客户端 | https://geth.ethereum.org/ |
| Lighthouse | ETH2共识客户端 | https://lighthouse.sigmaprime.io/ |
| Web3Signer | 远程密钥签名 | https://docs.web3signer.consensys.net/ |
| Prometheus | 监控采集 | https://prometheus.io/ |
| Grafana | 可视化监控 | https://grafana.com/ |
| ethdo | 验证器管理工具 | https://github.com/wealdtech/ethdo |

## 参考资源
- [Geth Security Guide](https://geth.ethereum.org/docs/fundamentals/security)
- [Ethereum Staking Security](https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/)
- [Lighthouse Security Best Practices](https://lighthouse-book.sigmaprime.io/)
- [Validator Security Checklist](https://eth-docker.net/docs/About/Security/)

