Skip to content

Commit

Permalink
fix: Implement IRSA mode to allow k8s deployments to use mounted serv…
Browse files Browse the repository at this point in the history
…ice account auth (percona#98)
  • Loading branch information
michaelbauerinc authored Dec 13, 2024
1 parent 929f899 commit 915aceb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Instance struct {
DisableBasicMetrics bool `yaml:"disable_basic_metrics"`
DisableEnhancedMetrics bool `yaml:"disable_enhanced_metrics"`
Labels map[string]string `yaml:"labels"` // may be empty
IRSAEnabled bool `yaml:"irsa_enabled"`

// TODO Type InstanceType `yaml:"type"` // may be empty for old pmm-managed
}
Expand Down
15 changes: 15 additions & 0 deletions sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ func (s *Sessions) GetSession(region, instance string) (*session.Session, *Insta
}

func buildCredentials(instance config.Instance) (*credentials.Credentials, error) {
// If IRSA is enabled, let the AWS SDK use the default credential provider chain,
// which includes the service account role credentials.
if instance.IRSAEnabled {
// Create a new session with just the region set, no credentials provided explicitly.
// This allows the SDK to use the credentials mounted by IRSA.
stsSession, err := session.NewSession(&aws.Config{
Region: aws.String(instance.Region),
})
if err != nil {
return nil, err
}

return stsSession.Config.Credentials, nil
}

if instance.AWSRoleArn != "" {
stsSession, err := session.NewSession(&aws.Config{
Region: aws.String(instance.Region),
Expand Down

0 comments on commit 915aceb

Please sign in to comment.