Buildkite integration
Chinmina Bridge can be integrated as a Git credentials helper, or used directly to create a token.
Git authentication via helper
Section titled “Git authentication via helper”There is a handy plugin that facilitates using Chinmina Bridge for Git authentication: the Chinmina Git Credentials Buildkite plugin.
There are two cooperating parts to the plugin:
- An
environmenthook to configure a Chinmina Git credentials helper using environment variables. - A Chinmina Bridge Git credentials helper. This is a simple bash script that will be called by Git (as configured in the environment).
Chinmina Bridge has an endpoint that returns credentials in the Git credential helper format.
How it works
Section titled “How it works”The following gives a high-level overview of the actions performed when the credential helper is configured in Git.
In essence, Git calls the Credential Helper, which defers to Chinmina (authenticated with an OIDC token for this pipeline). Chinmina returns a result in the Git credentials helper format containing the required username, and the token created for the pipeline.
Configuration
Section titled “Configuration”On pipeline steps
Section titled “On pipeline steps”Like other Buildkite plugins, this plugin can be enabled on commands steps. For example:
steps: - command: ls plugins: - chinmina/chinmina-git-credentials#v1.0.2: chinmina-url: "https://chinmina-bridge-url" audience: "chinmina:your-github-organization"In order for this plugin to work for a whole pipeline, it must be enabled on every step. This includes any steps configured in the pipeline configuration.
In practice, this becomes quite repetitive and prone to misconfiguration. The only other option available is configuring the plugin on the agent: see below for instructions.
Parameters
Section titled “Parameters”chinmina-url (Required, string)
Section titled “chinmina-url (Required, string)”The URL of the chinmina-bridge helper agent that vends a
token for a pipeline. This is a separate HTTP service that must be accessible to
your Buildkite agents.
audience (string)
Section titled “audience (string)”Default: chinmina:default
The value of the aud claim of the OIDC JWT that will be sent to
chinmina-bridge. This must correlate with the value
configured in the chinmina-bridge settings.
A recommendation: chinmina:your-github-organization. This is specific
to the purpose of the token, and also scoped to the GitHub organization that
tokens will be vended for. chinmina-bridge’s GitHub app is configured for a
particular GitHub organization/user, so if you have multiple organizations,
multiple agents will need to be running.
Chinmina token plugin
Section titled “Chinmina token plugin”Another handy library plugin that facilitates fetching github token from Chinmina for the current repository or for an requested org profile: the Chinmina Token Buildkite plugin.
There are two parts to the plugin:
- An
environmenthook to configure the variables used by thechinmina_tokenscript and
adding the script to the PATH. - A
chinmina_tokenscript. This is a simple bash script which either uses the cached buildkite oidc token from thecredential helperif still available or generates a new one and perform a call to thetokenendpoint in Chinmina to fetch a Github token.
Chinmina Bridge has an token endpoint that returns credentials in JSON format.
Configuration
Section titled “Configuration”On pipeline steps
Section titled “On pipeline steps”Like other Buildkite plugins, this plugin can be configured in the following way:
steps: plugins: - chinmina/chinmina-token#v1.0.0: chinmina-url: "https://chinmina-bridge-url" audience: "chinmina:your-github-organization"In order for this plugin to work for a whole pipeline, it must be enabled on every step. This includes any steps configured in the pipeline configuration.
In practice, this becomes quite repetitive and prone to misconfiguration. The only other option available is configuring the plugin on the agent: see below for instructions.
To get a GitHub token, then fetch a private GitHub release asset (example usage), would be the following:
# use the helper function to get a tokenexport GITHUB_TOKEN=$(chinmina_token "org:profile-name")
# The GH CLI will use GITHUB_TOKEN as its authorization for any API requests:
# ... show this to the consolegh auth status
# ... download a release from a private repogh releases download --repo "${repo}" \ --pattern "release-file=${arch}.zip" \ --dir "${directory}" \ "${tag}"Parameters
Section titled “Parameters”chinmina-url (Required, string)
Section titled “chinmina-url (Required, string)”The URL of the chinmina-bridge helper agent that vends a
token for a pipeline. This is a separate HTTP service that be accessible to
your Buildkite agents.
audience (string)
Section titled “audience (string)”Default: chinmina:default
The value of the aud claim of the OIDC JWT that will be sent to
chinmina-bridge. This must correlate with the value
configured in the chinmina-bridge settings.
A recommendation: chinmina:your-github-organization. This is specific
to the purpose of the token, and also scoped to the GitHub organization that
tokens will be vended for. chinmina-bridge’s GitHub app is configured for a
particular GitHub organization/user, so if you have multiple organizations,
multiple agents will need to be running.
Enable on the agent (all pipelines)
Section titled “Enable on the agent (all pipelines)”This method enables the plugin in the agent environment hook, using a plugin
version that has been downloaded in the agent bootstrap.
This will enable the functionality to fetch Github token and authenticate via Chinmina Bridge on all builds running on the agent.
-
Alter the agent
bootstraphook to clone the plugin source to the agent so it can be activated by any step.Terminal window plugin_repo="https://github.com/chinmina/chinmina-token-buildkite-plugin.git"plugin_version="v1.0.0"plugin_dir="/buildkite/plugins/chinmina-token-buildkite-plugin"[[ -d "${plugin_dir}" ]] && rm -rf "${plugin_dir}"GIT_CONFIG_COUNT=1 \GIT_CONFIG_KEY_0=advice.detachedHead \GIT_CONFIG_VALUE_0=false \git clone --depth 1 --single-branch --no-tags \--branch "${plugin_version}" -- \"${plugin_repo}" "${plugin_dir}" -
Call the plugin’s
environmenthook directly from the agent’senvironmenthook, specifying the plugin parameters directly.Execute plugin environment hook directly BUILDKITE_PLUGIN_CHINMINA_TOKEN_CHINMINA_URL="${BUILDKITE_PLUGIN_CHINMINA_TOKEN_CHINMINA_URL:-https://chinmina.url-to-instance.io}" \BUILDKITE_PLUGIN_CHINMINA_TOKEN_AUDIENCE="${BUILDKITE_PLUGIN_CHINMINA_TOKEN_AUDIENCE:-chinmina:your-org}" \source /buildkite/plugins/chinmina-token-buildkite-plugin/hooks/environment