Skip to content

Commit

Permalink
added physicalName in key policy
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev committed Dec 24, 2023
1 parent 1d3526b commit cd88c9d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"kms:ReEncrypt*"
],
"Condition": {
"ArnLike": {
"ArnEquals": {
"kms:EncryptionContext:aws:logs:arn": {
"Fn::Join": [
"",
Expand All @@ -54,7 +54,7 @@
{
"Ref": "AWS::AccountId"
},
":*"
":log-group:aws-cdk-log-group-encrypted-integLogGroupDECB5FC9"
]
]
}
Expand Down Expand Up @@ -87,6 +87,7 @@
"LogGroupF5B46931": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "aws-cdk-log-group-encrypted-integLogGroupDECB5FC9",
"KmsKeyId": {
"Fn::GetAtt": [
"Key961B73FD",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"LogGroupLambdaAuditF8F47F46": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "aws-cdk-log-group-integLogGroupLambdaAudit8AB75176",
"RetentionInDays": 731
},
"UpdateReplacePolicy": "Retain",
Expand All @@ -16,6 +17,7 @@
"LogGroupLambdaAC756C5B": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "aws-cdk-log-group-integLogGroupLambda9924FF7D",
"DataProtectionPolicy": {
"name": "policy-name",
"description": "policy description",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions packages/aws-cdk-lib/aws-logs/lib/log-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ILogSubscriptionDestination, SubscriptionFilter } from './subscription-
import * as cloudwatch from '../../aws-cloudwatch';
import * as iam from '../../aws-iam';
import * as kms from '../../aws-kms';
import { Annotations, Arn, ArnFormat, RemovalPolicy, Resource, Stack, Token } from '../../core';
import { Annotations, Arn, ArnFormat, Lazy, Names, RemovalPolicy, Resource, Stack, Token } from '../../core';

export interface ILogGroup extends iam.IResourceWithPolicy {
/**
Expand Down Expand Up @@ -491,7 +491,9 @@ export class LogGroup extends LogGroupBase {

constructor(scope: Construct, id: string, props: LogGroupProps = {}) {
super(scope, id, {
physicalName: props.logGroupName,
physicalName: props.logGroupName ?? Lazy.string({
produce: () => Names.uniqueResourceName(this, { maxLength: 512, allowedSpecialCharacters: '-_' }),
}),
});

let retentionInDays = props.retention;
Expand Down Expand Up @@ -547,8 +549,8 @@ export class LogGroup extends LogGroupBase {
],
resources: ['*'],
conditions: {
ArnLike: {
'kms:EncryptionContext:aws:logs:arn': `arn:${this.stack.partition}:logs:${this.env.region}:${this.env.account}:*`,
ArnEquals: {
'kms:EncryptionContext:aws:logs:arn': `arn:${this.stack.partition}:logs:${this.env.region}:${this.env.account}:log-group:${this.physicalName}`,
},
},
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('log group', () => {
},
},
Condition: {
ArnLike: {
ArnEquals: {
'kms:EncryptionContext:aws:logs:arn': {
'Fn::Join': [
'',
Expand All @@ -88,7 +88,7 @@ describe('log group', () => {
{
Ref: 'AWS::AccountId',
},
':*',
':log-group:LogGroup',
],
],
},
Expand Down

0 comments on commit cd88c9d

Please sign in to comment.