Apache Casbin Gateway
5. 运维

5.2 安全与对外提供服务

Gateway默认绑定127.0.0.1,因为有两样东西对能连上这个端口的人是完全敞开的:

  • 界面不问就把本地管理员登录上,
  • /v1用存在这里的API Key向上游转发。

对一个本机工具来说这两点正是你要的,但都不该端给网络。

确实要让别的机器访问

在conf/app.conf里设httpaddr = 0.0.0.0,然后这两件事都要做:

  1. **在"我的账户"里改掉管理员密码。**自动登录在第一个非本机请求处就停了,从此密码是唯一的一道门。
  2. 每个发往/v1的请求都带上中继令牌。Gateway在第一次启动时生成它,显示在设置→安全里。

供应商页和Agent页上的环境变量片段本来就带着这个令牌,Gateway给Agent写配置时写的也是它。来自本机的请求永远不需要它。

落盘的Key

设置→安全里的apiKeyEncryptionKey,用AES-256-GCM把数据库里的供应商API Key加密。在添加你在意的那些供应商之前先设好它。

还有一些东西压根就不会进存储:

  • 请求头——入站API Key会在那里,而请求头完全不记录。
  • 被记录正文里像凭据的内容,在写入之前就被替换掉(4.2)。

网络设置

设置→网络:

字段用途
出站SOCKS5代理通过代理访问厂商端点
允许的主机名Gateway响应哪些Host头
允许的来源哪些浏览器来源可以调这套API

httpaddr一旦不是回环地址,后两项就重要了:放在网络上的Gateway,应该只回应你打算让它回应的那些名字。

登录

开箱即用的登录是Gateway自己的用户表,加上本地管理员自动登录。设置casdoorEndpoint会把整套切到Casdoor,同时带来单点登录和OAuth登录(5.1)。

Agent拿到了什么,没拿到什么

流量走Gateway的Agent手里是Gateway的中继令牌,绝不是厂商的Key。要收回某个Agent的访问权,这是在Gateway这边的一次改动,不是改八个配置文件——而权限页可以在完全不碰那个Agent的情况下,缩小这个令牌的用处。

下一节:5.3 备份与云同步。

在GitHub上编辑
Apache Incubator

Apache Casbin (Incubating) is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2026 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.

Apache, Apache Casbin, the names of Apache projects, and the feather logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. All other marks mentioned may be trademarks or registered trademarks of their respective owners.

本页内容