Bitbucket On-Premise Configuration
Overview
This page contains all the information needed to create a Guardrails Bitbucket user and application link on your Bitbucket server (or Bitbucket data center) instance. This is needed to allow guardrails to seamlessly integrate into the development workflow and makes onboarding all repositories in your organization easy and quick.
Only required for Bitbucket deployments.
IMPORTANT: For this guide we will assume that <YOUR_HOST>
will be the configured dns (i.e.: guardrails.your-company.com). So whenever you see a <YOUR_HOST>
remember this.
Create private/public keys
The goal of this step is to create a private and a public key that will be used to secure the communication between Guardrails and the Bitbucket server.
Generate the private/public key pairs by executing the following commands
mkdir guardrails-keys && cd guardrails-keys
openssl genrsa -out privatekey.pem 2048
openssl rsa -in privatekey.pem -outform PEM -pubout -out publickey.pem
You can view the private key by executing the following command:
cat privatekey.pcks8
We will refer to this output as <YOUR_PRIVATE_KEY>
in the steps below.
You can view the public key by executing the following command:
cat publickey.pem
We will refer to this output as <YOUR_PUBLIC_KEY>
in the steps below.
Create the GuardRails Application Link
The goal of this step is to create a Bitbucket server application link that we are going to use to connect to GuardRails to allow for a seamless integration of the security scanning across all repositories. GuardRails is tightly integrated into the workflow and provides a pleasant developer experience.
Create a Bitbucket application link for GuardRails in your Bitbucket server instance by following the instructions below:
- Login to
<bitbucket-domain>
as an administrative user - Go to
<bitbucket-domain>/plugins/servlet/applinks/listApplicationLinks
- Enter
https://<YOUR_HOST>
into the input box - Click on
Create new link
- Click on
Continue
. (Even if you get an error message that no response was received from the URL) - Fill out the details like below:
- Application Name:
Guardrails
- Application Type:
Generic Application
- (leave the rest of the fields blank)
- Application Name:
- Click on
Continue
- In the application list, click on the edit (pencil icon) on the right hand side of the
Guardrails
list item - Click on
Incoming Authentication
- Fill out the details like below:
- Consumer Key: (enter random characters, but you need to remember it as you will need it in a later step, we will refer to this as the
<CONSUMER_KEY>
) - Consumer Name:
Guardrails
- Description: (leave this blank)
- Public Key:
<YOUR_PUBLIC_KEY>
- Consumer Callback URL: (leave this blank)
- Allow 2-Legged OAuth: (leave unchecked)
- Consumer Key: (enter random characters, but you need to remember it as you will need it in a later step, we will refer to this as the
- Click on
Save
- Click on
Close
Self-signed Certificates
If you are using self-signed certificates for the GuardRails instance, then Bitbucket will not be able to connect to it by default and require some custom configuration steps to make it work.
The steps needed to set it up can be found at this Atlassian resource.
Create a Bitbucket User
The goal of this step is to create a privileged Bitbucket GuardRails user that will allow for a seamless integration of the security scanning across all repositories. We will also need the details to allow for a single-sign on authentication using your Bitbucket on-premise instance. Because of this step, GuardRails is tightly integrated into the workflow and provides a pleasant developer experience.
Create a Bitbucket user for GuardRails in your Bitbucket server instance by following the instructions below:
- Login to
<bitbucket-domain>
as an administrative user - Go to
<bitbucket-domain>/admin/users?create
- Fill out the user details like below:
- Username:
guardrails
- Full name:
GuardRails
- Email:
[email protected]
, this has to be filled out, but a valid email address is not required. - Password: (enter a password)
- Username:
- Click on
Create user
Give user admin permission
- Go to
<bitbucket-domain>/admin/permissions
- Click on the input box under "User access" that says "Add Users"
- Enter
guardrails
in the input box - In the dropdown list that says "Bitbucket User" select
Admin
- Click on
Add
Create a PAT for the new user
PAT = Personal Access Token
- Login to Bitbucket server as the user (guardrails) that you just created
- Navigate to
<bitbucket-domain>/plugins/servlet/access-tokens/manage
- Click on
Create a token
- Under
Token details
enter the following:- Token name:
guardrails-pat
- Token name:
- Under
Permissions
select the following:- Projects:
Admin
- Repositories:
Admin
- Projects:
- Click on
Create
- Now you will see your personal access token which you need to save for later use we will refer to this token as
<YOUR_PAT>
in later steps. - Click on
Continue
If you followed and completed the steps of this guide, you should have collected the following data in order to continue:
- Private Key For Communication Between Guardrails And Bitbucket
- Bitbucket Consumer Key For The Application Link
- Bitbucket User Personal Access Token (PAT)
Make sure you have this before you proceed to Setup & Deploy
Configure Pre-Receive Hooks
You can configure pre-receive hooks for Bitbucket on-premise versions by following the instructions here.