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

feat(terraform): Added new Terraform-AWS python IAMUserNotUsedForAccess(CKV_AWS_273) policy #3574

Merged
merged 6 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions checkov/terraform/checks/resource/aws/IAMUserNotUsedForAccess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

from typing import Any

from checkov.common.models.enums import CheckCategories, CheckResult
from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck


class IAMUserNotUsedForAccess(BaseResourceCheck):
def __init__(self) -> None:
name = "Ensure access is controlled through SSO and not AWS IAM defined users"
id = "CKV_AWS_273"
supported_resources = ('aws_iam_user',)
categories = (CheckCategories.IAM,)
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

def scan_resource_conf(self, conf: dict[str, list[Any]]) -> CheckResult:
return CheckResult.FAILED


check = IAMUserNotUsedForAccess()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# fail
resource "aws_iam_user" "bad" {
name = "example"
path = "/system/"

tags = {
tag-key = "tag-value"
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
from pathlib import Path

from checkov.runner_filter import RunnerFilter
from checkov.terraform.checks.resource.aws.IAMUserNotUsedForAccess import check
from checkov.terraform.runner import Runner


class TestIAMUserNotUsedForAccess(unittest.TestCase):
def test(self):
# given
test_files_dir = Path(__file__).parent / "example_IAMUserNotUsedForAccess"

# when
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id]))

# then
summary = report.get_summary()

passing_resources = set()
failing_resources = {
"aws_iam_user.bad",
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

self.assertEqual(summary["passed"], len(passing_resources))
self.assertEqual(summary["failed"], len(failing_resources))
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

self.assertEqual(passing_resources, passed_check_resources)
self.assertEqual(failing_resources, failed_check_resources)


if __name__ == "__main__":
unittest.main()