Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
feat: enable encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Vahor committed Dec 25, 2023
1 parent 3df2a05 commit a72a468
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions aws/policies/pulumi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"s3:List*",
"s3:PutBucketPublicAccessBlock",
"s3:PutBucketPolicy",
"s3:PutEncryptionConfiguration",
"s3:DeleteBucketPolicy"
],
"Resource": [
Expand Down
38 changes: 37 additions & 1 deletion src/aws/resources/files-bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,52 @@ export const createFilesBucket = () => {
const bucket = new aws.s3.Bucket('files.pedaki.fr', {
bucket: 'files.pedaki.fr',
acl: 'private',
serverSideEncryptionConfiguration: {
rule: {
applyServerSideEncryptionByDefault: {
sseAlgorithm: 'aws:kms',
},
bucketKeyEnabled: true,
},
},
});

const publicAccessBlock = new aws.s3.BucketPublicAccessBlock('publicAccessBlock', {
const publicAccessBlock = new aws.s3.BucketPublicAccessBlock('files.pedaki.fr-publicAccessBlock', {
bucket: bucket.id,
blockPublicAcls: true,
blockPublicPolicy: true,
ignorePublicAcls: true,
restrictPublicBuckets: true,
});

const policy = new aws.s3.BucketPolicy(
'files-bucket-policy',
{
bucket: bucket.id,
policy: bucket.arn.apply(arn =>
JSON.stringify({
// all files should be encrypted
Version: '2012-10-17',
Statement: [
{
Sid: 'DenyUnEncryptedObjectUploads',
Effect: 'Deny',
Principal: '*',
Action: 's3:PutObject',
Resource: `${arn}/*`,
Condition: {
StringNotEquals: {
's3:x-amz-server-side-encryption': 'aws:kms',
},
},
},
],
}),
),
},
{ dependsOn: [publicAccessBlock] },
);

const record = new cloudflare.Record('files.pedaki.fr', {
name: 'files',
type: 'CNAME',
Expand Down
4 changes: 2 additions & 2 deletions src/aws/resources/static-bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const createStaticBucket = () => {
bucket: 'static.pedaki.fr',
});

const publicAccessBlock = new aws.s3.BucketPublicAccessBlock('publicAccessBlock', {
const publicAccessBlock = new aws.s3.BucketPublicAccessBlock('static.pedaki.fr-publicAccessBlock', {
bucket: bucket.id,
blockPublicAcls: false,
blockPublicPolicy: false,
Expand All @@ -16,7 +16,7 @@ export const createStaticBucket = () => {
});

const _ = new aws.s3.BucketPolicy(
'bucket-policy',
'static-bucket-policy',
{
bucket: bucket.id,
policy: bucket.arn.apply(arn =>
Expand Down

0 comments on commit a72a468

Please sign in to comment.