GitHub Bot
Monitor, alert, and discover sensitive data in your code for each commit. Get instant feedback on any commit you push to your repository. Spectral Bot can be installed directly on organizations and user accounts and grant access to specific repositories. By default, only one instance the bot can be deployed to a region. To deploy more than one instance of GitHub bot to the same region, contact Customer Support.
Integration Environment Variables
Name |
Required |
Description |
Valid Values |
Default |
---|---|---|---|---|
|
Yes |
GitHub app id |
|
|
|
Yes |
If Spectral finds issues in a PR - how should we handle the PR check? The policies are based on the Spectral issue severity - critical, high, medium, low, and informational |
|
|
|
No |
Include detectors by tag, separated by comma |
|
|
|
No |
Engines list to run Spectral with, separated by commas |
|
|
|
No |
Your Spectral DSN retrieved from SpectralOps (leave empty if you are using vault) |
|
|
|
No |
The GitHub app webhook secret, any strong secret would be fine (leave empty if you are using vault) |
|
|
|
No |
GitHub app private key base64 encoded (leave blank if stored in vault) |
|
|
|
No |
The vault you're storing your secrets in |
aws_secrets_manager |
|
|
No |
The key in the vault where the Spectral DSN is stored. should be in the format of |
|
|
|
No |
The key in the vault where the GitHub webhook secret is stored. should be in the format of |
|
|
|
No |
The key in the vault where the GitHub private key is stored. should be in the format of |
|
|
|
No |
Add a custom text to the pull request comment and check summary - Markdown format |
|
|
|
No |
If set to true - findings won't be sent to SpectralOps and won't be seen in your dashboard |
|
|
|
No |
Should review comments be posted on PR files where Spectral has identified issues |
|
|
|
No |
Disable GitHub check creation |
|
|
|
No |
Name of the bucket containing the blacklist file |
|
|
|
No |
Blacklist file S3 object key |
|
|
|
No |
If set to true - issues from changed files in the PR will fail the check even if the issues are in lines that hasn't been modified |
|
|
|
No |
If the environment does not automatically set this variable, specify a path to an existing location that has write permissions. For example, in AWS Lambda |
|
|
|
No |
Provide the domain if you're running a self-hosted Github (for example: https://my-github-domain.com). |
|
|
|
No |
The SSL certificate content for on-prem Github. Use this variable if not using AWS |
|
|
|
No |
The vault key to retrieve the custom SSL certificate. |
|
|
Configuring Code Security Github Bot
-
Create a new GitHub app:
-
Select on which depositories to install the app:
-
All repositories (applies to all current and future repositories owned by the resource owner)
-
Only select repositories
-
-
Use one of these methods to deploy the bot:
Method
How to Deploy
Cloud Formation
Prerequisite
These permissions are required in your AWS account:
Copylambda:GetAccountSettings
cloudformation:DescribeStacks
iam:CreateRole
iam:DeleteRole
apigateway:POST
logs:CreateLogGroup
iam:PutRolePolicyProcedure
-
In AWS, launch the stack.
-
In the settings of your new GitHubb app, generate a private key.
-
Encode the private key in base64 without line breaks. Example OpenSSL command:
openssl base64 -A -in YOUR-PRIVATE-KEY.pem
-
In AWS > GITHUB_PRIVATE_KEY field, enter the private key that you created in the previous step.
-
For Check Policy, select one of these:
-
Fail on any issue
-
Fail on critical only
-
Fail on high and above
-
Fail on medium and above
-
Fail on low and above
-
Always pass
-
-
Set the value of the STRICT_MODE parameter. If this parameter is true, the status check runs on all issues. If this parameter is set to false, the status check runs only for new issues.
Terraform - Deploy AWS resources using the Code Security Terraform module. Set the value of the
integration_type
parameter togithub
).Note: The Terraform deployment is supported starting from GitHub bot 2.x versions.
Follow the deployment instructions in the Code Security DockerHub repo.
-
-
Go to the GitHub app settings page.
-
In the Webhook section, enter these values:
-
Webhook URL
-
Webhook secret
Note - In AWS Lambda, to generate the webhook URL, append
/api/github/event
to the ServiceEndpoint output from this stack:https://<id>.execute-api.<region>.amazonaws.com/prod/api/github/event
Note - In Docker, to generate the webhook URL, append
/events/github
to the URL for your container:https://<container-domain>/events/github
-
-
In the Webhook section, set the Webhook to active.
Using a Vault
We recommend to store your secrets in a vault instead of directly in the configuration of your Lambda. Only AWS Secret Manager is supported.
To use AWS Secret Manager to store your secrets:
-
In Code Security, set the value of the
SECRETS_VAULT
environment variable toaws_secrets_manager
. -
In your vault, set these secrets:
Secret
Value
GITHUB_PRIVATE_KEY
Spectral_GithubBot_PrivateKey
GITHUB_WEBHOOK_SECRET
Spectral_GithubBot_WebhookSecre
tSPECTRAL_DSN
Spectral_Dsn
Using Custom Vault Keys
Use these Code Security integration environment variables to create custom secret vault keys:
|
Note - If you use AWS Secrets Manager with a CloudFormation or Terraform deployment, the role you created for the Lambda functions gives permission to perform the action only for the default secrets. |
Integration Environment Variable |
Description |
---|---|
|
Spectral DSN key name, in this format: |
|
GitHub app webhook secret, in this format: |
|
Private key, in this format:
|
|
Optional - This is a key for a vault that contains a self-signed certificate. Default value: |
Advanced Configuration: Excluding Repositories
To exclude specific repositories from the scan, add them to an exclusion list of repo URLs.
-
Create a text file containing a list of full URLs of repositories to exclude (for example: https://github.com/expressjs/express). Put each URL on a new line in the file.
-
In Code Security, define these integration environment variables:
Integration Environment Variable
Description
S3_BLACK_LIST_BUCKET_NAME
The name of the bucket containing the exclusion list file
S3_BLACK_LIST_OBJECT_KEY
The object key of the exclusion list file
Advanced Configuration: Configuring Multiple GitHub Apps with a Single Instance of Code Security Bot
To configure mutliple GitHub apps with a single instance of Code Security bot, configure a multi_app.json file in the root directory and add it to the frontend and backend Lambda functions.

The GitHub object is a dictionary containing all of the GitHub Apps. For each app, you must set the private_key, which is a base64-encoded string of the GitHub App's private key. In the <app_id>
Procedure
-
In the AWS Lambda deployment, in the root directory, open the multi_app.json file.
-
In the <app_id> section, enter the GitHub App ID to configure a specific application.
-
Optional - Configure one or more of these optional parameters:
Parameter
Description
check_failure_policy
Determines the failure policy for scans from this specific GitHub App. If not set, it defaults to
CHECK_POLICY
. Refer to the table above for possible values.spectral_dsn
Allows splitting scans using a different DSN for this GitHub App. It defaults to
SPECTRAL_DSN
.webhook_token
Allows using a webhook secret for this GitHub App. It defaults to
GITHUB_WEBHOOK_SECRET
.secret_vault
Enables storing secrets (webhook secret, app private key, spectral DSN) in a vault at the app level. When using a vault, you must specify all the keys for the webhook secret, GitHub App private key, and optional spectral DSN.
self_hosted_domain
Allows self hosted domain for this GitHub App. It defaults to
GITHUB_SELF_HOSTED_DOMAIN
.
Example multi_app.json Configuration File
{
"github": {
"<app_id>": {
"private_key": "",
"spectral_dsn": "",
"webhook_token": "",
"self_hosted_domain": "",
"secret_vault": {
"name": "aws_secrets_manager",
"key_webhook_secret": "",
"key_private_key": "",
"key_spectral_dsn": "",
"key_ssl_certificate": "",
}
}
}
}

-
Download and unzip the Lambda code:
-
Download the Lambda code as a .zip file.
-
Unzip the downloaded file.
-
-
Add the multi_app.json configuration file you edited in Step 1 to the unzipped directory.
-
Re-zip the configuration file and upload it to the Lambda:
-
Select all of the files in the unzipped directory.
-
Zip the files.
-
Upload the new .zip file to AWS Lambda. Make sure that the multi_app.json configuration file is in the .zip file.
-
Monitoring Code Security Github Bot with CloudWatch alarms
We recommend to monitor GitHub Bot errors using CloudWatch alarms in AWS Lambda. Follow this procedure in CloudWatch:
-
Click Create Alarm.
-
Click Select Metric.
-
Select the Errors metric for the Lambda.
-
Click Select Metric.
-
Set the statistic to Sum and select the required period to measure the threshold.
-
In the Conditions section:
-
For threshold, select static.
-
Select Greater.
-
Set the threshold value to 1 or a greater number.
-
Click Next.
-
-
Add the email addresses to receive the alarm.
-
Click Next.
-
Enter a name for the alarm.
-
Click Next.
-
Read the summary. If the configuration is correct, click OK.
Upgrading the Github Bot
The Code Security GitHub bot is versioned.
To upgrade the l GitHub bot with Lambda:
In Lambda, in the Code tab, upload a new .zip file of the Github bot. Upload the new version to the frontend Lambda and to the backend Lambda.
To upgrade the GitHub bot with Docker:
Deploy a new GitHub bot image from the docker hub.