Skip to content

Introduce the tctl terraform env command#43664

Merged
hugoShaka merged 12 commits intomasterfrom
hugo/tctl-terraform-env
Jul 10, 2024
Merged

Introduce the tctl terraform env command#43664
hugoShaka merged 12 commits intomasterfrom
hugo/tctl-terraform-env

Conversation

@hugoShaka
Copy link
Copy Markdown
Contributor

@hugoShaka hugoShaka commented Jun 28, 2024

This is the implementation of the "running Terraform locally" part of RFD-173.

Fixes #39744 on local setups.

This PR introduces a new command: tctl terraform env. The design is described in more details in the RFD but basically the UX looks like:

tsh login ...
eval $(tctl terraform env)
# progress + potential MFA challenge

terraform plan
# automatically logged in

User documentation and reference will come in a future PR.

In addition to the few unit tests and the proxy/auth integration tests, this has been tested with a local instance (-c teleport.yaml) and with a Teleport Cloud tenant.

Changelog: Add the tctl terraform env command that makes running the Terraform Provider locally easier.

Changelog: Add a new role preset terraform-provider with all permissions required to use the Teleport Terraform provider. Any existing role with the same name will take precedence.

@hugoShaka hugoShaka force-pushed the hugo/tctl-terraform-env branch from 9cd1c1c to d5fab1e Compare June 28, 2024 19:47
@marcoandredinis marcoandredinis changed the title Introduce the tctl terrafor env command Introduce the tctl terraform env command Jul 1, 2024
Comment thread integrations/terraform/Makefile Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
@hugoShaka hugoShaka force-pushed the hugo/tctl-terraform-env branch from 9b34016 to 82d1cdb Compare July 2, 2024 20:03
@hugoShaka hugoShaka marked this pull request as ready for review July 2, 2024 20:03
@hugoShaka hugoShaka requested a review from marcoandredinis July 2, 2024 20:03
@github-actions github-actions Bot added size/lg tctl tctl - Teleport admin tool labels Jul 2, 2024
@github-actions github-actions Bot requested a review from tigrato July 2, 2024 20:04
@hugoShaka hugoShaka requested a review from r0mant July 2, 2024 20:05
Comment thread api/constants/constants.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment on lines 61 to 63
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think terraform provider needs to connect to these resources. Can we leave remove these wildcards and leave label selectors empty?

Copy link
Copy Markdown
Contributor Author

@hugoShaka hugoShaka Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because of the way resource access control is implemented in teleport. You cannot see something you don't have access to. For the terraform provider or the operator to be able to reconcile those resources, they must see them, so they need to be able to access them, this is why we need the wildcards. This is mitigated by the fact the role does not grant any login.

I will add a comment about this in the code.

Comment thread tool/tctl/common/terraform_command.go Outdated
Comment on lines 67 to 84
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a "master list" of all resource kinds terraform provider supports somewhere so we can just update that list when adding a new resource?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this can become the master list if we move it to presets.

Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
Comment thread tool/tctl/common/terraform_command.go Outdated
@hugoShaka hugoShaka requested a review from r0mant July 3, 2024 16:27
Comment thread tool/tctl/common/terraform_command.go Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would just name this flag --role.

@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from tigrato July 4, 2024 07:47
@hugoShaka hugoShaka enabled auto-merge July 4, 2024 15:17
@hugoShaka hugoShaka added this pull request to the merge queue Jul 4, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 4, 2024
@hugoShaka
Copy link
Copy Markdown
Contributor Author

Blocked by: #43877 (tbot doesn't build on windows)

@hugoShaka hugoShaka enabled auto-merge July 9, 2024 15:47
@hugoShaka hugoShaka force-pushed the hugo/tctl-terraform-env branch from b5e9001 to 05e6380 Compare July 10, 2024 21:35
@hugoShaka hugoShaka added this pull request to the merge queue Jul 10, 2024
Merged via the queue into master with commit 2248a4b Jul 10, 2024
@hugoShaka hugoShaka deleted the hugo/tctl-terraform-env branch July 10, 2024 22:15
@public-teleport-github-review-bot
Copy link
Copy Markdown

@hugoShaka See the table below for backport results.

Branch Result
branch/v16 Failed

hugoShaka added a commit that referenced this pull request Jul 26, 2024
* Introduce the `tctl terrafor env` command

* fix tests

* address marco's feedback + use correct b64 lib

* add license

* add created-by label as specified in the RFD

* Update tool/tctl/common/terraform_command.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Have telpeort create the Terraform default role

* rename use-existing-role -> role, and stop hijacking identity.SSHCACertBytes

* Make the terraform provider role a real preset, rename to 'terraform-provider'

* lint

* Fix tbot's invocation after rebase

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
hugoShaka added a commit that referenced this pull request Aug 1, 2024
* Introduce the `tctl terrafor env` command

* fix tests

* address marco's feedback + use correct b64 lib

* add license

* add created-by label as specified in the RFD

* Update tool/tctl/common/terraform_command.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Have telpeort create the Terraform default role

* rename use-existing-role -> role, and stop hijacking identity.SSHCACertBytes

* Make the terraform provider role a real preset, rename to 'terraform-provider'

* lint

* Fix tbot's invocation after rebase

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
hugoShaka added a commit that referenced this pull request Aug 2, 2024
* Introduce the `tctl terrafor env` command

* fix tests

* address marco's feedback + use correct b64 lib

* add license

* add created-by label as specified in the RFD

* Update tool/tctl/common/terraform_command.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Have telpeort create the Terraform default role

* rename use-existing-role -> role, and stop hijacking identity.SSHCACertBytes

* Make the terraform provider role a real preset, rename to 'terraform-provider'

* lint

* Fix tbot's invocation after rebase

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
hugoShaka added a commit that referenced this pull request Aug 6, 2024
* Introduce the `tctl terrafor env` command

* fix tests

* address marco's feedback + use correct b64 lib

* add license

* add created-by label as specified in the RFD

* Update tool/tctl/common/terraform_command.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Have telpeort create the Terraform default role

* rename use-existing-role -> role, and stop hijacking identity.SSHCACertBytes

* Make the terraform provider role a real preset, rename to 'terraform-provider'

* lint

* Fix tbot's invocation after rebase

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
marcoandredinis pushed a commit that referenced this pull request Aug 26, 2024
* Introduce the `tctl terrafor env` command

* fix tests

* address marco's feedback + use correct b64 lib

* add license

* add created-by label as specified in the RFD

* Update tool/tctl/common/terraform_command.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Have telpeort create the Terraform default role

* rename use-existing-role -> role, and stop hijacking identity.SSHCACertBytes

* Make the terraform provider role a real preset, rename to 'terraform-provider'

* lint

* Fix tbot's invocation after rebase

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
github-merge-queue Bot pushed a commit that referenced this pull request Aug 26, 2024
)

* Introduce the `tctl terraform env` command (#43664)

* Introduce the `tctl terrafor env` command

* fix tests

* address marco's feedback + use correct b64 lib

* add license

* add created-by label as specified in the RFD

* Update tool/tctl/common/terraform_command.go

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Have telpeort create the Terraform default role

* rename use-existing-role -> role, and stop hijacking identity.SSHCACertBytes

* Make the terraform provider role a real preset, rename to 'terraform-provider'

* lint

* Fix tbot's invocation after rebase

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Refactor Terraform credential loading (#44037)

* Refactor Terraform credential loading

* Warn about expiry

* kip expired credentials

* fixup! kip expired credentials

* Use constants everywhere + add godocs

* fixup! Use constants everywhere + add godocs

* Address marco's feedback

* fixup! Address marco's feedback

* tidy go mod

* lint

* re-render TF docs

* Update v16 version in error message

* Add Terraform Provider native MachineID support (#44306)

* Add Terraform Provider native MachineID support

* Reject 'token' join method

* lint: fix imports

* re-render TF docs

* fix tests + add license

* lint

* tidy go mod

* use v16 client.Expiry() function

---------

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/lg tctl tctl - Teleport admin tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UX Bug: Terraform is extremely hard to use when MFA for admin action is enforced

4 participants