140 lines
3.8 KiB
Plaintext
Raw Normal View History

Create rule S6406[terraform]: Excessive Granting Of GCP IAM Permissions Is Security-Sensitive (#724) * Create rule S6406 * first draft * draft part2 * user-friendly draft v3 * light fix * add link * fix snippets columns * final draft * add metadata - 15min time because it's long * Light -> Lightweight * modern->sophisticated * fix punctuation * suggestion for snippets * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: loris-s-sonarsource <loris-s-sonarsource@users.noreply.github.com> Co-authored-by: Loris Sierra <loris.sierra@sonarsource.com> Co-authored-by: Loris S <91723853+loris-s-sonarsource@users.noreply.github.com> Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> Co-authored-by: Nils Werner <64034005+nils-werner-sonarsource@users.noreply.github.com>
2022-02-18 16:26:42 +00:00
Excessive granting of GCP IAM permissions can allow attackers to exploit an
organization's cloud resources with malicious intent.
To prevent improper creation or deletion of resources after an account is
compromised, proactive measures include both following GCP Security Insights
and ensuring custom roles contain as few privileges as possible.
After gaining a foothold in the target infrastructure, sophisticated attacks
typically consist of two major parts. +
First, attackers must deploy new resources to carry out their malicious intent.
To guard against this, operations teams must control what unexpectedly appears
in the infrastructure, such as what is:
* added
* written down
* updated
* started
* appended
* applied
* accessed.
Once the malicious intent is executed, attackers must avoid detection at all
costs. +
To counter attackers' attempts to remove their fingerprints, operations teams
must control what unexpectedly disappears from the infrastructure, such as what
is:
* stopped
* disabled
* canceled
* deleted
* destroyed
* detached
* disconnected
* suspended
* rejected
* removed.
For operations teams to be resilient in this scenario, their organization must
apply both:
* Detection security: log these actions to better detect malicious actions.
* Preventive security: review and limit granted permissions.
This rule raises an issue when a custom role grants a number of sensitive permissions
(read-write or destructive permission) that is greater than a given parameter.
== Ask Yourself Whether
* This custom role will be mostly used for read-only purposes.
* Compliance policies require read-only access.
There is a risk if you answered yes to any of these questions.
== Recommended Secure Coding Practices
To reduce the risks associated with this role after a compromise:
* Reduce the list of permissions to grant only those that are actually needed.
* Favor read-only over read-write.
== Sensitive Code Example
This custom role grants more than 5 sensitive permissions:
[source,terraform]
----
resource "google_project_iam_custom_role" "example" {
permissions = [ # Sensitive
"resourcemanager.projects.create", # Sensitive permission
"resourcemanager.projects.delete", # Sensitive permission
"resourcemanager.projects.get",
"resourcemanager.projects.list",
"run.services.create", # Sensitive permission
"run.services.delete", # Sensitive permission
"run.services.get",
"run.services.getIamPolicy",
"run.services.setIamPolicy", # Sensitive permission
"run.services.list",
"run.services.update", # Sensitive permission
]
}
----
== Compliant Solution
This custom role grants less than 5 sensitive permissions:
[source,terraform]
----
resource "google_project_iam_custom_role" "example" {
permissions = [
"resourcemanager.projects.get",
"resourcemanager.projects.list",
"run.services.create",
"run.services.delete",
"run.services.get",
"run.services.getIamPolicy",
"run.services.list",
"run.services.update",
]
}
----
== See
* https://cloud.google.com/iam/docs/recommender-overview[GCP Docs] - Enforce least privilege with role recommendations
* https://cloud.google.com/iam/docs/manage-policy-insights[GCP Docs] - Security Insights
* CWE - https://cwe.mitre.org/data/definitions/668[CWE-668 - Exposure of Resource to Wrong Sphere]
Create rule S6406[terraform]: Excessive Granting Of GCP IAM Permissions Is Security-Sensitive (#724) * Create rule S6406 * first draft * draft part2 * user-friendly draft v3 * light fix * add link * fix snippets columns * final draft * add metadata - 15min time because it's long * Light -> Lightweight * modern->sophisticated * fix punctuation * suggestion for snippets * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc * Update rules/S6406/terraform/rule.adoc Co-authored-by: loris-s-sonarsource <loris-s-sonarsource@users.noreply.github.com> Co-authored-by: Loris Sierra <loris.sierra@sonarsource.com> Co-authored-by: Loris S <91723853+loris-s-sonarsource@users.noreply.github.com> Co-authored-by: Pierre-Loup <49131563+pierre-loup-tristant-sonarsource@users.noreply.github.com> Co-authored-by: Nils Werner <64034005+nils-werner-sonarsource@users.noreply.github.com>
2022-02-18 16:26:42 +00:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Primary Message: This role grants more than ``max`` sensitive permissions. Make sure they are all required.
* Secondary Message: Sensitive permission: read-write or destructive
=== Parameters
.max
****
----
5
----
Number of sensitive permissions for a custom role.
****
=== Highlighting
Highlight the sensitive list item.
endif::env-github,rspecator-view[]