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

fix: Remove unnecessary IAM role for AWS Config #746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
60 changes: 6 additions & 54 deletions security/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
Conditions:
HasPermissionsBoundary: !Not [!Equals [!Ref PermissionsBoundary, '']]
InternalBucket: !Equals [!Ref ExternalConfigBucket, '']
ExternalBucket: !Not [!Equals [!Ref ExternalConfigBucket, '']]
Resources:
ConfigBucket:
Condition: InternalBucket
Expand Down Expand Up @@ -103,64 +102,17 @@
DeliveryFrequency: !Ref DeliveryFrequency
S3BucketName: !If [InternalBucket, !Ref ConfigBucket, !Ref ExternalConfigBucket]
SnsTopicARN: !Ref ConfigTopic
ConfigurationRecorderRole:
Condition: InternalBucket
Type: 'AWS::IAM::Role'
Properties:
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWS_ConfigRole'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AssumeRole1
Effect: Allow
Principal:
Service: 'config.amazonaws.com'
Action: 'sts:AssumeRole'
PermissionsBoundary: !If [HasPermissionsBoundary, !Ref PermissionsBoundary, !Ref 'AWS::NoValue']
Policies:
- PolicyName: 's3-policy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 's3:PutObject'
Resource: !Sub 'arn:aws:s3:::${ConfigBucket}/*'
Condition:
StringLike:
's3:x-amz-acl': 'bucket-owner-full-control'
- Effect: Allow
Action: 's3:GetBucketAcl'
Resource: !Sub 'arn:aws:s3:::${ConfigBucket}'
- PolicyName: 'sns-policy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 'sns:Publish'
Resource: !Ref ConfigTopic
ExternalConfigurationRecorderRole:
Condition: ExternalBucket
Type: 'AWS::IAM::Role'
ConfigServiceRole:
Type: 'AWS::IAM::ServiceLinkedRole'
Properties:
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWS_ConfigRole'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AssumeRole1
Effect: Allow
Principal:
Service: 'config.amazonaws.com'
Action: 'sts:AssumeRole'
PermissionsBoundary: !If [HasPermissionsBoundary, !Ref PermissionsBoundary, !Ref 'AWS::NoValue']
AWSServiceName: 'config.amazonaws.com'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a CustomSuffix property to avoid issues when the role already exists?

ConfigurationRecorder:
Type: 'AWS::Config::ConfigurationRecorder'
Properties:
RecordingGroup:
AllSupported: true
IncludeGlobalResourceTypes: true
RoleARN: !If [InternalBucket, !GetAtt 'ConfigurationRecorderRole.Arn', !GetAtt 'ExternalConfigurationRecorderRole.Arn']
RoleARN: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWSServiceRoleForConfig => ${ConfigServiceRole}

LambdaRole:
Type: 'AWS::IAM::Role'
Properties:
Expand Down Expand Up @@ -227,7 +179,7 @@
Handler: 'index.handler'
MemorySize: 128
Role: !GetAtt 'LambdaRole.Arn'
Runtime: 'nodejs20.x'
Runtime: 'nodejs22.x'
Timeout: 60
LambdaLogGroup:
Type: 'AWS::Logs::LogGroup'
Expand All @@ -252,4 +204,4 @@
Value: '__VERSION__'
StackName:
Description: 'Stack name.'
Value: !Sub '${AWS::StackName}'
Value: !Sub '${AWS::StackName}'

Check failure on line 207 in security/config.yaml

View workflow job for this annotation

GitHub Actions / lint

207:36 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 207 in security/config.yaml

View workflow job for this annotation

GitHub Actions / lint

207:36 [new-line-at-end-of-file] no new line character at the end of file
Loading