Skip to content

Commit f408e7f

Browse files
dlvenableJonah Calvo
authored andcommitted
Creates an IAM role granting the OpenSearch CI access to the S3 artifacts (opensearch-project#5815)
Creates an IAM role that the OpenSearch CI build server can assume to gain access to the S3 bucket for archives. Contributes toward opensearch-project#5796 by allowing the server to perform a full S3 download of the Maven artifacts. Signed-off-by: David Venable <dlv@amazon.com> Signed-off-by: Jonah Calvo <caljonah@amazon.com>
1 parent 4aa1b17 commit f408e7f

5 files changed

Lines changed: 791 additions & 273 deletions

File tree

release/staging-resources-cdk/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ The following CDK commands all require defining context. The context variables a
5252

5353
* `archivesBucketName` - The name of the S3 bucket you will use to deploy. This bucket must be in the same region as your stack.
5454
* `dataPrepperOrganization` - The name of the GitHub organization which has the `data-prepper` repository. This allows you to create staging environments for forks. The default value is `opensearch-project`.
55+
* `ciAccountId` - The AWS account Id of the OpenSearch CI release/build server.
5556

5657
The following command will deploy the CDK stack and create a new S3 bucket. If you'd like to use an existing S3 bucket, see the section below
5758
for deploying individual stacks.
5859

5960
```
60-
cdk deploy --all --context archivesBucketName={s3-bucket-name} --context dataPrepperOrganization={data-prepper-organization-name}
61+
cdk deploy --all --context archivesBucketName={s3-bucket-name} --context dataPrepperOrganization={data-prepper-organization-name} --context ciAccountId={opensearch-ci-account-id}
6162
```
6263

6364
#### Deploy to Use an Existing S3 Bucket

release/staging-resources-cdk/bin/staging-resources-cdk.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {GitHubAccessStack} from '../lib/GitHubAccessStack';
1111
import {ArchivesBucketStack} from '../lib/ArchivesBucketStack';
1212
import {StagingResourcesStack} from '../lib/StagingResourcesStack';
1313
import {GitHubActionsReleaseAccessStack} from '../lib/GitHubActionsReleaseAccessStack';
14+
import { OpenSearchCIAccessStack } from '../lib/OpenSearchCIAccessStack';
1415

1516

1617
const app = new App();
@@ -27,6 +28,10 @@ const stagingResourcesStack = new StagingResourcesStack(app, 'StagingResourcesSt
2728
stackName: 'StagingResources'
2829
});
2930

31+
new OpenSearchCIAccessStack(app, 'OpenSearchCIAccessStack', {
32+
stackName: 'DataPrepperStagingResources-OpenSearchCIAccess'
33+
});
34+
3035
new GitHubActionsReleaseAccessStack(app, 'GitHubActionsReleaseAccessStack', {
3136
stackName: 'GitHubActionsReleaseAccess',
3237
gitHubOidcProvider: gitHubAccessStack.gitHubOidcProvider,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
import { Stack, StackProps } from 'aws-cdk-lib';
11+
import { Role, ArnPrincipal, PolicyStatement, Effect, PolicyDocument, CompositePrincipal } from 'aws-cdk-lib/aws-iam';
12+
import { Construct } from 'constructs';
13+
14+
/**
15+
* This stack creates resources necessary for the OpenSearch CI server
16+
* to access the staging archives bucket by assuming a role in the staging
17+
* account.
18+
*/
19+
export class OpenSearchCIAccessStack extends Stack {
20+
constructor(scope: Construct, id: string, props?: StackProps) {
21+
super(scope, id, props);
22+
23+
const archivesBucketName: string = scope.node.tryGetContext('archivesBucketName');
24+
const ciAccountId: string = scope.node.tryGetContext('ciAccountId');
25+
26+
new Role(this, 'OpenSearchCIAccessRole', {
27+
assumedBy: new CompositePrincipal(
28+
new ArnPrincipal(`arn:aws:iam::${ciAccountId}:role/OpenSearch-CI-MainNodeRole`),
29+
new ArnPrincipal(`arn:aws:iam::${ciAccountId}:role/OpenSearch-CI-AgentNodeRole`)
30+
),
31+
inlinePolicies: {
32+
S3Access: new PolicyDocument({
33+
statements: [new PolicyStatement({
34+
effect: Effect.ALLOW,
35+
actions: ['s3:GetObject', 's3:ListBucket', 's3:GetObjectAcl'],
36+
resources: [
37+
`arn:aws:s3:::${archivesBucketName}`,
38+
`arn:aws:s3:::${archivesBucketName}/*`
39+
]
40+
})]
41+
})
42+
}
43+
});
44+
}
45+
}

0 commit comments

Comments
 (0)