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

Add Sensitive flag to private ssh_key properties #11984

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

xsalazar
Copy link
Contributor

Description

When generating Terraform plan outputs for OpsWorks resources that use custom_cookbooks, the private ssh_key is output directly to the console. You can see below the password is already obfuscated; however, the ssh_key will be printed and potentially stored in any CI/CD output or other Terraform pipelines. This property is already ignored from drift-detection because the AWS API does not return this value, given its sensitive nature.

This PR affects aws_opsworks_instance and aws_opsworks_application resources.

Terraform will perform the following actions:

  # aws_opsworks_stack.main will be created
  + resource "aws_opsworks_stack" "main" {
      + agent_version                 = (known after apply)
      + arn                           = (known after apply)
      + berkshelf_version             = "3.2.0"
      + configuration_manager_name    = "Chef"
      + configuration_manager_version = "12"
      + default_availability_zone     = "us-west-2b"
      + default_instance_profile_arn  = "arn:aws:iam::368081326042:instance-profile/aws-opsworks-ec2-role"
      + default_os                    = "Ubuntu 12.04 LTS"
      + default_root_device_type      = "instance-store"
      + default_subnet_id             = (known after apply)
      + hostname_theme                = "Layer_Dependent"
      + id                            = (known after apply)
      + manage_berkshelf              = false
      + name                          = "tf-stack"
      + region                        = "us-west-2"
      + service_role_arn              = "arn:aws:iam::368081326042:role/aws-opsworks-service-role"
      + stack_endpoint                = (known after apply)
      + use_custom_cookbooks          = false
      + use_opsworks_security_groups  = true
      + vpc_id                        = (known after apply)

      + custom_cookbooks_source {
          + password = (sensitive value)
          + revision = "master"
          + ssh_key  = "-----BEGIN RSA PRIVATE KEY-----MIIEpAIBAAKCAQEAv/1hnOZadSDMbJUVJsqweDwc/4TvhTGf0vl9vtNyjzqUUxgURrSvYrgkvWgAFtQ9J5QDNOPSRvS8F1cu7tR036cecdHPmA+Cxto1qENy8UeYrKzVI55i+vJiSn3i22HW+SbW1raBM+PL3sp9i0BQmCr8eh3i/V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1hVOYkglXPcV5OqRDn1sCo5gEsLZoXL1cZKEhIuhLawixPQl8yKMxSDEGjGQ2Acf4axANuRAt5qwskWOBjjdtx66MNohyznTgVrdk4cakMBWOMKVJplhx6XDj+gbct3NjB2A775oGRmg+Esnsp6siYzcpq0GqANFWQKBgQCyv8KoQXsD8f8XMvicRC42uZXfhlDjOUzpo1O7WQKWBYqPBqz4AHzECdy6djI120bqDOifre1qnBjoHezrG+ejaQOTpocOVwT5Zl7BhjoXQZRGiQXj+2aDtmm0+hpmkjX7jiPcljjs8S8gh+uCWieJoO4JNPk2SXRiePpYgKzdlg==-----END RSA PRIVATE KEY-----"
          + type     = "git"
          + url      = "https://github.com/aws/opsworks-example-cookbooks.git"
          + username = "username"
        }
    }

. . .
Plan: 2 to add, 0 to change, 0 to destroy.

With this PR, Terraform plans will now look like the following, with the private ssh_key properly hidden:

Terraform will perform the following actions:

  # aws_opsworks_stack.main will be created
  + resource "aws_opsworks_stack" "main" {
      + agent_version                 = (known after apply)
      + arn                           = (known after apply)
      + berkshelf_version             = "3.2.0"
      + configuration_manager_name    = "Chef"
      + configuration_manager_version = "12"
      + default_availability_zone     = "us-west-2b"
      + default_instance_profile_arn  = "arn:aws:iam::368081326042:instance-profile/aws-opsworks-ec2-role"
      + default_os                    = "Ubuntu 12.04 LTS"
      + default_root_device_type      = "instance-store"
      + default_subnet_id             = (known after apply)
      + hostname_theme                = "Layer_Dependent"
      + id                            = (known after apply)
      + manage_berkshelf              = false
      + name                          = "tf-stack"
      + region                        = "us-west-2"
      + service_role_arn              = "arn:aws:iam::368081326042:role/aws-opsworks-service-role"
      + stack_endpoint                = (known after apply)
      + use_custom_cookbooks          = false
      + use_opsworks_security_groups  = true
      + vpc_id                        = (known after apply)

      + custom_cookbooks_source {
          + password = (sensitive value)
          + revision = "master"
          + ssh_key  = (sensitive value)
          + type     = "git"
          + url      = "https://github.com/aws/opsworks-example-cookbooks.git"
          + username = "username"
        }
    }

. . .
Plan: 2 to add, 0 to change, 0 to destroy.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Release Note

Release note for CHANGELOG:

Add `Sensitive` flag for private `ssh_key` properties, so they are hidden from plan outputs

Acceptance Test

Output from acceptance testing:

make testacc TESTARGS='-run=TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties' TEST=./aws
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties -timeout 120m
=== RUN   TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties
=== PAUSE TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties
=== CONT  TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties
--- PASS: TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties (37.11s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	37.176s

@xsalazar xsalazar requested a review from a team February 10, 2020 19:05
@ghost ghost added size/XS Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. service/opsworks Issues and PRs that pertain to the opsworks service. labels Feb 10, 2020
@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 17, 2020
@bflad bflad self-assigned this Mar 17, 2020
@bflad bflad added this to the v2.54.0 milestone Mar 17, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this, @xsalazar 🚀

Output from acceptance testing:

--- PASS: TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties (24.65s)
--- PASS: TestAccAWSOpsworksStack_noVpcBasic (30.24s)
--- PASS: TestAccAWSOpsworksStack_noVpcCreateTags (34.00s)
--- PASS: TestAccAWSOpsworksApplication (37.73s)
--- PASS: TestAccAWSOpsworksStack_vpc (39.08s)
--- PASS: TestAccAWSOpsWorksStack_classicEndpoints (42.13s)
--- PASS: TestAccAWSOpsworksStack_noVpcChangeServiceRoleForceNew (53.81s)

@bflad bflad merged commit 2c54e04 into hashicorp:master Mar 17, 2020
bflad added a commit that referenced this pull request Mar 17, 2020
@xsalazar xsalazar deleted the resource/aws_opsworks/ssh_key branch March 17, 2020 16:04
@ghost
Copy link

ghost commented Mar 19, 2020

This has been released in version 2.54.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Apr 16, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/opsworks Issues and PRs that pertain to the opsworks service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants