Skip to content

Commit

Permalink
[Bug 1570800] Add real support for public artifacts in dev envs (task…
Browse files Browse the repository at this point in the history
…cluster#1144)

[Bug 1570800] Add real support for public artifacts in dev envs
  • Loading branch information
imbstack authored Aug 2, 2019
2 parents a0a579e + 67ab7b5 commit efd65e3
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions infrastructure/builder/src/dev/aws.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash');
const AWS = require('aws-sdk');

const setupIam = async ({iam, iamName, iamPolicy}) => {
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = async ({userConfig, answer, configTmpl}) => {

userConfig.queue = userConfig.queue || {};

// TODO: Add private artifact bucket and both blob buckets
// TODO: Add both blob buckets
// TODO: Also set up auth/notify aws stuff

const publicBucketName = `${prefix}-public-artifacts`;
Expand All @@ -54,7 +55,29 @@ module.exports = async ({userConfig, answer, configTmpl}) => {
ACL: 'public-read',
}).promise();
userConfig.queue.public_artifact_bucket = publicBucketName;
// TODO: Set up policy that allows for objects in here to be read
}

const publicPolicy = {
Version: '2012-10-17',
Statement: [
{
Sid: "PublicReadGetObject",
Effect: "Allow",
Principal: {
AWS: "*",
},
Action: "s3:GetObject",
Resource: `arn:aws:s3:::${publicBucketName}/*`,
},
],
};
if (!userConfig.meta.lastAppliedPublicBucketPolicy ||
!_.isEqual(userConfig.meta.lastAppliedPublicBucketPolicy, publicPolicy)) {
await s3.putBucketPolicy({
Bucket: publicBucketName,
Policy: JSON.stringify(publicPolicy),
}).promise();
userConfig.meta.lastAppliedPublicBucketPolicy = publicPolicy;
}

if (!userConfig.queue.private_artifact_bucket) {
Expand Down

0 comments on commit efd65e3

Please sign in to comment.