oauth2-proxy 接入 Entra ID 多租户应用时如何配置 common issuer 与 Entra ID 允许租户列表?
发布时间:2026/9/15 12:52:14 锦皓数字建站

oauth2-proxy 接入 Entra ID 多租户应用时如何配置 common issuer 与 Entra ID 允许租户列表【免费下载链接】oauth2-proxyA reverse proxy that provides authentication with Google, Azure, OpenID Connect and many more identity providers.项目地址: https://gitcode.com/GitHub_Trending/oa/oauth2-proxy当你用 oauth2-proxy 保护的服务需要允许来自多个 Entra ID 租户甚至个人 Microsoft 账号的用户登录时会遇到一个具体矛盾多租户应用签发的 ID token 由不同租户的 issuer 签发而 OIDC 默认校验要求 token 的issuer与配置的oidc_issuer_url完全一致。本文基于 oauth2-proxy 当前的 Microsoft Entra ID 提供程序文档说明如何用entra-id提供程序完成多租户接入把 issuer 指向common端点、关闭 issuer 校验并用entra_id_allowed_tenants限制允许登录的租户范围。前置条件先有一个多租户 App registration在配置 oauth2-proxy 之前需要在 Entra ID 侧完成应用注册文档在 Azure Portal 与 Terraform 两种示例中都有演示创建一个 App registration支持全部账号类型包括 single-tenant、multi-tenant、multi-tenant with Microsoft accounts 和 Microsoft accounts only设置 Web 平台的 redirect URI指向 oauth2-proxy 的回调地址例如https://podinfo.lakis.tech/oauth2/callbackTerraform 示例中的写法替换为你自己的域名生成一个 client secret。关于 scope文档说明对不带 groups 的多租户应用唯一必需的 scope 是openid对 personal microsoft accounts所需 scope 为openid profile email。如果要启用 groups claim 且用户可能拥有 200 个以上群组需要User.Readdelegated permissionscope 相应写为openid profile email User.Read。配置 common issuer 并关闭 issuer 校验多租户接入的核心两行配置oidc_issuer_urlhttps://login.microsoftonline.com/common/v2.0 insecure_oidc_skip_issuer_verificationtrueinsecure_oidc_skip_issuer_verification不是可选项。文档明确说明它用于禁用以下两项检查启动时的 discovery 一致性检查oauth2-proxy 启动时会比对 discovery documenthttps://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration返回的issuer字段与oidc_issuer_url配置是否一致。common端点的 discovery 文档中issuer字段并不等于https://login.microsoftonline.com/common/v2.0因此必须跳过该检查ID token 的issuerclaim 校验多租户场景下 token 由不同租户签发token 的issuerclaim 是https://login.microsoftonline.com/{tenant-id}/v2.0形式与commonissuer 天然不相等必须跳过严格匹配。作为补充安全约束文档指出entra-id提供程序自身仍会检查 ID token 的issuerclaim 是否符合https://login.microsoftonline.com/{tenant-id}/v2.0模板即不是任意 issuer 都会被接受。用 entra_id_allowed_tenants 限制允许登录的租户entra-id提供程序专属的参数如下来自文档 Config Options 表FlagToml 字段类型说明--entra-id-allowed-tenantentra_id_allowed_tenantsstring | list允许的租户列表。多租户应用收到的 token 由不同 issuer 签发需要同时禁用 OIDC issuer 校验未指定时允许所有租户对单租户应用是冗余的常规 ID token 校验本身就会匹配 issuer。语义要点不配置entra_id_allowed_tenants时所有租户都被允许此时commonissuer 跳过校验的配置会接受任意租户的用户配置后只有 tokenissuer中提取的租户出现在列表里才放行列表外的租户会被拒绝对单租户应用不需要该参数常规 issuer 校验已经覆盖了租户边界。文档给出的多租户完整示例其中client-id、client-secret、my-tenant-id是示例占位符替换为你在 App registration 中取得的 client ID、client secret 和目标租户 ID9188040d-6c67-4c5b-b112-36a304b66dad是文档示例中用于放行 Personal MS Accounts 的固定租户值providerentra-id oidc_issuer_urlhttps://login.microsoftonline.com/common/v2.0 client_idclient-id client_secretclient-secret insecure_oidc_skip_issuer_verificationtrue scopeopenid profile email User.Read entra_id_allowed_tenants[9188040d-6c67-4c5b-b112-36a304b66dad,my-tenant-id] # Allow only my-tenant-id and Personal MS Accounts tenant email_domains*这个示例对应一个 Entra 租户 个人 Microsoft 账号并考虑 group overage的场景。如果你的应用不支持个人账号只需要把列表换成你的租户 ID 即可scope 也可以按前面的规则收缩为openid。使用 alpha 配置方式的读者对应字段是entra-id配置块下的allowedTenants[]string与 OIDC 通用字段insecureSkipIssuerVerificationbool默认 falseWhen false, ID Token Issuers must match the OIDC discovery URL语义与上面的 TOML 字段一致见 alpha_config 文档。验证配置是否生效文档给出的判断依据是entra-id提供程序在ValidateSession阶段对租户的检查逻辑实现见 providers/ms_entra_id.go从 ID token 的issclaim 按模板https://login.microsoftonline.com/{tenant-id}/v2.0提取租户若配置了entra_id_allowed_tenants且提取出的租户不在列表中该会话校验失败登录被拒绝租户在列表中时日志会输出entra: tenant {tenant} is allowed不在列表中时输出entra: tenant {tenant} is not specified in the list of allowed tenants随后校验返回失败。因此验证路径是分别用一个列表内租户的用户和一个列表外租户的用户走完整登录流程——前者应成功建立会话后者应被拒绝同时 oauth2-proxy 日志中能看到对应租户的放行/拒绝记录。限制与边界insecure_oidc_skip_issuer_verification放宽的是 issuer 一致性检查但 token 的issuerclaim 仍必须匹配https://login.microsoftonline.com/{tenant-id}/v2.0模板两者不要混为一谈entra_id_allowed_tenants对单租户应用是冗余参数不要在单租户配置中叠加使用groups 相关能力groups claim、200 群组上限、GraphtransitiveMemberOf拉取全量群组与多租户配置相互独立详见 Microsoft Entra ID 文档的 Scopes and claims 小节旧版azure提供程序已废弃文档建议改用本文的entra-id提供程序见 Azure (Deprecated) 文档。【免费下载链接】oauth2-proxyA reverse proxy that provides authentication with Google, Azure, OpenID Connect and many more identity providers.项目地址: https://gitcode.com/GitHub_Trending/oa/oauth2-proxy创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
锦
锦皓数字建站
深耕本土企业品牌数字化升级,专注原创端正雅致商务官网,从视觉设计到稳定运维全程保驾护航。