Skip to content

Commit 5bb1a36

Browse files
Feat: encrypt kinesis by default (#888)
* feat: create kms keys for all other regions in log account, provided with new output variable in phase 0 * refactor: reuse create default s3 key, add policy for aws services * chore: fix typo in default kms key output type * feat: retrieve appropriate kms keys for sns in phase 2 based on account and region * fix: change condition checks to be against account ID and not key * fix: create topics with encryption keys for management & logs accounts * feat: add policy for sns to installer cmk and reuse it to encrypt main machine state machine sns topic * fix: add kms abilities to lambda and cloud watch as well to allow topics communication * refactor: retrieve account keys from config object instead of hardcoded * feat: add kms key and encrypt sns topic for main security account region if add sns topic is set * refactor: extra default key creation and output to a function for code clean up * refactor: extract logic of retrieving default key arn to its own function for code clean up * feat: add default kms keys to other regions in security account and reuse account bucket for main region * feat: allow macie to leverage the default keys created in other regions of security account * fix: reference to accountstack region and not global region variable * refactor: remove uneeded region function param for try find default key arn * chore: lint fix * chore: prettier fix * tests: spec entries for new phases introduced for kms keys * feat: leverage bucket kms keys to encrypt kinesis delivery stream & log stream * feat: add encryption configs to extended s3 destination of firehose * fix: remove uneeded configuration from firehose * chore: prettier fix * fixed bracket to dot notation Co-authored-by: hickeydh-aws <hickeydh@amazon.com>
1 parent 127f1ca commit 5bb1a36

File tree

3 files changed

+50
-3
lines changed
  • src
    • deployments/cdk/src/deployments
    • lib/common-outputs/src

3 files changed

+50
-3
lines changed

src/deployments/cdk/src/deployments/central-services/central-logging-s3/step-1.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import * as c from '@aws-accelerator/common-config';
2727
import { StackOutput } from '@aws-accelerator/common-outputs/src/stack-output';
2828
import { IamRoleOutputFinder } from '@aws-accelerator/common-outputs/src/iam-role';
2929
import { CfnLogDestinationOutput } from './outputs';
30+
import * as kms from '@aws-cdk/aws-kms';
31+
import { LogBucketOutputTypeOutputFinder } from '@aws-accelerator/common-outputs/src/buckets';
32+
import { DefaultKmsOutputFinder } from '@aws-accelerator/common-outputs/src/kms';
3033

3134
import path from 'path';
3235

@@ -47,6 +50,7 @@ export async function step1(props: CentralLoggingToS3Step1Props) {
4750
const allAccountIds = accounts.map(account => account.id);
4851
const centralLogServices = config['global-options']['central-log-services'];
4952
const cwlRegionsConfig = config['global-options']['additional-cwl-regions'];
53+
const homeRegion = config['global-options']['central-log-services'].region;
5054
if (!cwlRegionsConfig[centralLogServices.region]) {
5155
cwlRegionsConfig[centralLogServices.region] = {
5256
'kinesis-stream-shard-count': centralLogServices['kinesis-stream-shard-count'],
@@ -80,6 +84,32 @@ export async function step1(props: CentralLoggingToS3Step1Props) {
8084
);
8185
continue;
8286
}
87+
let keyArn: string;
88+
logAccountStack.region === centralLogServices.region
89+
? (keyArn = LogBucketOutputTypeOutputFinder.findOneByName({
90+
outputs,
91+
accountKey: logAccountStack.accountKey,
92+
region: logAccountStack.region,
93+
})?.encryptionKeyArn!)
94+
: (keyArn = DefaultKmsOutputFinder.findOneByName({
95+
outputs,
96+
accountKey: logAccountStack.accountKey,
97+
region: logAccountStack.region,
98+
})?.encryptionKeyArn!);
99+
100+
const homeRegionEncryptionKeyArn = LogBucketOutputTypeOutputFinder.findOneByName({
101+
outputs,
102+
accountKey: logAccountStack.accountKey,
103+
region: homeRegion,
104+
})?.encryptionKeyArn!;
105+
106+
const homeRegionEncryptionKey = kms.Key.fromKeyArn(
107+
logAccountStack,
108+
'Default-Home-Region-Key-Phase-1',
109+
homeRegionEncryptionKeyArn,
110+
);
111+
const encryptionKey = kms.Key.fromKeyArn(logAccountStack, 'Default-Key-Phase-1', keyArn);
112+
83113
await cwlSettingsInLogArchive({
84114
scope: logAccountStack,
85115
accountIds: allAccountIds,
@@ -89,6 +119,8 @@ export async function step1(props: CentralLoggingToS3Step1Props) {
89119
kinesisStreamRoleArn: cwlKinesisStreamRoleOutput.roleArn,
90120
dynamicS3LogPartitioning: centralLogServices['dynamic-s3-log-partitioning'],
91121
region,
122+
encryptionKey,
123+
homeRegionEncryptionKey,
92124
});
93125
}
94126
}
@@ -103,6 +135,8 @@ async function cwlSettingsInLogArchive(props: {
103135
bucketArn: string;
104136
logStreamRoleArn: string;
105137
kinesisStreamRoleArn: string;
138+
encryptionKey: kms.IKey;
139+
homeRegionEncryptionKey: kms.IKey;
106140
shardCount?: number;
107141
dynamicS3LogPartitioning?: c.S3LogPartition[];
108142
region: string;
@@ -116,6 +150,8 @@ async function cwlSettingsInLogArchive(props: {
116150
shardCount,
117151
dynamicS3LogPartitioning,
118152
region,
153+
encryptionKey,
154+
homeRegionEncryptionKey,
119155
} = props;
120156

121157
// Create Kinesis Stream for Logs streaming
@@ -124,7 +160,8 @@ async function cwlSettingsInLogArchive(props: {
124160
name: 'Kinesis-Logs-Stream',
125161
suffixLength: 0,
126162
}),
127-
encryption: kinesis.StreamEncryption.UNENCRYPTED,
163+
encryption: kinesis.StreamEncryption.KMS,
164+
encryptionKey,
128165
shardCount,
129166
});
130167

@@ -186,6 +223,7 @@ async function cwlSettingsInLogArchive(props: {
186223
deliveryStreamName: createName({
187224
name: 'Firehose-Delivery-Stream-Partition',
188225
}),
226+
189227
deliveryStreamType: 'KinesisStreamAsSource',
190228
kinesisStreamSourceConfiguration: {
191229
kinesisStreamArn: logsStream.streamArn,
@@ -203,6 +241,11 @@ async function cwlSettingsInLogArchive(props: {
203241
enabled: true,
204242
},
205243
errorOutputPrefix: `${CLOUD_WATCH_CENTRAL_LOGGING_BUCKET_PREFIX}/processing-failed`,
244+
encryptionConfiguration: {
245+
kmsEncryptionConfig: {
246+
awskmsKeyArn: homeRegionEncryptionKey.keyArn,
247+
},
248+
},
206249
prefix: '!{partitionKeyFromLambda:dynamicPrefix}',
207250
processingConfiguration: {
208251
enabled: true,

src/deployments/cdk/src/deployments/defaults/shared.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@ export function createDefaultS3Key(props: { accountStack: AccountStack; prefix:
4444
);
4545
encryptionKey.addToResourcePolicy(
4646
new iam.PolicyStatement({
47-
sid: 'Allow ASEA Roles to use the encryption key',
47+
sid: 'Allow AWS services to use the encryption key',
4848
actions: ['kms:Encrypt', 'kms:Decrypt', 'kms:ReEncrypt*', 'kms:GenerateDataKey*', 'kms:DescribeKey'],
4949
principals: [
5050
new iam.ServicePrincipal('sns.amazonaws.com'),
5151
new iam.ServicePrincipal('cloudwatch.amazonaws.com'),
5252
new iam.ServicePrincipal('lambda.amazonaws.com'),
5353
// For macie usage in security account
5454
new iam.ServicePrincipal('macie.amazonaws.com'),
55+
// Kinesis for usage in the log account
56+
new iam.ServicePrincipal('kinesis.amazonaws.com'),
5557
],
5658
resources: ['*'],
5759
}),
5860
);
5961
encryptionKey.addToResourcePolicy(
6062
new iam.PolicyStatement({
61-
sid: 'Allow AWS services to use the encryption key',
63+
sid: 'Allow Accelerator Role to use the encryption key',
6264
actions: ['kms:Encrypt', 'kms:Decrypt', 'kms:ReEncrypt*', 'kms:GenerateDataKey*', 'kms:DescribeKey'],
6365
principals: [new iam.AnyPrincipal()],
6466
resources: ['*'],

src/lib/common-outputs/src/kms.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const DefaultKmsOutput = t.interface(
2424
'DefaultKms',
2525
);
2626

27+
export type EbsKmsOutput = t.TypeOf<typeof DefaultKmsOutput>;
28+
2729
export const DefaultKmsOutputFinder = createStructuredOutputFinder(DefaultKmsOutput, finder => ({
2830
findOneByName: (props: { outputs: StackOutput[]; accountKey: string; region?: string }) =>
2931
finder.tryFindOne({

0 commit comments

Comments
 (0)