awscloud: add option to mark S3 object as public

By setting the object's ACL to "public-read", anyone can download the object
even without authenticating with AWS.

The osbuild-upload-generic-s3 command got a new -public argument that
uses this new feature.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2022-08-15 15:16:09 +02:00 committed by Sanne Raymaekers
parent 1c3fe82d1e
commit 0e6c132ee6
2 changed files with 25 additions and 0 deletions

View file

@ -581,3 +581,18 @@ func (a *AWS) S3ObjectPresignedURL(bucket, objectKey string) (string, error) {
logrus.Info("[AWS] 🎉 S3 Presigned URL ready")
return url, nil
}
func (a *AWS) MarkS3ObjectAsPublic(bucket, objectKey string) error {
logrus.Infof("[AWS] 👐 Making S3 object public %s/%s", bucket, objectKey)
_, err := a.s3.PutObjectAcl(&s3.PutObjectAclInput{
Bucket: aws.String(bucket),
Key: aws.String(objectKey),
ACL: aws.String(s3.BucketCannedACLPublicRead),
})
if err != nil {
return err
}
logrus.Info("[AWS] ✔️ Making S3 object public successful")
return nil
}