Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: enable Terraform debug mode via deployment configuration #8260

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
merged 12 commits into from
Jun 29, 2023

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Jun 29, 2023

Related: #8248

This PR mitigates the security concern around the untrusted Terraform plugin:

  • It disables the debug mode by default
  • It restricts access to the debug mode to admins only
  • Debug mode can be enabled using deployment config:
CODER_ENABLE_TERRAFORM_DEBUG_MODE=true
Screenshot 2023-06-29 at 09 47 47

@mtojek mtojek self-assigned this Jun 29, 2023
@mtojek mtojek requested review from johnstcn and mafredri June 29, 2023 08:21
@mtojek mtojek marked this pull request as ready for review June 29, 2023 08:22
@johnstcn
Copy link
Member

Should we:

a) Only allow admins to run builds in debug mode? (That is, hide the "try in debug mode" button unless you're an admin - this would resolve the issue with not being able to get the deployment values.)
b) Invert the debug mode logic - disable by default, and require users to enable? This is a more "secure by default" configuration.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Change looks good to me mechanically, I just wonder if it's better to disable debug mode by default or only allow admins to use debug mode.

@mafredri
Copy link
Member

I think @johnstcn makes some good points. I would take it even further such that enable debug mode is per-provisioner (disabled by default).

Another thought that comes to mind.. should the user even be allowed to see the build log from a debug-enabled build? I can foresee there being multiple knobs for this behavior. Like allow debug: never|admin|user. If set to admin, users shouldn't see the build log, etc.

@mtojek
Copy link
Member Author

mtojek commented Jun 29, 2023

I think @johnstcn makes some good points.

I'm working on this 👍

Another thought that comes to mind.. should the user even be allowed to see the build log from a debug-enabled build? I can foresee there being multiple knobs for this behavior. Like allow debug: never|admin|user. If set to admin, users shouldn't see the build log, etc.

I would not like to increase the complexity of this PR as we have an issue to mitigate (disable unsafe logs). We can chat later about gaps we should address in the future. Here I would focus on enabling a global switch.

@mafredri
Copy link
Member

I would not like to increase the complexity of this PR as we have an issue to mitigate (disable unsafe logs). We can chat later about gaps we should address in the future. Here I would focus on enabling a global switch.

Agreed, that's fair. 👍🏻

@mtojek mtojek marked this pull request as draft June 29, 2023 10:17
@mtojek mtojek changed the title feat: disable Terraform debug mode via deployment configuration feat: enable Terraform debug mode via deployment configuration Jun 29, 2023
@mtojek
Copy link
Member Author

mtojek commented Jun 29, 2023

I refactored the PR considering the following statements:

  • It disables the debug mode by default.
  • It restricts access to the debug mode to admins only.
  • Debug mode can be enabled using deployment config.

@mtojek mtojek requested a review from johnstcn June 29, 2023 12:03
@mtojek mtojek marked this pull request as ready for review June 29, 2023 12:03
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Looks good!

@@ -638,11 +646,19 @@ func (b *Builder) authorize(authFunc func(action rbac.Action, object rbac.Object
}
}

if b.logLevel != "" && !authFunc(rbac.ActionUpdate, template) {
if b.logLevel != "" && !authFunc(rbac.ActionRead, rbac.ResourceDeploymentValues) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this the de-facto way to check for admin? It feels like it'd be one of those things that might change in the future (esp. a read permission). Probably fine for now though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's why I covered it on the workspace build level with tests for all crucial roles.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

👍

@mtojek mtojek merged commit 83fee4b into main Jun 29, 2023
@mtojek mtojek deleted the 8248-debug-log-config branch June 29, 2023 13:22
@github-actions github-actions bot locked and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants