-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Machine ID: Documentation for Bitbucket Pipelines joining #49172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
timothyb89
merged 3 commits into
master
from
timothyb89/bitbucket-pipelines-joining-docs
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
docs/pages/enroll-resources/machine-id/deployment/bitbucket.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| --- | ||
| title: Deploying Machine ID on Bitbucket Pipelines | ||
| description: How to install and configure Machine ID on Bitbucket Pipelines | ||
| --- | ||
|
|
||
| In this guide, you will configure Machine ID's agent, `tbot`, to run within a | ||
| Bitbucket Pipelines workflow. The bot will be configured to use the `bitbucket` | ||
| delegated joining method to eliminate the need for long-lived secrets. | ||
|
|
||
| ## How it works | ||
|
|
||
| The `bitbucket` join method is a secure way for Machine ID bots to authenticate | ||
| with the Teleport Auth Service without using any shared secrets. Instead, it | ||
| makes use of an OpenID Connect token that Bitbucket Pipelines injects into the | ||
| job environment. | ||
|
|
||
| This token is sent to the Teleport Auth Service, and assuming it has been | ||
| configured to trust Bitbucket's identity provider and all identity assertions | ||
| match, the authentication attempt will succeed. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| (!docs/pages/includes/edition-prereqs-tabs.mdx!) | ||
|
|
||
| - (!docs/pages/includes/tctl.mdx!) | ||
| - A Bitbucket repository you can push to. | ||
|
|
||
| ## Step 1/4. Determine Bitbucket configuration | ||
|
|
||
| Bitbucket joining requires a number of configuration parameters that can be | ||
| found in your repository settings. From the Bitbucket repository, navigate to | ||
| "Repository settings", then in the sidebar under "Pipelines" select "OpenID | ||
| Connect". | ||
|
|
||
| From this page, note the following values: | ||
| - Identity provider URL (<Var name="identity-provider-url" />) | ||
| - Audience (<Var name="audience" />) | ||
| - Workspace UUID, including the braces (<Var name="workspace-uuid" />) | ||
| - Repository UUID, including the braces (<Var name="repository-uuid" />) | ||
|
|
||
| ## Step 2/4. Create the Machine ID bot | ||
|
|
||
| (!docs/pages/includes/machine-id/create-a-bot.mdx!) | ||
|
|
||
| ## Step 3/4. Create the join token for Bitbucket Pipelines | ||
|
|
||
| In order to allow your Pipelines workflow to authenticate with your Teleport | ||
| cluster, you'll first need to create a join token. These tokens set out criteria | ||
| by which the Auth Service decides whether or not to allow a bot or node to join. | ||
|
|
||
| Create a file named `bot-token.yaml`, ensuring that you replace the | ||
| `identity_provider_url`, `audience`, `workspace_uuid`, and `repository_uuid` | ||
| with the values from Step 1. | ||
|
|
||
| ```yaml | ||
| kind: token | ||
| version: v2 | ||
| metadata: | ||
| name: example-bot | ||
| spec: | ||
| roles: [Bot] | ||
| join_method: bitbucket | ||
| bot_name: example | ||
| bitbucket: | ||
| identity_provider_url: <Var name="identity-provider-url" /> | ||
| audience: <Var name="audience" /> | ||
| # allow specifies the rules by which the Auth Service determines if `tbot` | ||
| # should be allowed to join. | ||
| allow: | ||
| - workspace_uuid: <Var name="workspace-uuid" /> | ||
| repository_uuid: <Var name="repository-uuid" /> | ||
| ``` | ||
|
|
||
| Let's go over the token resource's fields in more detail: | ||
|
|
||
| - `metadata.name` defines the name of the token. Note that this value will need | ||
| to be used in other parts of the configuration later. | ||
| - `spec.bot_name` is the name of the Machine ID bot that this token will grant | ||
| access to. Note that this value will need to be used in other parts of the | ||
| configuration later. | ||
| - `spec.roles` defines which roles that this token will grant access to. The | ||
| value of `[Bot]` states that this token grants access to a Machine ID bot. | ||
| - `spec.join_method` defines the join method the token is applicable for. Since | ||
| this guide only focuses on Bitbucket Pipelines, you will set this to to | ||
| `bitbucket`. | ||
| - `spec.bitbucket.identity_provider_url` is the identity provider URL shown in | ||
| the Bitbucket repository settings, under Pipelines and OpenID Connect. | ||
| - `spec.bitbucket.audience` is the audience value shown in the Bitbucket | ||
| repository settings, under Pipelines and OpenID connect. | ||
| - `spec.bitbucket.allow` is used to set rules for what Bitbucket Pipelines runs | ||
| will be able to authenticate by using the token. | ||
|
|
||
| Refer to the [token reference](../../../reference/join-methods.mdx#bitbucket-pipelines-bitbucket) | ||
| for a full list of valid fields. | ||
|
|
||
| Apply this to your Teleport cluster using `tctl`: | ||
|
|
||
| ```code | ||
| $ tctl create -f bot-token.yaml | ||
| ``` | ||
|
|
||
| ## Step 4/4. Configure a Bitbucket Pipelines workflow | ||
|
|
||
| With the bot and join token created, you can now configure a workflow that can | ||
| authenticate to Teleport. | ||
|
|
||
| This example workflow defines a "custom" pipeline that can be triggered manually | ||
| from "Pipelines" or "Branches" views: | ||
|
|
||
| ```yaml | ||
| image: atlassian/default-image:3 | ||
|
|
||
| pipelines: | ||
| custom: | ||
| run-tbot: | ||
| - step: | ||
| oidc: true | ||
| script: | ||
| # Download and extract Teleport | ||
| - wget https://cdn.teleport.dev/teleport-v(=teleport.version=)-linux-amd64-bin.tar.gz | ||
| - tar -xvf teleport-v(=teleport.version=)-linux-amd64-bin.tar.gz | ||
|
|
||
| # Run `tbot` in identity mode for SSH access | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will have to change this if we backport bitbucket to v16, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, I'll tweak this in the backport to borrow step 5 from the other guides. |
||
| - ./teleport/tbot start identity --destination=./tbot-user --join-method=bitbucket --proxy-server=example.teleport.sh:443 --token=bot-bitbucket --oneshot | ||
|
|
||
| # Make use of the generated SSH credentials | ||
| - ssh -F ./tbot-user/ssh_config user@node.example.teleport.sh echo "hello world" | ||
| ``` | ||
|
|
||
| This example will start `tbot` in identity mode to generate SSH credentials. | ||
| Refer to the [`tbot start` documentation](../../../reference/cli/tbot.mdx#tbot-start) | ||
| for details on using other modes such as database, application, and Kubernetes | ||
| access. | ||
|
|
||
| If you're adapting an existing workflow, note these steps: | ||
| 1. Set `oidc: true` on the step properties so that step will be issued a token | ||
| 1. Download and extract a `.tar.gz` Teleport build | ||
| 1. Run `tbot` with `--join-method=bitbucket`, `--token=example-bot` (or | ||
| whichever name was configured in Step 3), and `--oneshot` | ||
|
|
||
| <Admonition type="warning" title="Sharing credentials between steps"> | ||
| Note that in Bitbucket Pipelines, outputs cannot be securely shared between | ||
| steps as anything stored using `artifacts` will remain downloadable once the CI | ||
| run has completed. | ||
|
|
||
| Due to this limitation, all operations making use of Teleport credentials should | ||
| be performed as part of the same step. If necessary, you can duplicate the | ||
| script shown here to download and run `tbot` multiple times in a given run if | ||
| credentials are needed in multiple steps. | ||
| </Admonition> | ||
|
|
||
| ## Further steps | ||
|
|
||
| - Follow the [access guides](../access-guides/access-guides.mdx) to finish configuring `tbot` for | ||
| your environment. | ||
| - Read the [configuration reference](../../../reference/machine-id/configuration.mdx) to explore | ||
| all the available configuration options. | ||
| - For more information about Bitbucket Pipelines itself, read | ||
| [their documentation](https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/). | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ```yaml | ||
| kind: token | ||
| version: v2 | ||
| metadata: | ||
| name: example-bot | ||
| spec: | ||
| roles: [Bot] | ||
| join_method: bitbucket | ||
| bot_name: example | ||
| bitbucket: | ||
| # The URL of the workspace-specific OIDC identity provider. This can be | ||
| # found in the repository settings under "Pipelines" and "OpenID Connect". | ||
| identity_provider_url: $IDENTITY_PROVIDER_URL | ||
|
|
||
| # The audience of the OIDC tokens issued by Bitbucket. This can be found in | ||
| # the repository settings under "Pipelines" and "OpenID Connect". | ||
| audience: $AUDIENCE | ||
|
|
||
| # allow specifies the rules by which the Auth Server determines if `tbot` | ||
| # should be allowed to join. All parameters in a given allow entry must | ||
| # match for the join attempt to succeed, but many allow rules may be | ||
| # provided. One or both of `workspace_uuid` and `repository_uuid` are | ||
| # required; all other fields are optional. | ||
| allow: | ||
| - # The UUID of a workspace whose runs should be allowed to connect. This | ||
| # value can be found in the repository settings under "Pipelines" and | ||
| # "OpenID Connect". It must be enclosed in braces, i.e. `{...}`. At | ||
| # least `workspace_uuid` or `repository_uuid` must be provided. | ||
| workspace_uuid: '{WORKSPACE_UUID}' | ||
|
|
||
| # The UUID of a repository whose runs should be allowed to connect. This | ||
| # value can be found in the repository settings under "Pipelines" and | ||
| # "OpenID Connect". It must be enclosed in braces, i.e. `{...}`. At | ||
| # least `workspace_uuid` or `repository_uuid` must be provided. | ||
| repository_uuid: '{REPOSITORY_UUID}' | ||
|
|
||
| # If set, only steps tagged with the deployment environment linked to | ||
| # this UUID will be allowed to connect. This value can be found in the | ||
| # repository settings under "Pipelines" and "OpenID Connect" when a | ||
| # deployment environment is selected from the drop-down menu. It must be | ||
| # enclosed in braces, i.e. `{...}`. Optional. | ||
| deployment_environment_uuid: '{DEPLOYMENT_ENVIRONMENT_UUID}' | ||
|
|
||
| # If set, only workflows running on the named branch will be allowed to | ||
| # connect. Optional. | ||
| branch_name: "main" | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it's correct as written? "Bitbucket Pipelines" is a singular product so I think "injects" is correct here. If we said "Bitbucket pipelines" referring to individual workflows then we'd want the singular form, but I've tried to refer to them as "Bitbucket Pipelines workflows" or similar.
Amusingly, even Bitbucket frequently calls them workflows instead of pipelines.