Skip to content
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

Machine ID: Add bitbucket join method for Bitbucket Pipelines joining #48724

Merged
merged 20 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
eda4a35
Add `bitbucket` join method for Bitbucket Pipelines joining
timothyb89 Nov 9, 2024
d902da1
Add unit tests for bitbucket joining
timothyb89 Nov 12, 2024
afd7b50
Fix imports
timothyb89 Nov 12, 2024
eab4ff8
Merge remote-tracking branch 'origin/master' into timothyb89/bitbucke…
timothyb89 Nov 12, 2024
a45b359
Update tf docs
timothyb89 Nov 12, 2024
b3b7e30
Docs update
timothyb89 Nov 12, 2024
fef4b82
Update generated TF resources
timothyb89 Nov 12, 2024
a898fb0
Merge remote-tracking branch 'origin/master' into timothyb89/bitbucke…
timothyb89 Nov 12, 2024
92ee2dc
Attempt to work around docs linter
timothyb89 Nov 12, 2024
253491c
Add provision token tests
timothyb89 Nov 12, 2024
fb2cabd
Remove pipeline_uuid and step_uuid from protos
timothyb89 Nov 15, 2024
d41526e
Remove references to removed fields in tests
timothyb89 Nov 19, 2024
418030e
Merge remote-tracking branch 'origin/master' into timothyb89/bitbucke…
timothyb89 Nov 19, 2024
a3f8bb1
Switch to go-oidc/v3 and remove now-redundant nbf check
timothyb89 Nov 20, 2024
e6b1cb3
Fix go.mod imports for the TF provider
timothyb89 Nov 20, 2024
d1aca30
Fix event-handler go.mod
timothyb89 Nov 20, 2024
0a6f425
Address review feedback; add 15s timeout to fetch provider metadata
timothyb89 Nov 21, 2024
1f2e7fb
Merge remote-tracking branch 'origin/master' into timothyb89/bitbucke…
timothyb89 Nov 21, 2024
66a852a
Update lib/bitbucket/token_validator.go
timothyb89 Nov 21, 2024
41e54c6
Fix build after constant rename
timothyb89 Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions api/proto/teleport/legacy/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,8 @@ message ProvisionTokenSpecV2 {
ProvisionTokenSpecV2TPM TPM = 15 [(gogoproto.jsontag) = "tpm,omitempty"];
// TerraformCloud allows the configuration of options specific to the "terraform_cloud" join method.
ProvisionTokenSpecV2TerraformCloud TerraformCloud = 16 [(gogoproto.jsontag) = "terraform_cloud,omitempty"];
// Bitbucket allows the configuration of options specific to the "bitbucket" join method.
ProvisionTokenSpecV2Bitbucket Bitbucket = 17 [(gogoproto.jsontag) = "bitbucket,omitempty"];
}

// ProvisionTokenSpecV2TPM contains the TPM-specific part of the
Expand Down Expand Up @@ -1661,6 +1663,51 @@ message ProvisionTokenSpecV2TerraformCloud {
string Hostname = 3 [(gogoproto.jsontag) = "hostname,omitempty"];
}

message ProvisionTokenSpecV2Bitbucket {
// Rule is a set of properties the Bitbucket-issued token might have to be
// allowed to use this ProvisionToken.
message Rule {
// WorkspaceUUID is the UUID of the workspace for which this token was
// issued. Bitbucket UUIDs must begin and end with braces, e.g. '{...}'.
// This value may be found in the Pipelines -> OpenID Connect section of the
// repository settings.
string WorkspaceUUID = 1 [(gogoproto.jsontag) = "workspace_uuid,omitempty"];

// RepositoryUUID is the UUID of the repository for which this token was
// issued. Bitbucket UUIDs must begin and end with braces, e.g. '{...}'.
// This value may be found in the Pipelines -> OpenID Connect section of the
// repository settings.
string RepositoryUUID = 2 [(gogoproto.jsontag) = "repository_uuid,omitempty"];

// PipelineUUID is the UUID of the pipeline for which this token was issued.
// Bitbucket UUIDs must begin and end with braces, e.g. '{...}'
string PipelineUUID = 3 [(gogoproto.jsontag) = "pipeline_uuid,omitempty"];

// StepUUID is the UUID of the pipeline step for which this token was
// issued. Bitbucket UUIDs must begin and end with braces, e.g. '{...}'
string StepUUID = 4 [(gogoproto.jsontag) = "step_uuid,omitempty"];

// BranchName is the name of the branch on which this pipeline executed.
string BranchName = 5 [(gogoproto.jsontag) = "branch_name,omitempty"];
}

// Allow is a list of Rules, nodes using this token must match one
// allow rule to use this token.
repeated Rule Allow = 1 [(gogoproto.jsontag) = "allow,omitempty"];

// Audience is a Bitbucket-specified audience value for this token. It is
// unique to each Bitbucket repository, and must be set to the value as
// written in the Pipelines -> OpenID Connect section of the repository
// settings.
string Audience = 2 [(gogoproto.jsontag) = "audience,omitempty"];

// IdentityProviderURL is a Bitbucket-specified issuer URL for incoming OIDC
// tokens. It is unique to each Bitbucket repository, and must be set to the
// value as written in the Pipelines -> OpenID Connect section of the
// repository settings.
string IdentityProviderURL = 3 [(gogoproto.jsontag) = "identity_provider_url,omitempty"];
}

// StaticTokensV2 implements the StaticTokens interface.
message StaticTokensV2 {
option (gogoproto.goproto_stringer) = false;
Expand Down
42 changes: 42 additions & 0 deletions api/types/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ const (
// JoinMethodTerraformCloud indicates that the node will join using the Terraform
// join method. See lib/terraformcloud for more.
JoinMethodTerraformCloud JoinMethod = "terraform_cloud"
// JoinMethodBitbucket indicates that the node will join using the Bitbucket
// join method. See lib/bitbucket for more.
JoinMethodBitbucket JoinMethod = "bitbucket"
)

var JoinMethods = []JoinMethod{
Expand Down Expand Up @@ -363,6 +366,17 @@ func (p *ProvisionTokenV2) CheckAndSetDefaults() error {
if err := providerCfg.checkAndSetDefaults(); err != nil {
return trace.Wrap(err, "spec.terraform_cloud: failed validation")
}
case JoinMethodBitbucket:
providerCfg := p.Spec.Bitbucket
if providerCfg == nil {
return trace.BadParameter(
"spec.bitbucket: must be configured for the join method %q",
JoinMethodBitbucket,
)
}
if err := providerCfg.checkAndSetDefaults(); err != nil {
return trace.Wrap(err, "spec.bitbucket: failed validation")
}
default:
return trace.BadParameter("unknown join method %q", p.Spec.JoinMethod)
}
Expand Down Expand Up @@ -862,3 +876,31 @@ func (a *ProvisionTokenSpecV2TerraformCloud) checkAndSetDefaults() error {

return nil
}

func (a *ProvisionTokenSpecV2Bitbucket) checkAndSetDefaults() error {
timothyb89 marked this conversation as resolved.
Show resolved Hide resolved
if len(a.Allow) == 0 {
return trace.BadParameter("the %q join method requires at least one token allow rule", JoinMethodBitbucket)
}

if a.Audience == "" {
return trace.BadParameter("audience: an OpenID Connect Audience value is required")
}

if a.IdentityProviderURL == "" {
return trace.BadParameter("identity_provider_url: an identity provider URL is required")
}

for i, rule := range a.Allow {
workspaceSet := rule.WorkspaceUUID != ""
repositorySet := rule.RepositoryUUID != ""

if !workspaceSet && !repositorySet {
return trace.BadParameter(
"allow[%d]: at least one of ['workspace_uuid', 'repository_uuid'] must be set",
i,
)
}
}

return nil
}
Loading
Loading