hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Enhancement]: Surface necessary AWS permissions #36677

Open corkupine opened 5 months ago

corkupine commented 5 months ago

Description

In the course of implementing IaC, organizations move toward automating the execution of Terraform using CI/CD pipelines, workflows, and other agents. One issue for us (and others I presume) is that it can be difficult to enforce least privilege AWS permissions.

Current approaches:

There is also the issue of maintaining the appropriate permissions as resources are added and removed.

Possible new approach:

For each resource, have an internal property with a list of AWS permissions that are required to manage it. During plan and apply, generate an output that has the sum of AWS permissions required to manage all resources.

Affected Resource(s) and/or Data Source(s)

All

Potential Terraform Configuration

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 5 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 5 months ago

Hey @corkupine 👋 Thank you for taking the time to raise this! I'm not sure this is something that could be easily achieved with the way Terraform operates at the Core level, however, there are third party tools that do a similar thing (iamlive is one I see recommended occasionally).

That said, given that I don't have a solid answer at the moment for whether or not this is attainable, I'm going to leave this open for additional input from others.

corkupine commented 5 months ago

Thank you, @justinretzolk ! I just found this, which seems like it could help as well, though coverage of resources is at about 50%. Having providers use some type of convention/reserved name for an output seems like it would be fairly simple, and putting the onus on the provider author would mean that everything would (eventually) be kept in sync without having to map it afterward in a separate project.

dgholz commented 5 months ago

Another recommendation: I use https://github.com/salesforce/policy_sentry to generate the statements. It has a Terraform module to automatically create the policies, but requires its Python script to be locally installed and executable.