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

Secrets manager policy validation fails for principals that are just created #14449

Closed
sandrogattuso opened this issue Aug 3, 2020 · 4 comments · Fixed by #14459
Closed

Secrets manager policy validation fails for principals that are just created #14449

sandrogattuso opened this issue Aug 3, 2020 · 4 comments · Fixed by #14459
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service. service/secretsmanager Issues and PRs that pertain to the secretsmanager service.
Milestone

Comments

@sandrogattuso
Copy link

sandrogattuso commented Aug 3, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue 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 issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.16

  • provider.archive v1.3.0
  • provider.aws v3.0.0
  • provider.null v2.1.2

Affected Resource(s)

  • aws_iam_role
  • aws_secretsmanager_secret

Terraform Configuration Files

resource "aws_iam_role" "this" {
  name                 = join("-", ["instance-profile", "test"])
  assume_role_policy   = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF
}

data "aws_iam_policy_document" "this" {
  statement { 
    effect    = "Allow"
    resources = ["*"]
    actions   = ["secretsmanager:Get*"]
    principals {
      type        = "AWS"
      identifiers = [aws_iam_role.this.arn]
    }
  }
}
resource "aws_secretsmanager_secret" "this" {
  name                    = "test"
  description             = "Created by test"
  recovery_window_in_days = 0
  policy                  = data.aws_iam_policy_document.this.json
}

Debug Output

Panic Output

Expected Behavior

Secret is generated with the appropriate permission at the first apply

Actual Behavior

The validation for the policy fails with the following output
data.aws_caller_identity.current: Refreshing state...
aws_iam_role.this: Creating...
aws_iam_role.this: Creation complete after 2s [id=instance-profile-test]
data.aws_iam_policy_document.this: Refreshing state...
aws_secretsmanager_secret.this: Creating...
Error: error setting Secrets Manager Secret "arn:aws:secretsmanager:ap-southeast-2:XXXXXXX: secret:test-e5XYyU" policy: MalformedPolicyDocumentException: This resource policy contains an unsupported principal.
on main.tf line 6, in resource "aws_secretsmanager_secret" "this":
6: resource "aws_secretsmanager_secret" "this" {

NOTE: a subsequent apply works as expected. I suspect the validation of the policy happens before the IAM role arn is actually available for querying due to IAM eventual consistency

Steps to Reproduce

  1. Ensure is the first execution or run terraform destroy
  2. terraform apply --> Generate an error
  3. terraform apply --> Successful execution
@ghost ghost added service/iam Issues and PRs that pertain to the iam service. service/secretsmanager Issues and PRs that pertain to the secretsmanager service. labels Aug 3, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Aug 3, 2020
@DrFaust92 DrFaust92 added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Aug 4, 2020
@bflad bflad added this to the v3.1.0 milestone Aug 6, 2020
@bflad
Copy link
Contributor

bflad commented Aug 6, 2020

The fix for this has been merged and will release with version 3.1.0 of the Terraform AWS Provider, likely later today. Thanks to @DrFaust92 for the implementation. 👍

@sandrogattuso
Copy link
Author

@DrFaust92 thanks for the prompt implementation :)

@ghost
Copy link

ghost commented Aug 7, 2020

This has been released in version 3.1.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 Sep 6, 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 Sep 6, 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/iam Issues and PRs that pertain to the iam service. service/secretsmanager Issues and PRs that pertain to the secretsmanager service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants