"""Ensure IAM User has proper tagging.""" from checkov.common.models.enums import CheckCategories, CheckResult from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck import json import logging import re import tools class UserTagging(BaseResourceCheck): def __init__(self): name = 'Ensure IAM User has proper tagging' id = 'ORCD_AWS_12' categories = [CheckCategories.IAM] supported_resources = ['aws_iam_user'] guideline = 'https://www.notion.so/Checkov-guide-e5c30d67d35248ebbb0806df59775e0e#6203b6e0751f40b1935db0c21d193273' super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources, guideline=guideline) def scan_resource_conf(self, conf): tags_attribute = tools.flatten(conf.get('tags')) if not tags_attribute or not isinstance(tags_attribute, dict): return CheckResult.FAILED return self._analyze_user_tags(tags_attribute) def _analyze_user_tags(self, tags): if 'role' not in tags: return CheckResult.FAILED role_tag = tags['role'] if role_tag == 'service-user': return CheckResult.PASSED if role_tag not in ['tech', 'infosec', 'business']: return CheckResult.FAILED if ('name' not in tags or 'email' not in tags or 'company' not in tags or 'manager' not in tags): return CheckResult.FAILED return CheckResult.PASSED check = UserTagging()