本站支持搜索的镜像仓库:Docker Hub、gcr.io、ghcr.io、quay.io、k8s.gcr.io、registry.gcr.io、elastic.co、mcr.microsoft.com
OpenFGA CLI 是一款跨平台命令行工具,用于与 OpenFGA 服务器交互。OpenFGA 是基于 Google Zanzibar 论文实现的开源细粒度授权(Fine-Grained Authorization)解决方案,而该 CLI 提供了便捷的命令集,支持管理存储实例、授权模型、关系元组及执行权限查询等核心操作,适用于开发、测试及生产环境中 OpenFGA 服务的日常运维与集成。
docker pull openfga/cli
docker run -it openfga/cli --help # 查看帮助
挂载本地配置文件(~/.fga.yaml)到容器中:
docker run -it -v ~/.fga.yaml:/root/.fga.yaml openfga/cli store list
docker run -it -e FGA_API_URL=[***] \ -e FGA_STORE_ID=01H0H015178Y2V4CX10C2KGHF4 \ openfga/cli model list
version: '3' services: fga-cli: image: openfga/cli environment: - FGA_API_URL=[***] - FGA_CLIENT_ID=your-client-id - FGA_CLIENT_SECRET=your-client-secret - FGA_STORE_ID=your-store-id volumes: - ./models:/app/models # 挂载本地模型文件 command: model write --file /app/models/model.fga
brew install openfga/tap/fga
sudo apt install ./fga_<version>_linux_<arch>.deb
sudo dnf install ./fga_<version>_linux_<arch>.rpm
sudo apk add --allow-untrusted ./fga_<version>_linux_<arch>.apk
通过 Scoop 安装:
scoop install openfga
go install github.com/openfga/cli/cmd/fga@latest
从 GitHub Releases 下载预编译二进制文件,添加到系统 PATH。
支持三种配置方式(优先级:命令行标志 > 环境变量 > 配置文件):
| 配置项 | 命令行标志 | 环境变量 | 配置文件(~/.fga.yaml) |
|---|---|---|---|
| API 地址 | --api-url | FGA_API_URL | api-url |
| 共享密钥 | --api-token | FGA_API_TOKEN | api-token |
| OAuth 客户端 ID | --client-id | FGA_CLIENT_ID | client-id |
| OAuth 客户端密钥 | --client-secret | FGA_CLIENT_SECRET | client-secret |
| OAuth 作用域 | --api-scopes | FGA_API_SCOPES | api-scopes |
| Token 签发者 | --api-token-issuer | FGA_API_TOKEN_ISSUER | api-token-issuer |
| Token 受众 | --api-audience | FGA_API_AUDIENCE | api-audience |
| 存储实例 ID | --store-id | FGA_STORE_ID | store-id |
| 授权模型 ID | --model-id | FGA_MODEL_ID | model-id |
# Auth0 FGA 示例配置 api-url: [***] client-id: 4Zb..UYjaHreLKOJuU8 client-secret: J3...2pBwiauD api-audience: [***] api-token-issuer: auth.fga.dev store-id: 01H0H015178Y2V4CX10C2KGHF4
# 仅创建存储 fga store create --name "FGA Demo Store" # 创建存储并自动导入模型 fga store create --name "Demo" --model model.fga
响应示例:
{ "store": { "id": "01H6H9CNQRP2TVCFR7899XGNY8", "name": "Demo", "created_at": "2023-07-29T16:58:28.984402Z", "updated_at": "2023-07-29T16:58:28.984402Z" }, "model": { "authorization_model_id": "01H6H9CNQV36Y9WS1RJGRN8D06" } }
fga store import --file store.fga.yaml --max-parallel-requests 8
(支持导入模型、元组及测试用例,文件格式参考 Store File Format)
# 导出到终端 fga store export --store-id 01H0H015178Y2V4CX10C2KGHF4 # 导出到文件 fga store export --store-id <id> --output-file backup.fga.yaml
fga store list --max-pages 10
fga store get --store-id 01H0H015178Y2V4CX10C2KGHF4
fga store delete --store-id 01H0H015178Y2V4CX10C2KGHF4
# 从文件写入(FGA 格式) fga model write --store-id <id> --file model.fga # 从 JSON 字符串写入 fga model write --store-id <id> '{"schema_version":"1.1","type_definitions":[{"type":"user"},{"type":"document","relations":{"can_view":{"this":{}}}}]}' --format json
# 查询最新模型(FGA 格式) fga model get --store-id <id> # 查询指定模型(JSON 格式) fga model get --store-id <id> --model-id <model-id> --format json
fga model validate --file model.fga --format fga
响应示例(有效模型):
{"is_valid":true}
# 运行单个测试文件 fga model test --tests tests/demo.fga.yaml # 运行目录下所有测试文件 fga model test --tests "tests/**/*.fga.yaml"
测试文件格式示例(YAML):
model: | model schema 1.1 type user type document relations define can_view: [user] tuples: - user: user:anne relation: can_view object: document:1 tests: - name: anne_can_view check: - user: user:anne object: document:1 assertions: can_view: true
# 单行写入 fga tuple write user:anne can_view document:roadmap --store-id <id> # 批量写入(从文件) fga tuple write --store-id <id> --file tuples.json --max-parallel-requests 8
批量文件示例(JSON):
[ {"user":"user:bob","relation":"can_edit","object":"document:roadmap"}, {"user":"user:carol","relation":"can_view","object":"document:roadmap"} ]
# 查询所有元组 fga tuple read --store-id <id> # 按对象筛选 fga tuple read --store-id <id> --object document:roadmap
fga tuple changes --store-id <id> --type document --start-time 2024-01-01T00:00:00Z
fga query check --store-id <id> --user user:anne --relation can_view --object document:roadmap
响应示例:
{"allowed":true}
fga query expand --store-id <id> --user user:anne --relation can_view --object document:roadmap
fga query list-objects --store-id <id> --user user:anne --type document --relation can_view
# 克隆仓库 git clone [***] && cd cli # 构建二进制文件 go build -o ./dist/fga ./cmd/fga/main.go # 或使用 make make build # 运行 ./dist/fga --version

免费版仅支持 Docker Hub 加速,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
免费版仅支持 docker.io;专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录方式配置轩辕镜像加速服务,包含7个详细步骤
在 Linux 系统上配置轩辕镜像源,支持主流发行版
在 Docker Desktop 中配置轩辕镜像加速,适用于桌面系统
在 Docker Compose 中使用轩辕镜像加速,支持容器编排
在 k8s 中配置 containerd 使用轩辕镜像加速
在宝塔面板中配置轩辕镜像加速,提升服务器管理效率
在 Synology 群晖NAS系统中配置轩辕镜像加速
在飞牛fnOS系统中配置轩辕镜像加速
在极空间NAS中配置轩辕镜像加速
在爱快ikuai系统中配置轩辕镜像加速
在绿联NAS系统中配置轩辕镜像加速
在威联通NAS系统中配置轩辕镜像加速
在 Podman 中配置轩辕镜像加速,支持多系统
配置轩辕镜像加速9大主流镜像仓库,包含详细配置步骤
无需登录即可使用轩辕镜像加速服务,更加便捷高效
需要其他帮助?请查看我们的 常见问题 或 官方QQ群: 13763429