Skip to content

Commit

Permalink
hotfix(filemanager): add permissions for api and inventory to access …
Browse files Browse the repository at this point in the history
…byob objects by re-using the ingest role
  • Loading branch information
mmalenic committed Nov 8, 2024
1 parent 518c705 commit fa4f7f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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

0 comments on commit fa4f7f9

Please sign in to comment.