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

MalformedPolicyDocument: Invalid principal in policy: "AWS" [Only when Principal is a ROLE.] #1388

Closed
hashibot opened this issue Aug 10, 2017 · 6 comments
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.

Comments

@hashibot
Copy link

hashibot commented Aug 10, 2017

This issue was originally opened by @etsangsplk as hashicorp/terraform#15771. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

https://gist.github.com/p0bailey/3bb66f4cc628bb9fedc5d03d37b7e1c8

Expected Behavior

Want to create a IAM role that allows another IAM role to assume. So there are 2 roles involved.

  1. First role that is the assumer
  2. Second role is the target role to be assumed
    First Role is created as in gist.
    But Second Role is error out only if it is granting permission to another IAM ROLE to assume
    If the target entity is a Service, all is fine.
    We should be able to process as long as the target enitity is a valid IAM principal.
    If I just copy and paste the target role ARN that is created via console, then it is fine.

Actual Behavior

First Role is created as in gist.
But Second Role is errorred out only if it is granting permission to another IAM ROLE to assume
If the target entity is a Service, all is fine.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

See gist

@bflad
Copy link
Contributor

bflad commented Nov 14, 2017

@etsangsplk is this still an issue for you? I would try running this against a recent version of the AWS provider as there have been fixes made in this area. Here's a snippet of aws_iam_role resource code, which handles this error (same eventual consistency applies for IAM roles):

		// IAM users (referenced in Principal field of assume policy)
		// can take ~30 seconds to propagate in AWS
		if isAWSErr(err, "MalformedPolicyDocument", "Invalid principal in policy") {
			return resource.RetryableError(err)
		}

For additional reference, we have plenty of IAM roles with sts:AssumeRole permissions given to other IAM roles in our environment.

@bflad bflad added the service/iam Issues and PRs that pertain to the iam service. label Jan 18, 2018
@bflad
Copy link
Contributor

bflad commented Jan 18, 2018

I'm going to close this given the lack of response and the eventual consistency fixes that have already landed in the provider. Please don't hesitate to reply back if this is still an issue with a recent version of the AWS provider.

@bflad bflad closed this as completed Jan 18, 2018
@fr34k8
Copy link

fr34k8 commented Aug 13, 2018

i'love to see this would be fixed.. #worksnotforme

@alertedsnake
Copy link

This is also still an issue for me with the current provider - it is impossible to use Terraform for this.

It's an especially hilarious bug given the documentation specifically says this is allowed:
https://www.terraform.io/docs/providers/aws/d/iam_policy_document.html#example-with-multiple-principals

Maybe we can get this re-opened, @bflad ?

@alertedsnake
Copy link

Ah, it's definitely a timing thing - if I comment out the 'AWS' principal and run everything, then uncomment and re-run, it does work. Frustrating!

@bflad
Copy link
Contributor

bflad commented Oct 31, 2018

@alertedsnake if you create a new issue we can take a look. IAM is notoriously troublesome with eventual consistency.

I'm going to lock this issue to encourage fresh bug reports with full details.

@hashicorp hashicorp locked and limited conversation to collaborators Oct 31, 2018
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.
Projects
None yet
Development

No branches or pull requests

5 participants