lighthouse-fw
一个面向 Tencent Cloud Lighthouse 防火墙白名单更新 的 Python 包,支持:
uvx lighthouse-fw/lhfw无参数进入交互式 CLI 菜单- 添加腾讯云账号后自动扫描全部地域的轻量实例,勾选导入
- 从云上防火墙发现 SSH 类规则(22 / 2222 / 备注含 ssh)并勾选托管
lhfw run预览 diff,--apply写入前显式确认- Windows / Linux / macOS 跨平台配置布局
- 密钥优先系统钥匙串,无法使用时回退到本地加密文件
产品交互说明见 docs/product-design.md。
English summary
lighthouse-fw is a Python package for managing Tencent Cloud Lighthouse SSH firewall allowlists. The default no-arg entry is an interactive CLI: add a Tencent Cloud account, scan every region for Lighthouse instances, import SSH-like firewall rules, then preview and apply the current public IP. Parameterized commands such as lhfw run --apply --yes remain for scripts.
安装与运行
1. 直接用 uvx
无参数进入交互式菜单(没有账号时直接添加账号):
uvx lighthouse-fw
直接运行 CLI 子命令:
uvx lighthouse-fw doctor
uvx lighthouse-fw run
2. 安装成工具命令
uv tool install lighthouse-fw
lhfw doctor
lhfw run
3. 仓库内本地运行
uv run lhfw doctor
uv run lhfw run
默认行为
uvx lighthouse-fw/lhfw:无参数进入交互式 CLI。没有账号时走「添加账号」;已有账号时出现菜单(默认第 1 项:更新防火墙白名单)- 添加账号只需要名称和 SecretId / SecretKey,随后扫描全部地域勾选实例,再勾选云上已有的 SSH 类规则
- 某台机器没有 SSH 类规则时仍然导入,白名单更新对它是空操作,并提示一句
lhfw run:不带筛选条件时,默认运行所有 enabled 的 serverlhfw run --apply:会先做 diff 预览,再要求显式确认lhfw doctor:检查本地环境、密钥后端,以及账号级 API 可达性
配置模型
当前包的持久化配置由三部分组成:
- 普通配置:
config.toml - 密钥:优先系统钥匙串;无安全后端时回退到本地加密文件
secrets.bin - 本地口令/密钥文件:
secrets.key
server 支持:
enabled状态- 多个自由标签
tags - 完整
managed_rules
每条 managed_rules 支持:
protocolportcidractiondescriptionreplace_existing_same_port
常用 CLI
对外只有这些命令。精细改动(关某台机器、加非 SSH 端口、改 IP 查询源等)直接编辑 config.toml。
lhfw # 交互菜单;没有账号时直接添加
lhfw account add # 添加腾讯云账号并导入
lhfw sync --account work # 同步新服务器 / SSH 规则
lhfw sync --account work --all
lhfw run # 预览
lhfw run --apply # 预览后确认写入
lhfw run --apply --yes # 无人值守写入
lhfw run --tag prod --tag sg
lhfw doctor
lhfw config show
lhfw config history
交互式 CLI
无参数启动后用方向键选择:
- 更新防火墙白名单
- 添加腾讯云账号
- 同步服务器和规则
- 查看当前配置
- 退出
安全说明
- 优先使用系统钥匙串
- 如果当前平台没有安全 keyring backend,会回退到本地加密文件
- SecretId / SecretKey 在交互输入时隐藏
doctor默认是只读检查,不会逐台 server 修改任何东西
腾讯云权限要求
本工具通过腾讯云 API 管理轻量应用服务器的防火墙规则,需要为 API 密钥对应的子账号授予以下全部权限,缺一不可。
操作步骤
- 打开 访问管理 → 策略
- 新建自定义策略,选择「按策略语法创建」,粘贴下方 JSON
- 将策略关联到 API 密钥对应的子账号
所需权限列表
预设策略(基础只读,doctor 验证需要):
| 策略名 | 说明 |
|---|---|
QcloudLighthouseReadOnlyAccess |
轻量应用服务器只读权限(包含 DescribeInstances 等) |
自定义策略(防火墙规则管理,run 命令需要):
{
"version": "2.0",
"statement": [
{
"effect": "allow",
"resource": ["*"],
"action": [
"lighthouse:DescribeFirewallRules",
"lighthouse:DescribeFirewallRulesTemplate",
"lighthouse:DescribePresetFirewallRules",
"lighthouse:CheckFirewallRules",
"lighthouse:CheckInstanceFirewallPorts",
"lighthouse:DescribeFirewallTemplateApplyRecords",
"lighthouse:DescribeFirewallTemplateQuota",
"lighthouse:DescribeFirewallTemplateRuleQuota",
"lighthouse:DescribeFirewallTemplateRules",
"lighthouse:DescribeFirewallTemplates",
"lighthouse:ApplyFirewallTemplate",
"lighthouse:CreateFirewallRules",
"lighthouse:CreateFirewallTemplate",
"lighthouse:CreateFirewallTemplateRules",
"lighthouse:DeleteFirewallRules",
"lighthouse:DeleteFirewallTemplate",
"lighthouse:DeleteFirewallTemplateRules",
"lighthouse:ModifyFirewallRuleDescription",
"lighthouse:ModifyFirewallRules",
"lighthouse:ModifyFirewallTemplate",
"lighthouse:ReplaceFirewallTemplateRule",
"lighthouse:ResetFirewallTemplateRules"
]
}
]
}
权限与命令的对应关系
| 命令 / 功能 | 所需权限 |
|---|---|
lhfw doctor |
QcloudLighthouseReadOnlyAccess |
lhfw run(预览 diff) |
QcloudLighthouseReadOnlyAccess + 自定义策略中的读操作 |
lhfw run --apply(写入规则) |
QcloudLighthouseReadOnlyAccess + 自定义策略中的全部操作 |
开发与测试
uv run python -m unittest discover -s tests -v
uv run lhfw doctor
发布
项目按 PyPI 发布路径设计:
- 包名:
lighthouse-fw - 命令名:
lhfw - 版本 tag:
v1.2.3 - 认证:GitHub OIDC Trusted Publishing
推送版本 tag 后,GitHub Actions 会自动构建并发布到 PyPI。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lighthouse_fw-0.3.0.tar.gz.
File metadata
- Download URL: lighthouse_fw-0.3.0.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb177d5c7f04a0800ecbd03c2beba4646e58f65359d3e3dbfddad788f922f276
|
|
| MD5 |
5da6e9664dc4c7caa8b4a84cad483506
|
|
| BLAKE2b-256 |
dc6faa3cc2252cb829cdd03e63e913c3f4864b4a472748d340cd603558d9c7c1
|
Provenance
The following attestation bundles were made for lighthouse_fw-0.3.0.tar.gz:
Publisher:
lighthouse-fw-publish.yml on star-plan/tencent-lighthouse-fw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lighthouse_fw-0.3.0.tar.gz -
Subject digest:
bb177d5c7f04a0800ecbd03c2beba4646e58f65359d3e3dbfddad788f922f276 - Sigstore transparency entry: 2678502856
- Sigstore integration time:
-
Permalink:
star-plan/tencent-lighthouse-fw@39c18e9bb71ac8890dc69704793bd59ed0b68ea9 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/star-plan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
lighthouse-fw-publish.yml@39c18e9bb71ac8890dc69704793bd59ed0b68ea9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lighthouse_fw-0.3.0-py3-none-any.whl.
File metadata
- Download URL: lighthouse_fw-0.3.0-py3-none-any.whl
- Upload date:
- Size: 31.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
648a9c6dd4eb58e90161e0d0262fb787d76574a00724c27e5a8a29ecb6f99112
|
|
| MD5 |
91f77443dc8723b59118e40be4e9578b
|
|
| BLAKE2b-256 |
b1daac3260e6062340f1f1b1d00d43b2ab8cd15d2c833420a764ea4fd81396ed
|
Provenance
The following attestation bundles were made for lighthouse_fw-0.3.0-py3-none-any.whl:
Publisher:
lighthouse-fw-publish.yml on star-plan/tencent-lighthouse-fw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lighthouse_fw-0.3.0-py3-none-any.whl -
Subject digest:
648a9c6dd4eb58e90161e0d0262fb787d76574a00724c27e5a8a29ecb6f99112 - Sigstore transparency entry: 2678502895
- Sigstore integration time:
-
Permalink:
star-plan/tencent-lighthouse-fw@39c18e9bb71ac8890dc69704793bd59ed0b68ea9 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/star-plan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
lighthouse-fw-publish.yml@39c18e9bb71ac8890dc69704793bd59ed0b68ea9 -
Trigger Event:
push
-
Statement type: