Skip to content

Commit 186888f

Browse files
authored
fix(aws): do not load creds from env vars (#2509)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent 112aec3 commit 186888f

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
entgo.io/ent v0.14.4
1010
github.com/adrg/xdg v0.4.0
1111
github.com/aws/aws-sdk-go-v2 v1.39.4
12-
github.com/aws/aws-sdk-go-v2/config v1.31.15
12+
github.com/aws/aws-sdk-go-v2/config v1.31.15 // indirect
1313
github.com/aws/aws-sdk-go-v2/credentials v1.18.19
1414
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
1515
github.com/aws/aws-sdk-go-v2/service/sso v1.29.8

pkg/blobmanager/s3/backend.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"strings"
2727

2828
"github.com/aws/aws-sdk-go-v2/aws"
29-
"github.com/aws/aws-sdk-go-v2/config"
3029
"github.com/aws/aws-sdk-go-v2/credentials"
3130
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
3231
"github.com/aws/aws-sdk-go-v2/service/s3"
@@ -72,16 +71,11 @@ func NewBackend(creds *Credentials) (*Backend, error) {
7271
return nil, fmt.Errorf("failed to parse bucket name: %w", err)
7372
}
7473

75-
// Configure AWS config with v2 SDK
76-
cfg, err := config.LoadDefaultConfig(
77-
context.TODO(),
78-
config.WithRegion(region),
79-
config.WithCredentialsProvider(
80-
credentials.NewStaticCredentialsProvider(creds.AccessKeyID, creds.SecretAccessKey, ""),
81-
),
82-
)
83-
if err != nil {
84-
return nil, fmt.Errorf("failed to load AWS config: %w", err)
74+
// Using AWS config directly instead of using config.LoadDefaultConfig
75+
// to avoid the default credential chain and use only the static credentials
76+
cfg := aws.Config{
77+
Region: region,
78+
Credentials: credentials.NewStaticCredentialsProvider(creds.AccessKeyID, creds.SecretAccessKey, ""),
8579
}
8680

8781
// Create S3 client with custom options if needed

pkg/credentials/aws/secretmanager.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2023-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import (
2424
"strings"
2525

2626
"github.com/aws/aws-sdk-go-v2/aws"
27-
"github.com/aws/aws-sdk-go-v2/config"
2827
awscreds "github.com/aws/aws-sdk-go-v2/credentials"
2928
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
3029
"github.com/aws/aws-sdk-go-v2/service/sso/types"
@@ -67,15 +66,11 @@ func NewManager(opts *NewManagerOpts) (*Manager, error) {
6766
logger := servicelogger.ScopedHelper(l, "credentials/aws-secrets-manager")
6867
logger.Infow("msg", "configuring secrets-manager", "region", opts.Region, "role", opts.Role, "prefix", opts.SecretPrefix)
6968

70-
config, err := config.LoadDefaultConfig(
71-
context.TODO(),
72-
config.WithRegion(opts.Region),
73-
config.WithCredentialsProvider(
74-
awscreds.NewStaticCredentialsProvider(opts.AccessKey, opts.SecretKey, ""),
75-
),
76-
)
77-
if err != nil {
78-
return nil, fmt.Errorf("loading AWS config: %w", err)
69+
// Using AWS config directly instead of using config.LoadDefaultConfig
70+
// to avoid the default credential chain and use only the static credentials
71+
config := aws.Config{
72+
Region: opts.Region,
73+
Credentials: awscreds.NewStaticCredentialsProvider(opts.AccessKey, opts.SecretKey, ""),
7974
}
8075

8176
return &Manager{

0 commit comments

Comments
 (0)