Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 080c2e5

Browse files
authored
Only use anon credentials for public s3 buckets (#187)
* Only use anon credentials for public s3 buckets Fixes #188
1 parent 6ac4c7a commit 080c2e5

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
- Nothing.
2525

26+
## [1.2.2] - 2021-10-01
27+
28+
- [#188](https://github.com/meltwater/drone-cache/pull/188) v1.2.0 breaks EC2 IAM role bucket access
29+
2630
## [1.2.1] - 2021-09-30
2731

2832
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ GLOBAL OPTIONS:
180180
--path-style AWS path style to use for bucket paths. (true for minio, false for aws) (default: false) [$PLUGIN_PATH_STYLE, $AWS_PLUGIN_PATH_STYLE]
181181
--acl value upload files with acl (private, public-read, ...) (default: "private") [$PLUGIN_ACL, $AWS_ACL]
182182
--encryption value server-side encryption algorithm, defaults to none. (AES256, aws:kms) [$PLUGIN_ENCRYPTION, $AWS_ENCRYPTION]
183+
--s3-bucket-public value Set to use anonymous credentials with public S3 bucket [$PLUGIN_S3_BUCKET_PUBLIC, $S3_BUCKET_PUBLIC]
183184
--sts-endpoint value Custom STS endpoint for IAM role assumption [$PLUGIN_STS_ENDPOINT, $AWS_STS_ENDPOINT]
184185
--role-arn value AWS IAM role ARN to assume [$PLUGIN_ASSUME_ROLE_ARN, $AWS_ASSUME_ROLE_ARN]
185186
--gcs.api-key value Google service account API key [$PLUGIN_API_KEY, $GCP_API_KEY]

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ func main() {
363363
Usage: "server-side encryption algorithm, defaults to none. (AES256, aws:kms)",
364364
EnvVars: []string{"PLUGIN_ENCRYPTION", "AWS_ENCRYPTION"},
365365
},
366+
&cli.StringFlag{
367+
Name: "s3-bucket-public",
368+
Usage: "Set to use anonymous credentials with public S3 bucket",
369+
EnvVars: []string{"PLUGIN_S3_BUCKET_PUBLIC", "S3_BUCKET_PUBLIC"},
370+
},
366371
&cli.StringFlag{
367372
Name: "sts-endpoint",
368373
Usage: "Custom STS endpoint for IAM role assumption",
@@ -546,6 +551,7 @@ func run(c *cli.Context) error {
546551
Endpoint: c.String("endpoint"),
547552
Key: c.String("access-key"),
548553
PathStyle: c.Bool("path-style"),
554+
Public: c.Bool("s3-bucket-public"),
549555
Region: c.String("region"),
550556
Secret: c.String("secret-key"),
551557
StsEndpoint: c.String("sts-endpoint"),

storage/backend/s3/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ type Config struct {
3030
Secret string
3131

3232
PathStyle bool // Use path style instead of domain style. Should be true for minio and false for AWS.
33+
Public bool
3334
}

storage/backend/s3/s3.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ func New(l log.Logger, c Config, debug bool) (*Backend, error) {
3636
Endpoint: &c.Endpoint,
3737
DisableSSL: aws.Bool(!strings.HasPrefix(c.Endpoint, "https://")),
3838
S3ForcePathStyle: aws.Bool(c.PathStyle),
39-
Credentials: credentials.AnonymousCredentials,
39+
}
40+
41+
// Use anonymous credentials if the S3 bucket is public
42+
if c.Public {
43+
conf.Credentials = credentials.AnonymousCredentials
4044
}
4145

4246
if c.Key != "" && c.Secret != "" {

0 commit comments

Comments
 (0)