Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-chappell committed Nov 29, 2024
1 parent da28bba commit 6cda185
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/cdk/lib/cloudquery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import {
snykSourceConfig,
} from './config';
import { Images } from './images';
import { cloudqueryAccess, listOrgsPolicy, readBucketPolicy } from './policies';
import {
cloudqueryAccess,
listOrgsPolicy,
readBucketPolicy,
readDynamoDbTablePolicy,
} from './policies';

interface CloudqueryEcsClusterProps {
vpc: IVpc;
Expand Down Expand Up @@ -620,6 +625,15 @@ export function addCloudqueryEcsCluster(
'packages-bucket-name',
),
},
policies: [
readDynamoDbTablePolicy(
GuardianAwsAccounts.DeployTools,
'{BASE_IMAGES_TABLE_NAME}',
'{RECIPES_TABLE_NAME}',
'{BAKES_TABLE_NAME}',
),
readBucketPolicy('arn:aws:s3:::${PACKAGES_BUCKET_NAME}/packagelists/*'),
],
};

return new CloudqueryCluster(scope, `${app}Cluster`, {
Expand Down
26 changes: 26 additions & 0 deletions packages/cdk/lib/cloudquery/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ export const readBucketPolicy = (...resources: string[]): PolicyStatement => {
});
};

/**
* Create a policy statement allowing read access to the given DynamoDB tables.
*
* @param accountId the AWS account ID
* @param tableNames a list of DynamoDB table names
* @returns a policy statement allowing read access to the given DynamoDB tables.
*/
export const readDynamoDbTablePolicy = (
accountId: string,
...tableNames: string[]
): PolicyStatement => {
return new PolicyStatement({
effect: Effect.ALLOW,
// for each table name, create a resource ARN
resources: tableNames.map(
(tableName) => `arn:aws:dynamodb::${accountId}:table/${tableName}`,
),
actions: [
'dynamodb:GetItem',
'dynamodb:BatchGetItem',
'dynamodb:Query',
'dynamodb:Scan',
],
});
};

export function singletonPolicy(cluster: Cluster) {
return new PolicyStatement({
effect: Effect.ALLOW,
Expand Down

0 comments on commit 6cda185

Please sign in to comment.