Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix(filemanager): add permissions that allow API/inventory functions to access pipeline-*-cache buckets #670

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/stacks/fileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getFileManagerStackProps = (stage: AppStage): FilemanagerConfig =>
migrateDatabase: true,
inventorySourceBuckets: ['filemanager-inventory-test'],
eventSourceBuckets: [oncoanalyserBucket[stage], icav2PipelineCacheBucket[stage]],
fileManagerIngestRoleName: fileManagerIngestRoleName,
fileManagerRoleName: fileManagerIngestRoleName,
apiGatewayCognitoProps: {
...cognitoApiGatewayConfig,
corsAllowOrigins: corsAllowOrigins[stage],
Expand Down
22 changes: 13 additions & 9 deletions lib/workload/stateless/stacks/filemanager/deploy/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { HttpMethod, HttpRoute, HttpRouteKey } from 'aws-cdk-lib/aws-apigatewayv
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
import { InventoryFunction } from './constructs/functions/inventory';
import { NamedLambdaRole } from '../../../../components/named-lambda-role';
import { Role } from 'aws-cdk-lib/aws-iam';

export const FILEMANAGER_SERVICE_NAME = 'filemanager';

Expand All @@ -27,7 +28,7 @@ export type FilemanagerConfig = Omit<DatabaseProps, 'host' | 'securityGroup'> &
vpcProps: VpcLookupOptions;
migrateDatabase?: boolean;
securityGroupName: string;
fileManagerIngestRoleName: string;
fileManagerRoleName: string;
apiGatewayCognitoProps: ApiGatewayConstructProps;
};

Expand Down Expand Up @@ -63,6 +64,7 @@ export class Filemanager extends Stack {
props.databaseClusterEndpointHostParameter
);

const role = this.createRole(props.fileManagerRoleName);
if (props?.migrateDatabase) {
const migrateFunction = new MigrateFunction(this, 'MigrateFunction', {
vpc: this.vpc,
Expand All @@ -89,53 +91,55 @@ export class Filemanager extends Stack {
)
);

this.createIngestFunction(props);
this.createInventoryFunction(props);
this.createIngestFunction(props, role);
this.createInventoryFunction(props, role);

this.domainName = this.createApiFunction(props);
this.domainName = this.createApiFunction(props, role);
}

private createIngestRole(name: string) {
private createRole(name: string) {
return new NamedLambdaRole(this, 'IngestFunctionRole', { name });
}

/**
* Lambda function definitions and surrounding infrastructure.
*/
private createIngestFunction(props: FilemanagerProps) {
private createIngestFunction(props: FilemanagerProps, role: Role) {
return new IngestFunction(this, 'IngestFunction', {
vpc: this.vpc,
host: this.host,
securityGroup: this.securityGroup,
eventSources: [this.queue],
buckets: props.eventSourceBuckets,
role: this.createIngestRole(props.fileManagerIngestRoleName),
role,
...props,
});
}

/**
* Create the inventory function.
*/
private createInventoryFunction(props: FilemanagerProps) {
private createInventoryFunction(props: FilemanagerProps, role: Role) {
return new InventoryFunction(this, 'InventoryFunction', {
vpc: this.vpc,
host: this.host,
securityGroup: this.securityGroup,
port: props.port,
buckets: props.inventorySourceBuckets,
role,
});
}

/**
* Query function and API Gateway fronting the function. Returns the configured domain name.
*/
private createApiFunction(props: FilemanagerProps): string {
private createApiFunction(props: FilemanagerProps, role: Role): string {
let apiLambda = new ApiFunction(this, 'ApiFunction', {
vpc: this.vpc,
host: this.host,
securityGroup: this.securityGroup,
buckets: [...props.eventSourceBuckets, ...props.inventorySourceBuckets],
role,
...props,
});

Expand Down