Skip to content

Commit

Permalink
Add to existing policy instead of creating new one (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#402)

Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Mar 20, 2024
1 parent 1d84f53 commit 766302e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/network/ci-external-load-balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ApplicationListener, ApplicationLoadBalancer, ApplicationProtocol, ApplicationTargetGroup, ListenerCertificate, Protocol, SslPolicy,
} from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { PolicyStatement, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { Bucket, BucketPolicy } from 'aws-cdk-lib/aws-s3';
import { Bucket } from 'aws-cdk-lib/aws-s3';

export interface JenkinsExternalLoadBalancerProps {
readonly vpc: Vpc;
Expand Down Expand Up @@ -69,11 +69,7 @@ export class JenkinsExternalLoadBalancer {

this.loadBalancer.logAccessLogs(props.accessLogBucket, accessLoggingPrefix);

const bucketPolicy = new BucketPolicy(stack, 'ALBaccessLoggingBucketPolicyPErmission', {
bucket: props.accessLogBucket,
});

bucketPolicy.document.addStatements(
props.accessLogBucket.addToResourcePolicy(
new PolicyStatement({
actions: ['s3:PutObject'],
principals: [
Expand Down
78 changes: 78 additions & 0 deletions test/ci-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,84 @@ test('LoadBalancer Access Logging', () => {
Template.fromStack(stack).hasResourceProperties('AWS::S3::BucketPolicy', {
PolicyDocument: {
Statement: [
{
Action: [
's3:PutObject',
's3:PutObjectLegalHold',
's3:PutObjectRetention',
's3:PutObjectTagging',
's3:PutObjectVersionTagging',
's3:Abort*',
],
Effect: 'Allow',
Principal: {
AWS: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::127311923021:root',
],
],
},
},
Resource: {
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'jenkinsAuditBucket110D3080',
'Arn',
],
},
'/loadBalancerAccessLogs/AWSLogs/test-account/*',
],
],
},
},
{
Action: 's3:PutObject',
Condition: {
StringEquals: {
's3:x-amz-acl': 'bucket-owner-full-control',
},
},
Effect: 'Allow',
Principal: {
Service: 'delivery.logs.amazonaws.com',
},
Resource: {
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'jenkinsAuditBucket110D3080',
'Arn',
],
},
'/loadBalancerAccessLogs/AWSLogs/test-account/*',
],
],
},
},
{
Action: 's3:GetBucketAcl',
Effect: 'Allow',
Principal: {
Service: 'delivery.logs.amazonaws.com',
},
Resource: {
'Fn::GetAtt': [
'jenkinsAuditBucket110D3080',
'Arn',
],
},
},
{
Action: 's3:PutObject',
Effect: 'Allow',
Expand Down

0 comments on commit 766302e

Please sign in to comment.