IAM User Direct Policies
iam-user-direct-policies
What this rule checks
Detects IAM Users with policies attached directly (inline Policies or ManagedPolicyArns). CIS AWS Foundations 1.15 requires users to inherit permissions through groups.
How to fix it
- 1Create an IAM Group with the required policies
- 2Add the user to the group instead of attaching policies directly
- 3Remove Policies and ManagedPolicyArns from AWS::IAM::User resources
import { User, ManagedPolicy } from 'aws-cdk-lib/aws-iam';
new User(this, 'AppUser', {
managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName('AmazonS3ReadOnlyAccess')],
});import { User, Group, ManagedPolicy } from 'aws-cdk-lib/aws-iam';
const group = new Group(this, 'ReadOnlyGroup', {
managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName('AmazonS3ReadOnlyAccess')],
});
new User(this, 'AppUser', { groups: [group] });CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.
Affected resource types
AWS::IAM::UserIntentional? Suppress this finding
Sometimes a flag is deliberate — a genuinely public endpoint, say. You can dismiss iam-user-direct-policies and the reason is kept in the report, not silently hidden.
In .cdk-insights.json:
{
"ignoreRules": [
{ "id": "iam-user-direct-policies", "reason": "Why this is intentional" }
]
}Or inline in your CDK code:
Validations.of(scope).acknowledge({
id: 'cdk-insights::iam-user-direct-policies',
reason: 'Why this is intentional',
});Use the rule ID iam-user-direct-policies shown above — not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs →
Catch this in your stack
$ npx cdk-insights scanCDK Insights runs this and 118+ other rules locally against your synthesised CDK app — free, no account, your code never leaves your machine.