Skip to content

Commit d1e4b32

Browse files
Assume user role ARN (#81)
Co-authored-by: Joakim Tallinger <[email protected]>
1 parent a123409 commit d1e4b32

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func main() {
4747
Value: "drone-s3",
4848
EnvVar: "PLUGIN_ASSUME_ROLE_SESSION_NAME,ASSUME_ROLE_SESSION_NAME",
4949
},
50+
cli.StringFlag{
51+
Name: "user-role-arn",
52+
Usage: "AWS user role",
53+
EnvVar: "PLUGIN_USER_ROLE_ARN,AWS_USER_ROLE_ARN",
54+
},
5055
cli.StringFlag{
5156
Name: "bucket",
5257
Usage: "aws bucket",
@@ -146,6 +151,7 @@ func run(c *cli.Context) error {
146151
AssumeRole: c.String("assume-role"),
147152
AssumeRoleSessionName: c.String("assume-role-session-name"),
148153
Bucket: c.String("bucket"),
154+
UserRoleArn: c.String("user-role-arn"),
149155
Region: c.String("region"),
150156
Access: c.String("acl"),
151157
Source: c.String("source"),

plugin.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Plugin struct {
2626
AssumeRole string
2727
AssumeRoleSessionName string
2828
Bucket string
29+
UserRoleArn string
2930

3031
// if not "", enable server-side encryption
3132
// valid values are:
@@ -114,13 +115,24 @@ func (p *Plugin) Exec() error {
114115
log.Warn("AWS Key and/or Secret not provided (falling back to ec2 instance profile)")
115116
}
116117

118+
var client *s3.S3
117119
sess, err := session.NewSession(conf)
118120
if err != nil {
119121
log.WithError(err).Errorln("could not instantiate session")
120122
return err
121123
}
122124

123-
client := s3.New(sess)
125+
// If user role ARN is set then assume role here
126+
if len(p.UserRoleArn) > 0 {
127+
confRoleArn := aws.Config{
128+
Region: aws.String(p.Region),
129+
Credentials: stscreds.NewCredentials(sess, p.UserRoleArn),
130+
}
131+
132+
client = s3.New(sess, &confRoleArn)
133+
} else {
134+
client = s3.New(sess)
135+
}
124136

125137
// find the bucket
126138
log.WithFields(log.Fields{

0 commit comments

Comments
 (0)