NetBird
NetBird 是一个基于 WireGuard 的覆盖网络。自托管的 NetBird 服务器通过 OpenID Connect (OIDC) 让用户登录其仪表盘和客户端应用。将 Casdoor 作为身份提供商,用户可以使用他们的 Casdoor 账户登录 NetBird。
NetBird 如何使用 Casdoor
从版本 0.62 开始,NetBird 服务器内置了登录服务,您可以将其中的 Casdoor 添加为 Generic OIDC 身份提供商。仪表盘和 NetBird 客户端在此内置服务处登录,该服务会将用户引导至 Casdoor:
- 带有浏览器的计算机上的客户端使用带 PKCE 的授权码流程。没有桌面的 Linux 服务器上的客户端使用设备授权流程,并显示 URL 和代码。
- 这两种流程都在客户端和 NetBird 服务器之间运行。Casdoor 只看到 NetBird 服务器的登录,因此 Casdoor 应用需要一个重定向 URL、一个客户端密钥,且不需要设备授权流。
如果您的 NetBird 服务器是通过 setup.env 配置的,并且使用 Casdoor 代替内置登录,请参阅 Use Casdoor without the built-in login。
在 Casdoor 中创建应用
-
在 Casdoor 管理控制台中,打开您的用户所在的组织并添加一个应用,或者打开一个现有的应用。
-
将 NetBird 的回调地址添加到 Redirect URLs:
https://netbird.example.com/oauth2/callback -
保持 Token format 为默认的
JWT。NetBird 从 ID 令牌中读取用户信息,而无需请求 UserInfo 端点,默认格式在其中包含email、name(用户名)和groups。 -
保存,并记下 Client ID 和 Client secret。
在 NetBird 中添加 Casdoor
-
在 NetBird 仪表盘中,前往 Settings > Identity Providers 并点击 Add Identity Provider。
-
填写提供商信息:
Field Value Provider Type Generic OIDCName CasdoorIssuer URL https://door.example.comClient ID <your-client-id>Client Secret <your-client-secret>- Issuer URL:Casdoor 的 URL。它必须与
https://door.example.com/.well-known/openid-configuration中显示的issuer完全一致。 <your-client-id>、<your-client-secret>:来自 Casdoor 应用的值。
- Issuer URL:Casdoor 的 URL。它必须与
-
检查对话框中的 Redirect / Callback URL 是否为您在 Casdoor 的 Redirect URLs 中添加的那个,然后点击 Add Provider。
同步 Casdoor 群组
- 在 Casdoor 应用中,在 OIDC/OAuth 选项卡下,将 Token group format 设置为
Name (group),以便群组以developers而不是my-org/developers的形式传递。 - 在 NetBird 仪表盘中,前往 Settings > Groups,开启 JWT group sync,并将 JWT claim 设置为
groups。
NetBird 会在每次登录时添加和移除用户的群组会员资格。
验证结果
- 在私有浏览器窗口中打开 NetBird 仪表盘。登录页面会显示一个 Casdoor 按钮。
- 点击它并登录到 Casdoor。仪表盘打开时,Casdoor 用户已登录。
- 使用 NetBird 客户端连接一个设备。客户端会在浏览器中打开相同的登录界面,或者在没有桌面的服务器上,打印出一个 URL 和一个代码,以便在其他设备上打开。
不使用 Casdoor 内置登录功能
在旧版设置中,configure.sh 读取 setup.env 并配置仪表板和客户端直接与 Casdoor 通信。随后由 Casdoor 为客户端自身提供 PKCE 流程和设备授权流程。
-
在 Casdoor 应用中,将这些 URL 添加到 Redirect URLs:
https://netbird.example.com/nb-auth
https://netbird.example.com/nb-silent-auth
http://localhost:53000最后一个是 NetBird 客户端的 PKCE 回调地址。Casdoor 中的
localhost条目可匹配任意端口上的相同 URL。 -
在 OIDC/OAuth 选项卡中,在 Grant types 中启用 Authorization Code、Refresh Token 和 Device Code。
-
在 Signin methods 中添加 Device login。如果没有此方法,Casdoor 将拒绝应用程序的设备授权请求。
-
在
setup.env中,设置:NETBIRD_AUTH_OIDC_CONFIGURATION_ENDPOINT="https://door.example.com/.well-known/openid-configuration"
NETBIRD_AUTH_CLIENT_ID="<your-client-id>"
NETBIRD_AUTH_AUDIENCE="<your-client-id>"
NETBIRD_AUTH_SUPPORTED_SCOPES="openid profile email offline_access"
NETBIRD_AUTH_REDIRECT_URI="/nb-auth"
NETBIRD_AUTH_SILENT_REDIRECT_URI="/nb-silent-auth"
NETBIRD_AUTH_DEVICE_AUTH_CLIENT_ID="<your-client-id>"
NETBIRD_USE_AUTH0="false"
NETBIRD_MGMT_IDP="none"NETBIRD_AUTH_AUDIENCE:Casdoor 会将客户端 ID 放入其令牌的aud声明中,NetBird 服务器和客户端都会拒绝面向其他受众的令牌。NETBIRD_AUTH_DEVICE_AUTH_CLIENT_ID:启用设备授权流程,在没有桌面的 Linux 服务器上的客户端仅使用此流程。NETBIRD_MGMT_IDP:NetBird 没有针对 Casdoor 的用户管理集成。
这里的仪表板和客户端是公共客户端:它们使用 PKCE 且不发送客户端密钥,Casdoor 接受这种配置。
-
运行
./configure.sh并重启 NetBird 容器。
故障排除
| Symptom | Cause and fix |
|---|---|
Casdoor shows Redirect URI: ... doesn't exist in the allowed Redirect URI list | Add the URL from the error to Redirect URLs. With the built-in login, it is the Redirect / Callback URL from the NetBird dialog. |
| Sign-in fails with an issuer or discovery error | Issuer URL differs from the issuer in Casdoor's discovery document. Set origin in Casdoor's conf/app.conf to its public URL and use the same value. |
| The dashboard works, but the client never connects and shows no error | In the setup without the built-in login: on a Linux server without a desktop, the client uses only the device authorization flow. Turn on Device Code and add Device login to Signin methods in Casdoor, and set NETBIRD_AUTH_DEVICE_AUTH_CLIENT_ID. Also check that NETBIRD_AUTH_AUDIENCE is the client ID. |
The device authorization request fails with device login is not enabled for this application | Add Device login to the Signin methods of the application. |
| Groups don't appear in NetBird | Check that JWT group sync is on with the claim groups, that the user is in a group in Casdoor, and that Token format is JWT. |