OAuth 2.0 credentials for GitHub Apps - JWT
Perform the following steps to integrate your GitHub Apps using the JWT bearer token.
Before you begin
Role required:
- oauth_admin in DevOps Change Velocity.
Admin account in GitHub.
Note: The OAuth 2.0 JWT grant type is supported for GitHub & GitHub Enterprise with MID server.
Configure the GitHub App in your GitHub account (JWT)
Create a custom GitHub App from your GitHub account to enable OAuth 2.0 authentication with your ServiceNow instance.
Before you begin
GitHub requirement: GitHub App configured to integrate with ServiceNow
Role required: No instance role required
About this task
Complete these steps from your GitHub account. See Building GitHub Apps on the GitHub Developer site for instructions on creating and configuring custom applications.
Procedure
From your GitHub account, create your GitHub App by navigating to Developer Settings > GitHub Apps.
In the Homepage URL field, enter
https://<instance-name>.service-now.com.In the User authorization callback URL field, enter
https://<instance-name>.service-now.com/oauth_redirect.do.In the Identifying and authorizing users section, deselect the Expire user authorization tokens field.
In the Webhook section, select the Active field.
In the Webhook URL field, enter
https://<instance-name>.service-now.com/api/sn_devops/v2/devops/tool/apps?toolId=<Tool ID>, where Tool Id is your GitHub tool id (sys_id) from DevOps Change Velocity.Note:
If you are newly creating the tool and don't have the Tool ID, you can enter the webhook URL without the Tool ID and configure it later. To configure later:
- Navigate to the connected tool's tool record page.
- Select Configure GitHub App, then select Auto configure with existing token.
Auto configure with existing token.
This configures the Webhook URL of the GitHub App automatically.
You can get the Tool ID in one of the following ways:
- While connecting with the tool in DevOps Change Velocity, the Tool Id is available in the page URL. For example, `https://<instance-name>.service-now.com/.../sn_devops_tool/<Tool ID>/...`.
- You can copy the webhook URL from the GitHub tool record page in DevOps Change Velocity, from **Configure** > **Configure manually** > **Webhook URL**.
Leave the remaining fields empty (default).
In the Repository permissions section, configure the following settings.
| Action | Read-only |
| Checks | Read-only |
| Contents | Read-only |
| Deployments | Read and write |
| Environments | Read-only |
| Metadata | Read-only |
| Pull requests | Read-only |
| Secrets | Read-only |
| Webhooks | Read and writeNote: Read and write permissions are required to configure webhooks from ServiceNow. |
**Note:** If you are already using a GitHub App and you update any of the permissions, you must review and accept those permissions for your GitHub App. You can navigate to your app, and select **Configure > Review request > Accept new permissions**.
Leave the remaining permissions as
No access(default).In the Subscribe to events section, select the Deployment protection rule option.
Save the changes.
After creating the GitHub App, generate a new private key and save it to your machine.
Install the newly created GitHub App on the accounts of your choice.
From the GitHub Apps settings page, select your app.
In the left sidebar, select Install App.
Select Install next to the organization or personal account containing the correct repository.
Install the app on all repositories or select repositories.
For more information, see Installing GitHub Apps.
Generate the Java KeyStore certificate for GitHub
Generate a Java KeyStore (JKS) certificate for the JWT authentication.
Before you begin
Role required: admin
Procedure
Create a CA signed certificate using the GitHub App private key:
openssl req -new -x509 -key <file-name>.pem -out <certificate-name>.pem -days 1095Enter the required details.
Create the PKCS 12 file using the GitHub App private key and CA signed certificate:
openssl pkcs12 -export -in <certificate-name>.pem -inkey <file-name>.pem -certfile <certificate-name>.pem -out <PKCS-12-file-name>.p12Provide the export password.
Create the JKS file:
keytool -importkeystore -srckeystore <PKCS-12-file-name>.p12 -srcstoretype pkcs12 -destkeystore <JKS-certificate-filename>.jks -deststoretype JKSProvide the destination and source keystore passwords.
Attach the GitHub Java KeyStore certificate to your instance
Enable the JWT Bearer Grant token authentication by attaching the valid GitHub Java KeyStore (JKS) certificate to your ServiceNow instance.
Before you begin
Ensure the availability of a valid Java KeyStore certificate.
Role required: admin
Procedure
Navigate to All > System Definition > Certificates.
Select New.
On the form, fill in the fields.
Field Description Name Name to uniquely identify the record. For example, My GitHub App Certificate.Notify on expiration Option to specify the users to be notified when the certificate expires. Warn in days to expire Number of days to send a notification before the certificate expires. Active Option to enable the certificate. Type Option to select the type of the certificate. Select Java Key Store. Expires in days Number of days until the certificate expires. Key store password Password associated with the certificate (hint: the destination KeyStore password previously created). Short description Summary about the certificate. Select the attachments icon (
Attachments icon\) and attach a JKS certificate.
- Select Validate Stores/Certificates.
Create a JWT signing key for the GitHub JKS certificate
Create a JSON Web Token (JWT) signing key to assign to your GitHub Java KeyStore certificate.
Before you begin
Role required: admin, sn_devops.admin
Procedure
Navigate to All > System OAuth > JWT Keys.
Select New.
On the form, fill in the fields.
Field Description Name Name to uniquely identify the JWT signing key. For example, My GitHub App JWT Key.Signing Keystore Valid JKS certificate attached in the previous task. For example, My GitHub App Certificate.Key Id Unique Id to identify which key is used when multiple keys are used to sign tokens. Signing Algorithm Algorithm to sign with the JWT key (hint: RSA 256). Signing Key Password Password associated with the signing key (hint: the source keystore password previously created). Active Option to enable the key. Select Submit.
Create a JWT provider for your GitHub signing key
Add a JSON Web Token (JWT) provider to your ServiceNow instance for GitHub.
Before you begin
Role required: admin, sn_devops.admin
Procedure
Navigate to All > System OAuth > JWT Providers.
Select New.
On the form, fill in the fields.
Field Description Name Name to uniquely identify the JWT provider. For example, My GitHub App JWT Provider.Expiry Interval (sec) Number in seconds to set the lifespan of JWT provider tokens (Hint: You can leave it as default). Signing Configuration Valid JWT signing key previously created. For example, My GitHub App JWT Key.Right-click the form header, and select Save.
Enter your GitHub App App ID (available in the About section of your GitHub App configuration in GitHub ) as the value of the iss claim, in the Standard Claims related list.
Leave aud and sub values blank (default).
Register GitHub as an OAuth Provider (JWT)
Use the information generated during GitHub App account configuration to register GitHub as an OAuth provider and allow the instance to request OAuth 2.0 tokens.
Before you begin
Role required: admin, sn_devops.admin
Procedure
Navigate to All > System OAuth > Application Registry.
Select New.
The What kind of OAuth application? message is displayed.
Select Connect to a third party OAuth Provider.
On the form, fill in the fields.
| Field | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Name | Name to uniquely identify the record. For example, enter `My GitHub App Provider`. | ||||||||
| Client ID | Client ID of your GitHub App (hint: available in the About section of your GitHub App configuration in GitHub ). | ||||||||
| Client Secret | Client secret of your GitHub App (hint: available in the About section of your GitHub App configuration in GitHub ). | ||||||||
| OAuth API script | Option that enables you to reference an amended OAuthUtil script include. Select OAuthDevOpsGitHubJWTHandler. | ||||||||
| Default Grant type | Type of grant associated with application registry. Select JWT Bearer. | ||||||||
| Token URL | The location of the token endpoint that the instance uses to retrieve and refresh tokens. For cloud version, enter: `https://api.github.com/app/installations/
Image omitted: github-oauth-jwt-app-registries.png Application Registry form
Image omitted: github-oauth-provider.png Form that shows the result field is set to track. Create a credential record for GitHub App provider (JWT)Create a credential record to the GitHub App provider previously created to authorize actions. Before you beginRole required: admin, sn_devops.admin Procedure
Related topics ServiceNow DevOps custom actions from GitHub marketplace GitHub Deployment Gates for ServiceNow DevOps Change |