身份验证


Red Hat Developer Hub 1.2

在 Red Hat Developer Hub 中配置外部服务的身份验证

Red Hat Customer Content Services

摘要

作为 Red Hat Developer Hub 平台工程师,您可以管理其他用户的身份验证,以满足您机构的特定需求。

前言

Red Hat Developer Hub 中的身份验证有助于用户登录、识别和访问外部资源。它支持多个身份验证提供程序。

身份验证供应商通常通过以下方法使用:

  • 一个用于登录和识别的供应商。
  • 用于访问外部资源的其他提供程序。

Red Hat Developer Hub 支持以下身份验证供应商:

Microsoft Azure
microsoft
GitHub
github
Keycloak
oidc

对于您要使用的每个供应商,请按照专用流程完成以下任务:

  1. 设置身份验证供应商和 Red Hat Developer Hub 需要通信的共享 secret。
  2. 将 Red Hat Developer Hub 配置为使用身份验证供应商。

第 1 章 启用 Microsoft Azure 身份验证供应商

Red Hat Developer Hub 包括一个 Microsoft Azure 身份验证供应商,可以使用 OAuth 验证用户。

流程

  1. 要允许 Developer Hub 与 Microsoft Azure 进行身份验证,请在 Microsoft Azure 中创建 OAuth 应用程序。

    1. 进入 Azure Portal > App registrations,并为 Developer Hub 创建 App Registration
    2. App registration overview 页面中,使用 配置添加新的 Web 平台 配置:

      重定向 URI
      输入 Developer Hub 中设置的后端身份验证 URI: https:// <APP_FQDN&gt; /api/auth/microsoft/handler/frame
      front-channel logout URL
      留空。
      隐式授权和混合流
      保留所有复选框都未清除。
    3. API 权限 选项卡中,单击 Add Permission,然后为 Microsoft Graph API 添加以下 委派权限

      • email
      • offline_access
      • openid
      • 配置集
      • user.Read
      • 您可以在此处和 Developer Hub 配置中定义 Microsoft Graph API 的可选自定义范围(app-config-rhdh.yaml)。

        注意

        您的公司可能需要您授予 admin 同意这些权限。即使您的公司不需要管理员同意,您可能也要这样做,因为这意味着用户在第一次访问阶段时不需要单独同意。要授予 admin 同意,目录 admin 必须前往 admin consent 页面,然后单击 COMPANY NAME 的 Grant admin consent

    4. 进入 Certificates & Secrets 页面,然后进入 Client secret 选项卡,并创建新的客户端 secret。为下一步保存 Client secret
  2. 在 Developer Hub secret 中添加 Microsoft Azure 凭证。

    1. 编辑 Developer Hub secret,如 secrets-rhdh
    2. 添加以下键/值对:

      • AUTH_AZURE_CLIENT_ID :输入您在 Microsoft Azure 上生成的 应用程序 ID
      • AUTH_AZURE_CLIENT_SECRET :输入您在 Microsoft Azure 上生成的 客户端 secret
      • AUTH_AZURE_TENANT_ID: 在 Microsoft Azure 上输入您的 租户 ID
  3. 在 Developer Hub 自定义配置中设置 Microsoft Azure 身份验证供应商。

    编辑自定义 Developer Hub 配置映射,如 app-config-rhdh

    app-config-rhdh.yaml 内容中,在 root auth 配置下添加 microsoft 供应商配置,并启用 microsoft 供应商 for sign-in :

    app-config-rhdh.yaml fragment

    auth:
      environment: production
      providers:
        microsoft:
          production:
            clientId: ${AUTH_AZURE_CLIENT_ID}
            clientSecret: ${AUTH_AZURE_CLIENT_SECRET}
            tenantId: ${AUTH_AZURE_TENANT_ID}
            # domainHint: ${AUTH_AZURE_TENANT_ID} 
    1
    
            # additionalScopes: 
    2
    
              # - Mail.Send
    signInPage: microsoft 
    3

    1
    可选的用于单租户应用程序。您可以通过从其他租户过滤出帐户,减少具有多个租户中帐户的登录侵权。如果要将此参数用于单租户应用,请取消注释并输入租户 ID。如果您的应用程序注册是多租户的,请将此参数留空。如需更多信息,请参阅 Home Realm Discovery
    2
    可选用于其他范围。要为应用程序注册添加范围,取消注释并输入您要添加的范围列表。默认值为 ['user.read']
    3
    要启用 Microsoft Azure 供应商作为默认登录供应商。
注意

对于对外向访问有限制的环境,可选,如防火墙规则。如果您的环境有传出的访问限制,请确保您的 Backstage 后端可以访问以下主机:

  • login.microsoftonline.com :要获取并交换授权代码和访问令牌。
  • graph.microsoft.com :要获取用户配置文件信息(如此源代码中所示)。如果这个主机无法访问,用户可能会看到 Authentication failed,在尝试登录时无法获取用户配置集 错误。

第 2 章 启用 GitHub 身份验证供应商

Red Hat Developer Hub 使用内置的 GitHub 身份验证供应商来验证 GitHub 或 GitHub Enterprise 中的用户。

2.1. GitHub App​ 概述

GitHub 应用程序通常首选 OAuth 应用,因为它们使用精细的权限,从而进一步控制应用可访问的存储库,并使用简短令牌。如需更多信息,请参阅 GitHub 文档中的 GitHub 应用程序概述

2.2. 注册 GitHub​ 应用程序

在 GitHub App 中,您可以将允许的范围配置为该应用程序的一部分,因此您必须验证插件所需的范围。插件 README 文件中提供了范围信息。

要添加 GitHub 身份验证,请完成 GitHub 网站 中注册 GitHub 应用程序 中的步骤。

使用以下示例,在 Register new GitHub App 页面的必填字段中输入您的生产环境的信息:

  • 应用程序名称 :Red Hat Developer Hub
  • Homepage URL: https://developer-hub-<NAMESPACE_NAME>.<KUBERNETES_ROUTE_HOST>
  • 授权回调 URL: https://developer-hub-<NAMESPACE_NAME>.<KUBERNETES_ROUTE_HOST>/api/auth/github/handler/frame
注意

Homepage URL 指向 Developer Hub 前端,授权回调 URL 指向身份验证供应商后端。

2.3. 在 Developer Hub 中配置 GitHub 应用程序

要为 Developer Hub 添加 GitHub 身份验证,您必须在 app-config.yaml 文件中配置 GitHub App。

GitHub 身份验证供应商使用以下配置密钥:

  • clientId :您在 GitHub 上生成的客户端 ID。例如: b59241722e3c3b4816e2
  • clientSecret :与生成的客户端 ID 绑定的客户端 secret。
  • enterpriseInstanceUrl (可选):GitHub Enterprise 实例的基本 URL。例如 :https://ghe.<company>.com .Enterprise 只需要 enterpriseInstanceUrl
  • callbackUrl (可选):GitHub 在启动 OAuth 流时使用的回调 URL。例如: https://your-intermediate-service.com/handler。只有在 Developer Hub 不是直接接收器时才需要 callbackUrl,比如当您为多个 Developer Hub 实例使用一个 OAuth 应用程序时。

要配置 GitHub App,请在 root auth 配置下将供应商配置添加到 app-config.yaml 文件中。例如:

auth:
 environment: production
 providers:
   github:
     production:
       clientId: ${GITHUB_APP_CLIENT_ID}
       clientSecret: ${GITHUB_APP_CLIENT_SECRET}
       ## uncomment if using GitHub Enterprise
       # enterpriseInstanceUrl: ${GITHUB_URL}

2.4. 将 GitHub 供应商添加到 Developer Hub 前端中

要将供应商添加到前端,请将配置中的签名添加到 app-config.yaml 文件中。例如:

signInPage: github

其他资源

第 3 章 启用 OpenID Connect 身份验证供应商

Red Hat Developer Hub 使用 OpenID Connect (OIDC)身份验证供应商与支持 OIDC 协议的第三方服务进行身份验证。

您可以通过在 root auth 配置下更新 app-config.yaml 文件,在 Developer Hub 中配置 OIDC 身份验证供应商。例如:

auth:
  environment: production
  # Providing an auth.session.secret will enable session support in the auth-backend
  session:
    secret: ${SESSION_SECRET}
  providers:
    oidc:
      production:
        metadataUrl: ${AUTH_OIDC_METADATA_URL}
        clientId: ${AUTH_OIDC_CLIENT_ID}
        clientSecret: ${AUTH_OIDC_CLIENT_SECRET}
        prompt: ${AUTH_OIDC_PROMPT} # Recommended to use auto
        ## Uncomment for additional configuration options
        # callbackUrl: ${AUTH_OIDC_CALLBACK_URL}
        # tokenEndpointAuthMethod: ${AUTH_OIDC_TOKEN_ENDPOINT_METHOD}
        # tokenSignedResponseAlg: ${AUTH_OIDC_SIGNED_RESPONSE_ALG}
        # scope: ${AUTH_OIDC_SCOPE}
        ## Declarative resolvers to override the default resolver: `emailLocalPartMatchingUserEntityName`
        ## The authentication provider tries each sign-in resolver until it succeeds, and fails if none succeed. Uncomment the resolvers that you want to use.
        # signIn:
        #   resolvers:
        #     - resolver: preferredUsernameMatchingUserEntityName
        #     - resolver: emailMatchingUserEntityProfileEmail
        #     - resolver: emailLocalPartMatchingUserEntityName
signInPage: oidc

3.2. 使用 OIDC 身份验证供应商配置 Keycloak

Red Hat Developer Hub 包括一个 OIDC 身份验证供应商,可以使用 Keycloak 验证用户。

重要

您在 Keycloak 中创建的用户必须在 Developer Hub 目录中可用。

流程

  1. 在 Keycloak 中,创建一个新域,如 RHDH
  2. 添加新用户。

    用户名
    用户的用户名,例如 rhdhuser
    电子邮件
    用户的电子邮件地址。
    用户的名字。
    用户的姓氏。
    已验证电子邮件
    切换到 上的
  3. Create
  4. 导航到 Credentials 选项卡。
  5. 单击 设置密码
  6. 输入用户帐户的 Password,并将 Temporary 切换为 Off
  7. 创建一个新的客户端 ID,如 RHDH

    客户端身份验证
    切换到 上的
    有效的重定向 URI
    设置为 OIDC 处理程序 URL,例如 https://<RHDH_URL>/api/auth/oidc/handler/frame
  8. 导航到 Credentials 选项卡,再复制 Client secret
  9. 在下一步中保存客户端 ID 和客户端 Secret。
  10. 在 Developer Hub 中,在 Developer Hub secret 中添加 Keycloak 凭证。

    1. 编辑 Developer Hub secret,如 secrets-rhdh。
    2. 添加以下键/值对:

      AUTH_KEYCLOAK_CLIENT_ID
      输入您在 Keycloak 中生成的客户端 ID,如 RHDH
      AUTH_KEYCLOAK_CLIENT_SECRET
      输入您在 Keycloak 中生成的 Client Secret。
  11. 在 Developer Hub 自定义配置中设置 OIDC 身份验证供应商。

    1. 编辑自定义 Developer Hub ConfigMap,如 app-config-rhdh
    2. app-config-rhdh.yaml 内容中,在 root auth 配置下添加 oidc 供应商配置,并为 sign-in 启用 oidc 供应商:

      app-config-rhdh.yaml fragment

      auth:
        environment: production
        providers:
          oidc:
            production:
            clientId: ${AUTH_KEYCLOAK_CLIENT_ID}
            clientSecret: ${AUTH_KEYCLOAK_CLIENT_SECRET}
            metadataUrl: ${KEYCLOAK_BASE_URL}/auth/realms/${KEYCLOAK_REALM}
            prompt: ${KEYCLOAK_PROMPT} # recommended to use auto
             Uncomment for additional configuration options #callbackUrl: ${KEYCLOAK_CALLBACK_URL} #tokenEndpointAuthMethod: ${KEYCLOAK_TOKEN_ENDPOINT_METHOD} #tokenSignedResponseAlg: ${KEYCLOAK_SIGNED_RESPONSE_ALG} #scope: ${KEYCLOAK_SCOPE}  If you are using the keycloak-backend plugin, use the preferredUsernameMatchingUserEntityName resolver to avoid a login error.
            signIn:
              resolvers:
                - resolver: preferredUsernameMatchingUserEntityName
      signInPage: oidc

验证

  1. 重启 backstage-developer-hub 应用程序以应用更改。
  2. 您的 Developer Hub 注册页面 使用 OIDC 显示 Sign in

如果您使用 OAuth2 代理作为带有 Keycloak 的身份验证供应商,并且希望迁移到 OIDC,您可以更新身份验证供应商配置以使用 OIDC。

流程

  1. 在 Keycloak 中,将有效的重定向 URI 更新至 https://<rhdh_url>/api/auth/oidc/handler/frame。确保将 < rhdh_url&gt; 替换为您的 Developer Hub 应用程序 URL,如 my.rhdh.example.com
  2. app-config.yaml 文件的 auth 部分中的 oauth2Proxy 配置值替换为 oidc 配置值。
  3. signInPage 配置值从 oauth2Proxy 更新至 oidc

    以下示例显示了在将身份验证供应商迁移到 oid 之前 oauth2Proxyauth.providerssignInPage 配置:

    auth:
      environment: production
      session:
        secret: ${SESSION_SECRET}
      providers:
        oauth2Proxy: {}
    signInPage: oauth2Proxy

    以下示例显示了在将身份验证供应商迁移到 oidcauth.providerssignInPage 配置:

    auth:
      environment: production
      session:
        secret: ${SESSION_SECRET}
      providers:
        oidc:
          production:
            metadataUrl: ${KEYCLOAK_METADATA_URL}
            clientId: ${KEYCLOAK_CLIENT_ID}
            clientSecret: ${KEYCLOAK_CLIENT_SECRET}
            prompt: ${KEYCLOAK_PROMPT} # recommended to use auto
    signInPage: oidc
  4. 删除 OAuth2 Proxy sidecar 容器,并更新 Helm Chart 的 values.yaml 文件的 upstream.service 部分,如下所示:

    • service.ports.backend:7007
    • service.ports.targetPort:backend

      以下示例显示了在将身份验证供应商迁移到 oidc 之前 oauth2Proxy服务配置

      service:
        ports:
          name: http-backend
          backend: 4180
          targetPort: oauth2Proxy

      以下示例显示了将身份验证供应商迁移到 oidc 后的 服务配置

      service:
        ports:
          name: http-backend
          backend: 7007
          targetPort: backend
  5. 升级 Developer Hub Helm Chart。

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部