Skip to content

Commit

Permalink
Updates to new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
biffgaut committed Aug 25, 2023
1 parent 03f9791 commit 76b1a28
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .viperlightrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"failOn": "medium",
"failOn": "high",
"all": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,25 @@
},
"DependsOn": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
],
"Metadata": {
"cfn_nag": {
"rules_to_suppress": [
{
"id": "W58",
"reason": "CDK generated custom resource"
},
{
"id": "W89",
"reason": "CDK generated custom resource"
},
{
"id": "W92",
"reason": "CDK generated custom resource"
}
]
}
}
},
"minimalargumentsLambdaFunctionServiceRole73B77FF7": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -395,11 +413,29 @@
{
"Action": "logs:DescribeLogGroups",
"Effect": "Allow",
"Resource": "*"
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":logs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":log-group:/aws/kendra/*"
]
]
}
},
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,25 @@
},
"DependsOn": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
],
"Metadata": {
"cfn_nag": {
"rules_to_suppress": [
{
"id": "W58",
"reason": "CDK generated custom resource"
},
{
"id": "W89",
"reason": "CDK generated custom resource"
},
{
"id": "W92",
"reason": "CDK generated custom resource"
}
]
}
}
},
"existingRole3E995BBA": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -412,11 +430,29 @@
{
"Action": "logs:DescribeLogGroups",
"Effect": "Allow",
"Resource": "*"
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":logs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":log-group:/aws/kendra/*"
]
]
}
},
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,25 @@
},
"DependsOn": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
],
"Metadata": {
"cfn_nag": {
"rules_to_suppress": [
{
"id": "W58",
"reason": "CDK generated custom resource"
},
{
"id": "W89",
"reason": "CDK generated custom resource"
},
{
"id": "W92",
"reason": "CDK generated custom resource"
}
]
}
}
},
"minimalargumentsLambdaFunctionServiceRole73B77FF7": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -460,11 +478,29 @@
{
"Action": "logs:DescribeLogGroups",
"Effect": "Allow",
"Resource": "*"
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":logs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":log-group:/aws/kendra/*"
]
]
}
},
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as cdk from "aws-cdk-lib";
import { Template } from 'aws-cdk-lib/assertions';
import * as defaults from '@aws-solutions-constructs/core';

test('Launch with minimal code and check structure', () => {
test.only('Launch with minimal code and check structure', () => {
const stack = new cdk.Stack();
const testFunctionName = 'test-function-name24334';
const testBucketName = 'test-bucket-name12344';
Expand Down Expand Up @@ -115,11 +115,29 @@ test('Launch with minimal code and check structure', () => {
{
Action: "logs:DescribeLogGroups",
Effect: "Allow",
Resource: "*"
Resource: {
"Fn::Join": [
"",
[
"arn:",
{
Ref: "AWS::Partition"
},
":logs:",
{
Ref: "AWS::Region"
},
":",
{
Ref: "AWS::AccountId"
},
":log-group:/aws/kendra/*"
]
]
}
},
{
Action: [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function CreateS3DataSource(scope: Construct,

}

// TODO: test this in core, only checked in construct right now
function CreateKendraIndexLoggingRole(scope: Construct, id: string): string {
const allowKendraToLogPolicy = new iam.PolicyDocument({
statements: [
Expand All @@ -201,7 +202,7 @@ function CreateKendraIndexLoggingRole(scope: Construct, id: string): string {
effect: iam.Effect.ALLOW,
}),
new iam.PolicyStatement({
resources: ['*'],
resources: [`arn:${Aws.PARTITION}:logs:${Aws.REGION}:${Aws.ACCOUNT_ID}:log-group:/aws/kendra/*`],
actions: [
"logs:DescribeLogGroups"
],
Expand All @@ -210,7 +211,6 @@ function CreateKendraIndexLoggingRole(scope: Construct, id: string): string {
new iam.PolicyStatement({
resources: [`arn:${Aws.PARTITION}:logs:${Aws.REGION}:${Aws.ACCOUNT_ID}:log-group:/aws/kendra/*:log-stream:*`],
actions: [
'logs:CreateLogGroup',
'logs:CreateLogStream',
'logs:PutLogEvents',
'logs:DescribeLogStream',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,109 @@ test('Launch Kendra index with defaults', () => {
template.resourceCountIs("AWS::IAM::Role", 1);
});

test('Confirm kendra has log wrting privileges', () => {
const stack = new Stack(undefined, undefined);

buildKendraIndex(stack, 'test', {});

const template = Template.fromStack(stack);
template.hasResourceProperties("AWS::IAM::Role", {
Description: "Allow Kendra index to write CloudWatch Logs",
Policies: [
{
PolicyDocument: {
Statement: [
{
Action: "cloudwatch:PutMetricData",
Condition: {
StringEquals: {
"cloudwatch:namespace": "AWS/Kendra"
}
},
Effect: "Allow",
Resource: "*"
},
{
Action: "logs:CreateLogGroup",
Effect: "Allow",
Resource: {
"Fn::Join": [
"",
[
"arn:aws:logs:",
{
Ref: "AWS::Region"
},
":",
{
Ref: "AWS::AccountId"
},
":log-group:/aws/kendra/*"
]
]
}
},
{
Action: "logs:DescribeLogGroups",
Effect: "Allow",
Resource: {
"Fn::Join": [
"",
[
"arn:",
{
Ref: "AWS::Partition"
},
":logs:",
{
Ref: "AWS::Region"
},
":",
{
Ref: "AWS::AccountId"
},
":log-group:/aws/kendra/*"
]
]
}
},
{
Action: [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStream"
],
Effect: "Allow",
Resource: {
"Fn::Join": [
"",
[
"arn:",
{
Ref: "AWS::Partition"
},
":logs:",
{
Ref: "AWS::Region"
},
":",
{
Ref: "AWS::AccountId"
},
":log-group:/aws/kendra/*:log-stream:*"
]
]
}
}
],
Version: "2012-10-17"
},
PolicyName: "AllowLogging"
}
],
});
});

test('Launch Kendra index with custom properties', () => {
const testName = 'test-index-name';
const stack = new Stack(undefined, undefined);
Expand Down Expand Up @@ -432,7 +535,7 @@ test('Launch Kendra index with multiple data sources', () => {
});

test('Confirm Errof for bad kendra Permission in normalizeKendraPermissions()', () => {
const inputs = [ "read", "submitfeedback", "write"];
const inputs = ["read", "submitfeedback", "write"];

const outputs = normalizeKendraPermissions(inputs);

Expand All @@ -442,7 +545,7 @@ test('Confirm Errof for bad kendra Permission in normalizeKendraPermissions()',
});

test('Confirm successful operation of normalizeKendraPermissions()', () => {
const inputs = [ "badvalue", "write"];
const inputs = ["badvalue", "write"];

const app = () => {
normalizeKendraPermissions(inputs);
Expand Down

0 comments on commit 76b1a28

Please sign in to comment.