Credentials are used when a Dispatchfile is executed, to push images and clone source repositories. These credentials are attached to an individual service account that is specified when a Dispatch repository is created. The Dispatchfile’s tasks then have access to only those credentials that have been attached to the specified service account.
A Dispatch repository’s Dispatchfile is executed in the context of a specific Kubernetes service account. The Dispatchfile’s tasks use credentials attached to that service account in order to push/pull docker images from a registry or clone git repositories. These credentials are stored as Kubernetes secrets with special structure and annotations.
Create a service account
Before registering a new repository with Dispatch, you must create a service account and attach credentials to it.
-
Create a service account using the dispatch CLI as follows:
dispatch serviceaccount create team-1
This creates a service account named
team-1
.
Setting up Github credentials
-
Set up credentials for the
team-1
service account to access the source control management service on behalf of your account.GitHub
Create a Personal Access Token for your GitHub account. You must specify the following permissions:
- FULL access to
admin:repo_hook
: used to register webhooks to report events to Dispatch. - FULL access to
repo
: used to pull and/or push source code whether public or private, report build statuses to your commits, etc.
After creating the token, remember the secret value. Replace
$GITHUB_TOKEN
with the secret value in the following command:dispatch login github --service-account team-1 --user $GITHUB_USER --token $GITHUB_TOKEN
GitLab
Create a Personal Access Token for your GitLab account. The token should have the following scopes:
api
: used to register webhooks to report events to Dispatch and report build statuses to your commits, etc.write_repository
: used to pull and/or push source code whether public or private.
After creating the token, remember the secret value. Replace
$GITLAB_TOKEN
with the secret value in the following command:dispatch login gitlab --service-account team-1 --user $GITLAB_USER --token $GITLAB_TOKEN
BitBucket Cloud
Create an App Password for your Bitbucket Cloud account. The app password should have the following permissions:
- Repositories read and write: used to pull and/or push source code whether public or private, report build statuses to your commits, etc.
- Pull requests read and write: used to obtain and/or update pull request information.
- Webhooks read and write: used to register webhooks to report events to Dispatch.
After creating the app password, remember the secret value. Replace
$BITBUCKET_APP_PASSWORD
with the secret value in the following command:dispatch login bitbucket-cloud --service-account team-1 --user $BITBUCKET_USER --app-password $BITBUCKET_APP_PASSWORD
Bitbucket Server
Create a Personal Access Token for your Bitbucket Server account. The token should have the following permissions:
- Projects: read
- Repositories: admin
These permissions allow Dispatch to do the following:
- Perform pull request actions
- Update repository settings and permissions
- Push, pull, and clone repositories
After creating the token, remember the secret value. Replace
$BITBUCKET_TOKEN
with the secret value in the following command:dispatch login bitbucket-server --service-account team-1 --user $BITBUCKET_USER --app-password $BITBUCKET_TOKEN
- FULL access to
-
Set up Git SSH credentials if you want to trigger a build locally.
-
Generate an SSH key pair:
ssh-keygen -t ed25519 -f dispatch.pem
This generates two files:
- The SSH private key
dispatch.pem
(never copy or share this file anywhere you do not trust). - The SSH public key
dispatch.pem.pub
which corresponds to thedispatch.pem
private key file. This file is safe to copy or share publicly.
- The SSH private key
-
Add the SSH public key to your source control management service.
GitHub
- Visit https://github.com/settings/keys
- Click “New SSH key”.
- Give the key an appropriate title like “Dispatch test 1”.
- Run
cat ./dispatch.pem.pub
in your terminal, copy the output, and paste it in the “Key” text box on the page. - Click “Add SSH key”.
GitLab
- Visit https://gitlab.com/profile/keys
- Run
cat ./dispatch.pem.pub
in your terminal, copy the output, and paste it in the “Key” text box on the page. - Give the key an appropriate title like “Dispatch test 1”.
- Click “Add key”.
BitBucket Cloud
- Visit https://bitbucket.org/account/settings/ssh-keys/
- Click “Add key”.
- Give the key and appropriate label like “Dispatch test 1”.
- Run
cat ./dispatch.pem.pub
in your terminal, copy the output, and paste it in the “Key” text box on the page. - Click “Add key”.
BitBucket Server
- Click your profile picture at the upper-right corner of the web UI of your on-prem Bitbucket Server instance.
- Click “Manage account” in the drop-down manu to go to the “Account” page.
- Click “SSH keys” from the list manu.
- Click “Add key”.
- Run
cat ./dispatch.pem.pub
in your terminal, copy the output, and paste it in the “Key” text box on the page. - Click “Add key”.
-
Now that we’ve registered the SSH public key with the source control management service, we can add the corresponding SSH private key to the
team-1
service account:dispatch login git --service-account team-1 --private-key-path ./dispatch.pem
-
Setting up Docker credentials
Set up credentials for the team-1
service account to access the docker registry service on behalf of your account.
-
To store Docker registry credentials, run the
login docker
subcommand and specify the service account to attach the credentials to by mentioningusername
andpassword
:dispatch login docker --service-account team-1 --username $YOURDOCKERUSERNAME --password $YOURDOCKERPASSWORD
Alternatively, specify a non default registry endpoint as well:
dispatch login docker --service-account team-1 --username $YOURDOCKERUSERNAME --password $YOURDOCKERPASSWORD --registry https://us.gcr.io
Note The
--password
can be a token instead of docker password (useful for accounts protected by 2FA)