Skip to content

Commit

Permalink
Enable Terraform Cloud joining for Teleport Community Edition (#46419)
Browse files Browse the repository at this point in the history
* Terraform Cloud joining: Support Terraform Enterprise issuers

This adds support for hostname/issuer overrides, needed to support
on-prem Terraform Enterprise installs. When the new `hostname` field
is unset, behavior is changed, but when set, the JWT is validated
against it instead of `app.terraform.io`.

Additionally, this renames `join_terraform.go` to
`join_terraformcloud.go`, since that was missed during the rename
in #45574.

* Enable Terraform Cloud joining for Teleport Community Edition

This enables Terraform Cloud joining for Community Edition when
using the public HCP Terraform SaaS. Teleport Enterprise is still
required for use with self-hosted Terraform Enterprise.

changelog: Enable Terraform Cloud joining for Teleport Community Edition when using HCP Terraform

* Fix unit tests

* Update lib/auth/join_terraformcloud.go

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>

* Fix linter

---------

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
  • Loading branch information
timothyb89 and tigrato committed Sep 13, 2024
1 parent 1003159 commit c9f5d14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/auth/join_terraformcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ func (a *Server) checkTerraformCloudJoinRequest(ctx context.Context, req *types.
return nil, trace.BadParameter("terraform_cloud join method only supports ProvisionTokenV2, '%T' was provided", pt)
}

if modules.GetModules().BuildType() != modules.BuildEnterprise {
hostnameOverride := token.Spec.TerraformCloud.Hostname
if hostnameOverride != "" && modules.GetModules().BuildType() != modules.BuildEnterprise {
return nil, fmt.Errorf(
"terraform_cloud joining: %w",
"terraform_cloud joining for Terraform Enterprise: %w",
ErrRequiresEnterprise,
)
}
Expand All @@ -68,7 +69,7 @@ func (a *Server) checkTerraformCloudJoinRequest(ctx context.Context, req *types.
}

claims, err := a.terraformIDTokenValidator.Validate(
ctx, aud, token.Spec.TerraformCloud.Hostname, req.IDToken,
ctx, aud, hostnameOverride, req.IDToken,
)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
1 change: 1 addition & 0 deletions lib/auth/join_terraformcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func TestAuth_RegisterUsingToken_Terraform(t *testing.T) {
ProjectName: "example-project",
},
},
Hostname: "terraform.example.com",
},
},
request: newRequest(validIDToken),
Expand Down

0 comments on commit c9f5d14

Please sign in to comment.