ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

Authelia CLI 实战指南:authelia storage user 命令族——用户 TOTP、WebAuthn 与不透明标识符的存储级管理

Authelia CLI 实战指南:authelia storage user 命令族——用户 TOTP、WebAuthn 与不透明标识符的存储级管理 Authelia CLI 实战指南authelia storage user 命令族——用户 TOTP、WebAuthn 与不透明标识符的存储级管理【免费下载链接】autheliaThe Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready.项目地址: https://gitcode.com/GitHub_Trending/au/autheliaauthelia storage user是 Authelia CLI 中面向 SQL 存储层的管理命令组用于直接查看、生成、导入、导出和删除用户级安全配置TOTP、WebAuthn 凭据、不透明标识符。阅读本文后你将掌握该命令族完整的子命令树、全部命令行参数及其默认值、与配置文件键的一一映射关系以及一套可用于备份、迁移和批量运维的实战流程。命令定位与整体结构authelia storage user隶属于authelia storage命令组后者被定义为“Manage the Authelia storage”即通过一组高级操作与 Authelia 的 SQL 数据库直接交互——这些操作若手工执行会困难得多。authelia storage user本身的职责描述是Manages user settings. This subcommand allows modifying and exporting user settings. 管理用户设置。该子命令允许修改和导出用户设置。从源码结构看internal/commands/storage.go 中的newStorageUserCmd将该命令定义为不接受任何位置参数的纯分支节点Args: cobra.NoArgs并挂载了三个二级子命令子命令职责三级子命令identifiers管理用户不透明标识符opaque identifiersexport、import、generate、addtotp管理 TOTP 配置生成、删除、导入、导出generate、delete、import、export含csv/uri/pngwebauthn管理 WebAuthn 凭据列表、校验、删除、导入、导出list、verify、delete、export、import三个二级子命令的官方帮助示例均形如authelia storage user --help authelia storage user identifiers --help authelia storage user totp --help authelia storage user webauthn --help这些描述文本与示例字符串均定义在 internal/commands/const.gocmdAutheliaStorageUser*系列常量与仓库内的 CLI 参考文档 逐字对应。继承的全局选项存储连接参数运行authelia storage user --help时除自身的-h, --help外还会从父命令继承一组决定“连接到哪个存储”的选项-c, --config strings configuration files or directories to load, for more information run authelia -h authelia config (default [configuration.yml]) --config.experimental.filters strings list of filters to apply to all configuration files, for more information run authelia -h authelia filters --encryption-key string the storage encryption key to use --mysql.address string the MySQL server address (default tcp://127.0.0.1:3306) --mysql.database string the MySQL database name (default authelia) --mysql.password string the MySQL password --mysql.username string the MySQL username (default authelia) --postgres.address string the PostgreSQL server address (default tcp://127.0.0.1:5432) --postgres.database string the PostgreSQL database name (default authelia) --postgres.password string the PostgreSQL password --postgres.schema string the PostgreSQL schema name (default public) --postgres.username string the PostgreSQL username (default authelia) --sqlite.path string the SQLite database path这些选项支持三种主流后端SQLite--sqlite.path、MySQL--mysql.*、PostgreSQL--postgres.*另有--encryption-key提供存储加密密钥。典型的连接覆盖写法是authelia storage user --help --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 \ --postgres.address tcp://postgres:5432 --postgres.password autheliapw从源码结构看这些 CLI 选项并非各自为政而是被统一“翻译”为配置文件键。internal/commands/storage_run.go 中的ConfigStorageCommandLineConfigRunE维护了一张映射表例如--encryption-key → storage.encryption_key、--sqlite.path → storage.local.path、--mysql.address → storage.mysql.address、--postgres.address → storage.postgres.address等与 config.template.yml 中storage:段的键名一一对应。也就是说命令行参数本质上是临时注入配置树的 storage 配置优先级高于配置文件。此外internal/commands/storage_run.go 的LoadProvidersStorageRunE作为该命令族的 PreRunE 钩子会先加载受信证书链LoadTrustedCertificates再经getStorageProvider建立存储 Provider各*RunE执行函数如StorageUserWebAuthnExportRunE、StorageUserTOTPGenerateRunE等在执行结束时统一通过defer关闭 Provider保证连接被正确释放。identifiers用户不透明标识符管理不透明标识符opaque identifier用于以 UUID 形式指代用户典型场景是 OpenID Connect 的sub声明。identifiers子命令覆盖导出、导入、批量生成与手工添加四类任务。export —— 导出到 YAML 文件用于备份全部用户的不透明标识符。参数为-f, --file默认文件名authelia.export.opaque-identifiers.ymlauthelia storage user identifiers export authelia storage user identifiers export --file export.yml authelia storage user identifiers export --file export.yml --config config.yml authelia storage user identifiers export --file export.yml --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapwimport —— 从 YAML 文件导入YAML 文件既可用export自动生成也可以手工提供需为相同格式。导入要求恰好一个位置参数文件名authelia storage user identifiers import authelia storage user identifiers import authelia.export.opaque-identifiers.yml authelia storage user identifiers import --config config.yml export.yml authelia storage user identifiers import --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapw export.ymlgenerate —— 批量生成标识符参数包括--users要生成的用户列表逗号分隔、--services默认openid、--sectors默认空值即无扇区authelia storage user identifiers generate --users john,mary authelia storage user identifiers generate --users john,mary --services openid authelia storage user identifiers generate --users john,mary --services openid --sectors,example.com,test.com authelia storage user identifiers generate --users john,mary --services openid --sectors,example.com,test.com --config config.yml从源码结构看--sectors的默认值是包含一个空字符串的切片[]string{}表示“默认不按 sector 维度拆分标识符”--services的合法取值集合由validIdentifierServices定义openid是其中的缺省值。add —— 为单个用户手工添加add username需要恰好一个用户名参数并可指定标识符值、所属服务与扇区authelia storage user identifiers add john --identifier f0919359-9d15-4e15-bcba-83b41620a073 authelia storage user identifiers add john --identifier f0919359-9d15-4e15-bcba-83b41620a073 --config config.yml authelia storage user identifiers add john --identifier f0919359-9d15-4e15-bcba-83b41620a073 --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapw参数说明来自 internal/commands/storage.go 中的 flag 定义参数默认值说明--identifier空随机生成要使用的 version 4 UUID不设置则随机生成--serviceopenid标识符所属服务--sector空扇区标识符通常留空totpTOTP 配置管理totp子命令覆盖 TOTP 配置的生成、删除、导入与多种格式的导出。generate —— 为用户生成 TOTP 配置generate username需要恰好一个用户名参数可覆盖全部 TOTP 参数若配置已存在则默认不覆盖需--force显式强制authelia storage user totp generate john authelia storage user totp generate john --period 90 authelia storage user totp generate john --digits 8 authelia storage user totp generate john --algorithm SHA512 authelia storage user totp generate john --algorithm SHA512 --config config.yml authelia storage user totp generate john --algorithm SHA512 --config config.yml --path john.png参数默认值说明--secret空随机生成base32 编码无填充的共享密钥源码注释建议仅在恢复既有配置时使用--secret-sizeschema.TOTPSecretSizeDefault密钥长度--period30验证码轮换周期秒--digits6验证码位数--algorithmSHA1哈希算法可选SHA1多数应用支持、SHA256、SHA512--issuerAuthelia签发方描述-f, --forcefalse即使已存在配置也强制重新生成-p, --path空额外生成包含二维码的 PNG 文件路径可选从源码结构看--period、--digits、--algorithm、--issuer、--secret-size会被映射为totp.period、totp.digits、totp.algorithm、totp.issuer、totp.secret_size等配置键见ConfigStorageCommandLineConfigRunE的 flagsMap即 CLI 上的取值与全局totp:配置段走同一套校验逻辑。delete —— 删除用户的 TOTP 配置authelia storage user totp delete john authelia storage user totp delete john --config config.yml authelia storage user totp delete john --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapwexport / import —— YAML 往返导出默认文件名为authelia.export.totp.ymlauthelia storage user totp export --file example.yml authelia storage user totp export --config config.yml authelia storage user totp export --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapw导入要求恰好一个位置参数YAML 文件名authelia storage user totp import authelia.export.totp.yml authelia storage user totp import --config config.yml authelia.export.totp.yml authelia storage user totp import --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapw authelia.export.totp.ymlexport 的三种附加格式export本身可再展开三个子命令分别输出不可回导的派生格式export csv导出为 CSV默认文件authelia.export.totp.csvexport uri输出 TOTP URIexport png为每个用户生成包含二维码的 PNG 图片可用--directory指定保存目录默认为当前目录。authelia storage user totp export csv --file users.csv authelia storage user totp export uri authelia storage user totp export png authelia storage user totp export png --directory example/dirwebauthnWebAuthn 凭据管理webauthn子命令面向 Passkey/WebAuthn 场景提供查询、校验、删除与导入导出能力。list —— 列出用户的 WebAuthn 凭据list [username]接受至多一个用户名参数。从源码结构看其底层调用存储 Provider 的LoadWebAuthnCredentialsByUsername输出为ID、KID、Description三列的表格text/tabwriter排版若用户无凭据会返回明确的错误提示user name has no WebAuthn credentialsauthelia storage user webauthn list authelia storage user webauthn list john authelia storage user webauthn list john --config config.yml authelia storage user webauthn list john --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapwverify —— 校验已注册的凭据对全部已注册的 WebAuthn 凭据做一致性校验可用--verbose打开详细输出authelia storage user webauthn verify authelia storage user webauthn verify --verbosedelete —— 删除凭据delete [username]支持三种定位方式可组合使用参数说明--all删除该用户的全部 WebAuthn 凭据--description按凭据描述定位--kid按 key ID 定位此时用户名可省略authelia storage user webauthn delete john --all authelia storage user webauthn delete john --description Primary authelia storage user webauthn delete --kid abc123 authelia storage user webauthn delete john --all --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapwexport / import —— YAML 往返导出默认文件名为authelia.export.webauthn.ymlauthelia storage user webauthn export authelia storage user webauthn export --file authelia.export.webauthn.yml authelia storage user webauthn export --file authelia.export.webauthn.yml --config config.yml导入要求恰好一个位置参数YAML 文件名执行成功后会在 stdout 打印导入数量、类型与文件名的确认信息authelia storage user webauthn import authelia.export.webauthn.yml authelia storage user webauthn import --file authelia.export.webauthn.yml --encryption-key b3453fde-ecc2-4a1f-9422-2707ddbed495 --postgres.address tcp://postgres:5432 --postgres.password autheliapw实战组合一次完整的备份-迁移演练综合以上能力一套不中断服务、仅依赖 CLI 的备份与迁移流程如下以 PostgreSQL 源库为例参数均沿用官方示例格式# 1. 备份三类用户级配置 authelia storage user identifiers export --file authelia.export.opaque-identifiers.yml \ --encryption-key key --postgres.address tcp://postgres:5432 --postgres.password pw authelia storage user totp export --file authelia.export.totp.yml \ --encryption-key key --postgres.address tcp://postgres:5432 --postgres.password pw authelia storage user webauthn export --file authelia.export.webauthn.yml \ --encryption-key key --postgres.address tcp://postgres:5432 --postgres.password pw # 2. 在目标库例如换库后的 MySQL上逐一导入 authelia storage user identifiers import authelia.export.opaque-identifiers.yml \ --encryption-key key --mysql.address tcp://mysql:3306 --mysql.password pw authelia storage user totp import authelia.export.totp.yml \ --encryption-key key --mysql.address tcp://mysql:3306 --mysql.password pw authelia storage user webauthn import authelia.export.webauthn.yml \ --encryption-key key --mysql.address tcp://mysql:3306 --mysql.password pw需要强调的适用前提上述命令要求目标数据库已完成 schema 迁移可配合authelia storage migrate up使用且导入的 YAML 必须与导出版本的格式一致--encryption-key必须与存储加密配置匹配否则无法解密字段。此外totp generate/identifiers add等写入类操作会直接修改数据库中的用户安全配置生产环境执行前建议先执行对应export留存现场。相关文档authelia storage —— storage 命令组总览含bans、cache、encryption、migrate、schema-infoauthelia storage user identifiers —— 不透明标识符子命令参考authelia storage user totp —— TOTP 子命令参考authelia storage user webauthn —— WebAuthn 子命令参考主要源码参考命令定义见 internal/commands/storage.go帮助文案与示例见 internal/commands/const.go执行逻辑与参数-配置键映射见 internal/commands/storage_run.go。【免费下载链接】autheliaThe Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready.项目地址: https://gitcode.com/GitHub_Trending/au/authelia创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进