|
| 1 | +[id="enabling-authentication-with-github"] |
| 2 | += Enabling authentication with GitHub |
| 3 | + |
| 4 | +To authenticate users with GitHub, enable the GitHub authentication provider in {product}. |
| 5 | + |
| 6 | +.Prerequisites |
| 7 | +* You have link:https://docs.redhat.com/en/documentation/red_hat_developer_hub/{product-version}/html/administration_guide_for_red_hat_developer_hub/assembly-add-custom-app-file-openshift_admin-rhdh[added a custom {product-short} application configuration], and have sufficient permissions to modify it. |
| 8 | +* You have sufficient permissions in GitHub to create and manage a link:https://docs.github.com/en/apps/overview[GitHub App]. |
| 9 | + |
| 10 | +.Procedure |
| 11 | +. To allow {product-short} to authenticate with GitHub, create a GitHub App. |
| 12 | +Opt for a GitHub App instead of an OAuth app to use fine-grained permissions, gain more control over which repositories the application can access, and use short-lived tokens. |
| 13 | + |
| 14 | +.. link:https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app[Register a GitHub App] with the following configuration: |
| 15 | ++ |
| 16 | +* *GitHub App name*: Enter a unique name identifying your GitHub App, such as __<{product}>__-__<GUID>__. |
| 17 | +* *Homepage URL*: Your {product-short} URL: `pass:c,a,q[{my-product-url}]`. |
| 18 | +* *Authorization callback URL*: Your {product-short} authentication backend URL: `pass:c,a,q[{my-product-url}/api/auth/github/handler/frame]`. |
| 19 | +* *Webhook URL*: Your {product-short} URL: `pass:c,a,q[{my-product-url}]`. |
| 20 | +* *Webhook secret*: Provide a strong secret. |
| 21 | +* *Repository permissions*: |
| 22 | +** Enable `Read-only` access to: |
| 23 | +*** *Administration* |
| 24 | +*** *Commit statuses* |
| 25 | +*** *Contents* |
| 26 | +*** *Dependabot alerts* |
| 27 | +*** *Deployments* |
| 28 | +*** *Pull Requests* |
| 29 | +*** *Webhooks* |
| 30 | ++ |
| 31 | +TIP: If you plan to make changes using the GitHub API, ensure that `Read and write` permissions are enabled instead of `Read-only`. |
| 32 | + |
| 33 | +** Toggle other permissions as per your needs. |
| 34 | + |
| 35 | +* *Organization permissions*: |
| 36 | +** Enable `Read-only` access to *Members*. |
| 37 | + |
| 38 | +* For *Where can this GitHub App be installed?*, select `Only on this account`. |
| 39 | + |
| 40 | +.. In the *General* -> *Clients secrets* section, click *Generate a new client secret*. |
| 41 | + |
| 42 | +.. In the *General* -> *Private keys* section, click *Generate a private key*. |
| 43 | + |
| 44 | +.. In the *Install App* tab, choose an account to install your GitHub App on. |
| 45 | + |
| 46 | +.. Save the following values for the next step: |
| 47 | + |
| 48 | +* **App ID** |
| 49 | +* **Client ID** |
| 50 | +* **Client secret** |
| 51 | +* **Private key** |
| 52 | +* **Webhook secret** |
| 53 | + |
| 54 | +. To add your GitHub credentials to your {product-short} secrets, edit your {product-short} secrets, such as `secrets-rhdh`, and add the following key/value pairs: |
| 55 | ++ |
| 56 | +`AUTH_GITHUB_APP_ID`:: Enter the saved **App ID**. |
| 57 | +`AUTH_GITHUB_CLIENT_ID`:: Enter the saved **Client ID**. |
| 58 | ++ |
| 59 | +Optional: enter additional secrets. The additional secrets are not required for authentication, but for further integration with GitHub, including: |
| 60 | ++ |
| 61 | +`GITHUB_HOST_DOMAIN`:: Enter your GitHub host domain: `pass:c[https://github.com]` unless you are using GitHub Enterprise. |
| 62 | +`GITHUB_ORGANIZATION`:: Enter your GitHub organization name, such as `__<your_github_organization_name>__'. |
| 63 | +`GITHUB_ORG_URL`:: Enter `$GITHUB_HOST_DOMAIN/$GITHUB_ORGANIZATION`. |
| 64 | +`GITHUB_CLIENT_SECRET`:: Enter the saved **Client Secret**. |
| 65 | +`GITHUB_PRIVATE_KEY_FILE`:: Enter the saved **Private key**. |
| 66 | +`GITHUB_WEBHOOK_SECRET`:: Enter the saved *Webhook secret*. |
| 67 | + |
| 68 | +. To set up the GitHub authentication provider in your {product-short} custom configuration, edit your custom {product-short} ConfigMap such as `app-config-rhdh`, and add the following lines to the `app-config-rhdh.yaml` content: |
| 69 | ++ |
| 70 | +-- |
| 71 | +.`app-config-rhdh.yaml` fragment with mandatory fields to enable authentication with GitHub |
| 72 | +[source,yaml] |
| 73 | +---- |
| 74 | +auth: |
| 75 | + environment: production |
| 76 | + providers: |
| 77 | + github: |
| 78 | + production: |
| 79 | + clientId: ${AUTH_GITHUB_CLIENT_ID} |
| 80 | + clientSecret: ${AUTH_GITHUB_CLIENT_SECRET} |
| 81 | +signInPage: github |
| 82 | +---- |
| 83 | + |
| 84 | +`environment: production`:: |
| 85 | +Mark the environment as `production` to hide the Guest login in the {product-short} home page. |
| 86 | + |
| 87 | +`clientId`, `clientSecret`:: |
| 88 | +Use the {product-short} application information that you have created in GitHub and configured in OpenShift as secrets. |
| 89 | + |
| 90 | +`sigInPage: github`:: |
| 91 | +To enable the GitHub provider as default sign-in provider. |
| 92 | + |
| 93 | +Optional: Consider adding the following optional fields: |
| 94 | + |
| 95 | +`dangerouslyAllowSignInWithoutUserInCatalog: true`:: |
| 96 | +To enable authentication without requiring to provision users in the {product-short} software catalog. |
| 97 | ++ |
| 98 | +WARNING: Use `dangerouslyAllowSignInWithoutUserInCatalog` to explore {product-short} features, but do not use it in production. |
| 99 | ++ |
| 100 | +.`app-config-rhdh.yaml` fragment with optional field to allow authenticating users absent from the software catalog |
| 101 | +[source,yaml] |
| 102 | +---- |
| 103 | +auth: |
| 104 | + environment: production |
| 105 | + providers: |
| 106 | + github: |
| 107 | + production: |
| 108 | + clientId: ${AUTH_GITHUB_CLIENT_ID} |
| 109 | + clientSecret: ${AUTH_GITHUB_CLIENT_SECRET} |
| 110 | +signInPage: github |
| 111 | +dangerouslyAllowSignInWithoutUserInCatalog: true |
| 112 | +---- |
| 113 | + |
| 114 | +`callbackUrl`:: |
| 115 | +The callback URL that GitHub uses when initiating an OAuth flow, such as: __<your_intermediate_service_url/handler>__. |
| 116 | +Define it when {product-short} is not the immediate receiver, such as in cases when you use one OAuth app for many {product-short} instances. |
| 117 | ++ |
| 118 | +.`app-config-rhdh.yaml` fragment with optional `enterpriseInstanceUrl` field |
| 119 | +[source,yaml,subs="+quotes"] |
| 120 | +---- |
| 121 | +auth: |
| 122 | + providers: |
| 123 | + github: |
| 124 | + production: |
| 125 | + callbackUrl: __<your_intermediate_service_url/handler>__ |
| 126 | +---- |
| 127 | + |
| 128 | +`enterpriseInstanceUrl`:: |
| 129 | +Your GitHub Enterprise URL. |
| 130 | +Requires you defined the `GITHUB_HOST_DOMAIN` secret in the previous step. |
| 131 | ++ |
| 132 | +.`app-config-rhdh.yaml` fragment with optional `enterpriseInstanceUrl` field |
| 133 | +[source,yaml,subs="+quotes"] |
| 134 | +---- |
| 135 | +auth: |
| 136 | + providers: |
| 137 | + github: |
| 138 | + production: |
| 139 | + enterpriseInstanceUrl: ${GITHUB_HOST_DOMAIN} |
| 140 | +---- |
| 141 | + |
| 142 | +-- |
| 143 | + |
| 144 | +.Verification |
| 145 | +. Go to the {product-short} login page. |
| 146 | +. Your {product-short} sign-in page displays *Sign in using GitHub* and the Guest user sign-in is disabled. |
| 147 | +. Log in with GitHub. |
| 148 | + |
0 commit comments