Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions discovery/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type SDConfig struct {
SecretKey config.Secret `yaml:"secret_key,omitempty"`
Profile string `yaml:"profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
ExternalID string `yaml:"external_id,omitempty"`
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
Port int `yaml:"port,omitempty"`
HTTPClientConfig config.HTTPClientConfig `yaml:",inline"`
Expand Down Expand Up @@ -136,6 +137,9 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error {
if c.RoleARN != "" {
c.EC2SDConfig.RoleARN = c.RoleARN
}
if c.ExternalID != "" {
c.EC2SDConfig.ExternalID = c.ExternalID
}
if c.Port != 0 {
c.EC2SDConfig.Port = c.Port
}
Expand Down Expand Up @@ -167,6 +171,9 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error {
if c.RoleARN != "" {
c.ECSSDConfig.RoleARN = c.RoleARN
}
if c.ExternalID != "" {
c.ECSSDConfig.ExternalID = c.ExternalID
}
if c.Port != 0 {
c.ECSSDConfig.Port = c.Port
}
Expand Down Expand Up @@ -198,6 +205,9 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error {
if c.RoleARN != "" {
c.ElasticacheSDConfig.RoleARN = c.RoleARN
}
if c.ExternalID != "" {
c.ElasticacheSDConfig.ExternalID = c.ExternalID
}
if c.Port != 0 {
c.ElasticacheSDConfig.Port = c.Port
}
Expand Down Expand Up @@ -229,6 +239,9 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error {
if c.RoleARN != "" {
c.LightsailSDConfig.RoleARN = c.RoleARN
}
if c.ExternalID != "" {
c.LightsailSDConfig.ExternalID = c.ExternalID
}
if c.Port != 0 {
c.LightsailSDConfig.Port = c.Port
}
Expand Down Expand Up @@ -257,6 +270,9 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error {
if c.RoleARN != "" {
c.MSKSDConfig.RoleARN = c.RoleARN
}
if c.ExternalID != "" {
c.MSKSDConfig.ExternalID = c.ExternalID
}
if c.Port != 0 {
c.MSKSDConfig.Port = c.Port
}
Expand Down Expand Up @@ -288,6 +304,9 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error {
if c.RoleARN != "" {
c.RDSSDConfig.RoleARN = c.RoleARN
}
if c.ExternalID != "" {
c.RDSSDConfig.ExternalID = c.ExternalID
}
if c.Port != 0 {
c.RDSSDConfig.Port = c.Port
}
Expand Down
7 changes: 6 additions & 1 deletion discovery/aws/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type ECSSDConfig struct {
SecretKey config.Secret `yaml:"secret_key,omitempty"`
Profile string `yaml:"profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
ExternalID string `yaml:"external_id,omitempty"`
Clusters []string `yaml:"clusters,omitempty"`
Port int `yaml:"port"`
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
Expand Down Expand Up @@ -241,7 +242,11 @@ func (d *ECSDiscovery) initEcsClient(ctx context.Context) error {

// If the role ARN is set, assume the role to get credentials and set the credentials provider in the config.
if d.cfg.RoleARN != "" {
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN)
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN, func(o *stscreds.AssumeRoleOptions) {
if d.cfg.ExternalID != "" {
o.ExternalID = aws.String(d.cfg.ExternalID)
}
})
cfg.Credentials = aws.NewCredentialsCache(assumeProvider)
}

Expand Down
7 changes: 6 additions & 1 deletion discovery/aws/elasticache.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type ElasticacheSDConfig struct {
SecretKey config.Secret `yaml:"secret_key,omitempty"`
Profile string `yaml:"profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
ExternalID string `yaml:"external_id,omitempty"`
Clusters []string `yaml:"clusters,omitempty"`
Port int `yaml:"port"`
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
Expand Down Expand Up @@ -319,7 +320,11 @@ func (d *ElasticacheDiscovery) initElasticacheClient(ctx context.Context) error

// If the role ARN is set, assume the role to get credentials and set the credentials provider in the config.
if d.cfg.RoleARN != "" {
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN)
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN, func(o *stscreds.AssumeRoleOptions) {
if d.cfg.ExternalID != "" {
o.ExternalID = aws.String(d.cfg.ExternalID)
}
})
cfg.Credentials = aws.NewCredentialsCache(assumeProvider)
}

Expand Down
7 changes: 6 additions & 1 deletion discovery/aws/msk.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type MSKSDConfig struct {
SecretKey config.Secret `yaml:"secret_key,omitempty"`
Profile string `yaml:"profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
ExternalID string `yaml:"external_id,omitempty"`
Clusters []string `yaml:"clusters,omitempty"`
Port int `yaml:"port"`
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
Expand Down Expand Up @@ -231,7 +232,11 @@ func (d *MSKDiscovery) initMskClient(ctx context.Context) error {

// If the role ARN is set, assume the role to get credentials and set the credentials provider in the config.
if d.cfg.RoleARN != "" {
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN)
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN, func(o *stscreds.AssumeRoleOptions) {
if d.cfg.ExternalID != "" {
o.ExternalID = aws.String(d.cfg.ExternalID)
}
})
cfg.Credentials = aws.NewCredentialsCache(assumeProvider)
}

Expand Down
7 changes: 6 additions & 1 deletion discovery/aws/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ type RDSSDConfig struct {
SecretKey config.Secret `yaml:"secret_key,omitempty"`
Profile string `yaml:"profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
ExternalID string `yaml:"external_id,omitempty"`
Clusters []string `yaml:"clusters,omitempty"`
Port int `yaml:"port"`
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
Expand Down Expand Up @@ -349,7 +350,11 @@ func (d *RDSDiscovery) initRdsClient(ctx context.Context) error {

// If the role ARN is set, assume the role to get credentials and set the credentials provider in the config.
if d.cfg.RoleARN != "" {
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN)
assumeProvider := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), d.cfg.RoleARN, func(o *stscreds.AssumeRoleOptions) {
if d.cfg.ExternalID != "" {
o.ExternalID = aws.String(d.cfg.ExternalID)
}
})
cfg.Credentials = aws.NewCredentialsCache(assumeProvider)
}

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,9 @@ role: <string>
# AWS Role ARN, an alternative to using AWS API keys.
[ role_arn: <string> ]

# Optional External ID that can go along with role_arn.
[ external_id: <string> ]

# Refresh interval to re-read the targets list.
[ refresh_interval: <duration> | default = 60s ]

Expand Down