Skip to content

Commit 51f21de

Browse files
authored
Chore: [AEA-0000] - fix sync role permissions so it does not clash with other pull requests (#448)
## Summary - Routine Change ### Details - give sync role permissions directly on bucket and kms key - stagger dependabot updates
1 parent 8456b99 commit 51f21de

5 files changed

Lines changed: 38 additions & 16 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "Ubuntu",
2+
"name": "eps-assist-me",
33
"build": {
44
"dockerfile": "Dockerfile",
55
"context": "..",

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ updates:
2525
schedule:
2626
interval: "weekly"
2727
day: "friday"
28-
time: "18:00"
28+
time: "20:00"
2929
open-pull-requests-limit: 20
3030
versioning-strategy: increase
3131
commit-message:
@@ -39,7 +39,7 @@ updates:
3939
schedule:
4040
interval: "weekly"
4141
day: "friday"
42-
time: "18:00"
42+
time: "22:00"
4343
open-pull-requests-limit: 20
4444
versioning-strategy: increase
4545
commit-message:

packages/cdk/constructs/S3Bucket.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
AccountRootPrincipal,
1515
Effect,
1616
IPrincipal,
17+
IRole,
1718
PolicyDocument,
1819
PolicyStatement
1920
} from "aws-cdk-lib/aws-iam"
@@ -23,6 +24,7 @@ export interface S3BucketProps {
2324
readonly versioned: boolean
2425
readonly deploymentRole: IPrincipal
2526
readonly auditLoggingBucket: IBucket
27+
readonly documentSyncRole: IRole
2628
}
2729

2830
export class S3Bucket extends Construct {
@@ -76,6 +78,19 @@ export class S3Bucket extends Construct {
7678
]
7779
})
7880

81+
const syncPolicy = new PolicyStatement({
82+
effect: Effect.ALLOW,
83+
principals: [props.documentSyncRole!],
84+
actions: [
85+
"s3:GetBucket*",
86+
"s3:GetObject*",
87+
"s3:List*"
88+
],
89+
resources: [
90+
bucket.bucketArn,
91+
bucket.arnForObjects("*")
92+
]
93+
})
7994
const accountRootPrincipal = new AccountRootPrincipal()
8095
const kmsPolicy = new PolicyDocument({
8196
statements: [
@@ -93,11 +108,20 @@ export class S3Bucket extends Construct {
93108
"kms:GenerateDataKey"
94109
],
95110
resources:["*"]
111+
}),
112+
new PolicyStatement({
113+
effect: Effect.ALLOW,
114+
principals: [props.documentSyncRole!],
115+
actions: [
116+
"kms:Decrypt"
117+
],
118+
resources:["*"]
96119
})
97120
]
98121
})
99122

100123
bucket.addToResourcePolicy(deploymentPolicy)
124+
bucket.addToResourcePolicy(syncPolicy)
101125

102126
const contentBucketKmsKey = (kmsKey.node.defaultChild as CfnKey)
103127
contentBucketKmsKey.keyPolicy = kmsPolicy.toJSON()

packages/cdk/resources/Storage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {Construct} from "constructs"
22
import {S3Bucket} from "../constructs/S3Bucket"
3-
import {IPrincipal} from "aws-cdk-lib/aws-iam"
3+
import {IPrincipal, IRole} from "aws-cdk-lib/aws-iam"
44
import {Key} from "aws-cdk-lib/aws-kms"
55
import {Bucket, IBucket} from "aws-cdk-lib/aws-s3"
66

77
export interface StorageProps {
88
readonly stackName: string,
99
readonly deploymentRole: IPrincipal
1010
readonly auditLoggingBucket: IBucket
11+
readonly assistMeDocumentSyncRole: IRole
1112
}
1213

1314
export class Storage extends Construct {
@@ -22,7 +23,8 @@ export class Storage extends Construct {
2223
bucketName: `${props.stackName}-Docs`,
2324
versioned: true,
2425
deploymentRole: props.deploymentRole,
25-
auditLoggingBucket: props.auditLoggingBucket
26+
auditLoggingBucket: props.auditLoggingBucket,
27+
documentSyncRole: props.assistMeDocumentSyncRole
2628
})
2729
this.kbDocsBucket = kbDocsBucket.bucket
2830
this.kbDocsKmsKey = kbDocsBucket.kmsKey

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export class EpsAssistMeStack extends Stack {
6565
const deploymentRole = Role.fromRoleArn(this, "deploymentRole", deploymentRoleImport)
6666
const auditLoggingBucket = Bucket.fromBucketArn(
6767
this, "AuditLoggingBucket", auditLoggingBucketImport)
68+
const assistMeDocumentSyncRole = Role.fromRoleArn(
69+
this,
70+
"AssistMeDocumentSyncRole",
71+
assistMeDocumentSyncRoleArn
72+
)
6873

6974
if (!slackBotToken || !slackSigningSecret) {
7075
throw new Error("Missing required context variables. Please provide slackBotToken and slackSigningSecret")
@@ -95,7 +100,8 @@ export class EpsAssistMeStack extends Stack {
95100
const storage = new Storage(this, "Storage", {
96101
stackName: props.stackName,
97102
deploymentRole: deploymentRole,
98-
auditLoggingBucket: auditLoggingBucket
103+
auditLoggingBucket: auditLoggingBucket,
104+
assistMeDocumentSyncRole: assistMeDocumentSyncRole
99105
})
100106

101107
// initialize s3 folders for raw and processed documents
@@ -257,16 +263,6 @@ export class EpsAssistMeStack extends Stack {
257263
regressionTestRole.addManagedPolicy(regressionTestPolicy)
258264
}
259265

260-
// Grant Access to Document Sync Role
261-
const assistMeDocumentSyncRole = Role.fromRoleArn(
262-
this,
263-
"AssistMeDocumentSyncRole",
264-
assistMeDocumentSyncRoleArn
265-
)
266-
267-
storage.kbDocsBucket.grantRead(assistMeDocumentSyncRole)
268-
storage.kbDocsKmsKey.grantDecrypt(assistMeDocumentSyncRole)
269-
270266
// Output: SlackBot Endpoint
271267
new CfnOutput(this, "SlackBotEventsEndpoint", {
272268
value: `https://${apis.apis["api"].api.domainName?.domainName}/slack/events`,

0 commit comments

Comments
 (0)