Skip to content

Commit 07d1d9d

Browse files
avinash1IBMGitHub Enterprise
authored and
GitHub Enterprise
committed
Release 1.11.0
1 parent cf5ad02 commit 07d1d9d

25 files changed

+2943
-18
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# CHANGELOG
22

3+
## 1.11.0
4+
5+
### Content
6+
7+
#### Features
8+
9+
* Trusted Profile Authentication Support for Compute Resources.
10+
11+
#### Defect Fixes
12+
13+
* Update dependencies
14+
* Support for Golang 1.22.0
15+
316
## 1.10.3
417

518
### Content

aws/credentials/ibmiam/common.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,10 @@ func (p *Provider) Retrieve() (credentials.Value, error) {
125125
var returnErr error
126126
if p.logLevel.Matches(aws.LogDebug) {
127127
p.logger.Log(debugLog, ibmiamProviderLog, p.providerName, "ERROR ON GET", err)
128-
returnErr = awserr.New("TokenManagerRetrieveError", "error retrieving the token", err)
129-
} else {
130-
returnErr = awserr.New("TokenManagerRetrieveError", "error retrieving the token", nil)
131128
}
129+
returnErr = awserr.New("TokenManagerRetrieveError", "error retrieving the token", err)
132130
return credentials.Value{}, returnErr
133131
}
134-
if p.logLevel.Matches(aws.LogDebug) {
135-
p.logger.Log(debugLog, ibmiamProviderLog, p.providerName, "GET TOKEN", tokenValue)
136-
}
137132

138133
return credentials.Value{Token: *tokenValue, ProviderName: p.providerName, ProviderType: p.providerType,
139134
ServiceInstanceID: p.serviceInstanceID}, nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ibmiam
2+
3+
import (
4+
"os"
5+
6+
"github.com/IBM/ibm-cos-sdk-go/aws"
7+
"github.com/IBM/ibm-cos-sdk-go/aws/credentials"
8+
)
9+
10+
// EnvProviderName name of the IBM IAM provider that loads IAM trusted profile
11+
// credentials from environment variables
12+
const EnvProviderTrustedProfileName = "EnvProviderTrustedProfileIBM"
13+
14+
// NewEnvProvider constructor of the IBM IAM provider that loads IAM trusted profile
15+
// credentials from environment variables
16+
// Parameter:
17+
//
18+
// AWS Config
19+
//
20+
// Returns:
21+
//
22+
// A new provider with AWS config, Trusted Profile ID, CR token file path, IBM IAM Authentication Server Endpoint and
23+
// Service Instance ID
24+
func NewEnvProviderTrustedProfile(config *aws.Config) *TrustedProfileProvider {
25+
trustedProfileID := os.Getenv("TRUSTED_PROFILE_ID")
26+
serviceInstanceID := os.Getenv("IBM_SERVICE_INSTANCE_ID")
27+
crTokenFilePath := os.Getenv("CR_TOKEN_FILE_PATH")
28+
authEndPoint := os.Getenv("IBM_AUTH_ENDPOINT")
29+
30+
return NewTrustedProfileProvider(EnvProviderTrustedProfileName, config, authEndPoint, trustedProfileID, crTokenFilePath, serviceInstanceID, "CR")
31+
}
32+
33+
// NewEnvCredentials Constructor
34+
func NewEnvCredentialsTrustedProfile(config *aws.Config) *credentials.Credentials {
35+
return credentials.NewCredentials(NewEnvProviderTrustedProfile(config))
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ibmiam
2+
3+
import (
4+
"os"
5+
6+
"github.com/IBM/ibm-cos-sdk-go/aws/awserr"
7+
)
8+
9+
// Helper function to check whether both api-key and trusted-profile-id are set
10+
// in environment variables.
11+
//
12+
// Returns:
13+
//
14+
// Error if both apiKey and trustedProfileID are set, nil if only either of them is set.
15+
func CheckForConflictingIamCredentials() error {
16+
apiKey := os.Getenv("IBM_API_KEY_ID")
17+
trustedProfileID := os.Getenv("TRUSTED_PROFILE_ID")
18+
19+
if apiKey != "" && trustedProfileID != "" {
20+
return awserr.New("InvalidCredentials",
21+
`only one of ApiKey or TrustedProfileID should be set, not both`,
22+
nil)
23+
}
24+
return nil
25+
}
+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package ibmiam
2+
3+
import (
4+
"github.com/IBM/go-sdk-core/v5/core"
5+
"github.com/IBM/ibm-cos-sdk-go/aws"
6+
"github.com/IBM/ibm-cos-sdk-go/aws/awserr"
7+
"github.com/IBM/ibm-cos-sdk-go/aws/credentials"
8+
"github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam/token"
9+
)
10+
11+
// Provider Struct
12+
type TrustedProfileProvider struct {
13+
// Name of Provider
14+
providerName string
15+
16+
// Type of Provider - SharedCred, SharedConfig, etc.
17+
providerType string
18+
19+
// Authenticator instance, will be assigned dynamically
20+
authenticator core.Authenticator
21+
22+
// Service Instance ID passes in a provider
23+
serviceInstanceID string
24+
25+
// Error
26+
ErrorStatus error
27+
28+
// Logger attributes
29+
logger aws.Logger
30+
logLevel *aws.LogLevelType
31+
}
32+
33+
// NewTrustedProfileProvider allows the creation of a custom IBM IAM Trusted Profile Provider
34+
// Parameters:
35+
//
36+
// Provider Name
37+
// AWS Config
38+
// Trusted Profile ID
39+
// CR token file path
40+
// IBM IAM Authentication Server Endpoint
41+
// Service Instance ID
42+
// Resource type
43+
//
44+
// Returns:
45+
//
46+
// TrustedProfileProvider
47+
func NewTrustedProfileProvider(providerName string, config *aws.Config, authEndPoint string, trustedProfileID string, crTokenFilePath string,
48+
serviceInstanceID string, resourceType string) (provider *TrustedProfileProvider) {
49+
provider = new(TrustedProfileProvider)
50+
51+
provider.providerName = providerName
52+
provider.providerType = "oauth"
53+
54+
logLevel := aws.LogLevel(aws.LogOff)
55+
if config != nil && config.LogLevel != nil && config.Logger != nil {
56+
logLevel = config.LogLevel
57+
provider.logger = config.Logger
58+
}
59+
provider.logLevel = logLevel
60+
61+
if crTokenFilePath == "" {
62+
provider.ErrorStatus = awserr.New("crTokenFilePathNotFound", "CR Token file path not found", nil)
63+
if provider.logLevel.Matches(aws.LogDebug) {
64+
provider.logger.Log(debugLog, "<IBM IAM PROVIDER BUILD>", provider.ErrorStatus)
65+
}
66+
return
67+
}
68+
69+
if trustedProfileID == "" {
70+
provider.ErrorStatus = awserr.New("trustedProfileIDNotFound", "Trusted profile id not found", nil)
71+
if provider.logLevel.Matches(aws.LogDebug) {
72+
provider.logger.Log(debugLog, "<IBM IAM PROVIDER BUILD>", provider.ErrorStatus)
73+
}
74+
return
75+
}
76+
77+
provider.serviceInstanceID = serviceInstanceID
78+
79+
if authEndPoint == "" {
80+
authEndPoint = defaultAuthEndPoint
81+
if provider.logLevel.Matches(aws.LogDebug) {
82+
provider.logger.Log(debugLog, "<IBM IAM PROVIDER BUILD>", "using default auth endpoint", authEndPoint)
83+
}
84+
}
85+
86+
// This authenticator is dynamically initialized based on the resourceType parameter.
87+
// Since only cr-token based resources is supported now, it is initialized directly.
88+
// when other resources are supported, the authenticator should be initialized accordingly.
89+
authenticator, err := core.NewContainerAuthenticatorBuilder().
90+
SetCRTokenFilename(crTokenFilePath).
91+
SetIAMProfileID(trustedProfileID).
92+
SetURL(authEndPoint).
93+
SetDisableSSLVerification(true).
94+
Build()
95+
if err != nil {
96+
provider.ErrorStatus = awserr.New("errCreatingAuthenticatorClient", "cannot setup new Authenticator client", err)
97+
if provider.logLevel.Matches(aws.LogDebug) {
98+
provider.logger.Log(debugLog, "<IBM IAM PROVIDER BUILD>", provider.ErrorStatus)
99+
}
100+
return
101+
}
102+
provider.authenticator = authenticator
103+
104+
return provider
105+
}
106+
107+
// IsValid ...
108+
// Returns:
109+
//
110+
// TrustedProfileProvider validation - boolean
111+
func (p *TrustedProfileProvider) IsValid() bool {
112+
return nil == p.ErrorStatus
113+
}
114+
115+
// Retrieve ...
116+
// Returns:
117+
//
118+
// Credential values
119+
// Error
120+
func (p *TrustedProfileProvider) Retrieve() (credentials.Value, error) {
121+
if p.ErrorStatus != nil {
122+
if p.logLevel.Matches(aws.LogDebug) {
123+
p.logger.Log(debugLog, ibmiamProviderLog, p.providerName, p.ErrorStatus)
124+
}
125+
return credentials.Value{ProviderName: p.providerName}, p.ErrorStatus
126+
}
127+
128+
// The respective resourceTypes's class should be called based on the resourceType parameter.
129+
// Since only cr-token based resources is supported now, it is assigned to ContainerAuthenticator
130+
// directly. when other resource types are supported, the respective class should be used accordingly.
131+
tokenValue, err := p.authenticator.(*core.ContainerAuthenticator).GetToken()
132+
133+
if err != nil {
134+
var returnErr error
135+
if p.logLevel.Matches(aws.LogDebug) {
136+
p.logger.Log(debugLog, ibmiamProviderLog, p.providerName, "ERROR ON GET", err)
137+
}
138+
returnErr = awserr.New("TokenManagerRetrieveError", "error retrieving the token", err)
139+
return credentials.Value{}, returnErr
140+
}
141+
142+
return credentials.Value{
143+
Token: token.Token{
144+
AccessToken: tokenValue,
145+
TokenType: "Bearer",
146+
},
147+
ProviderName: p.providerName,
148+
ProviderType: p.providerType,
149+
ServiceInstanceID: p.serviceInstanceID,
150+
}, nil
151+
}
152+
153+
// IsExpired ...
154+
//
155+
// TrustedProfileProvider expired or not - boolean
156+
func (p *TrustedProfileProvider) IsExpired() bool {
157+
return true
158+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ibmiam
2+
3+
import (
4+
"github.com/IBM/ibm-cos-sdk-go/aws"
5+
"github.com/IBM/ibm-cos-sdk-go/aws/credentials"
6+
)
7+
8+
type ResourceType string
9+
10+
// TrustedProfileProviderName name of the IBM IAM provider that uses IAM trusted-profile
11+
// details passed directly
12+
const (
13+
TrustedProfileProviderName = "TrustedProfileProviderIBM"
14+
ResourceComputeResource ResourceType = "CR"
15+
)
16+
17+
// NewTrustedProfileProviderWithCR constructor of the IBM IAM provider that uses IAM trusted-profile
18+
// details passed
19+
// Returns: New TrustedProfileProvider (AWS type)
20+
func NewTrustedProfileProviderCR(config *aws.Config, authEndPoint string, trustedProfileID string, crTokenFilePath string, serviceInstanceID string) *TrustedProfileProvider {
21+
// Resource type ResourceComputeResource is passed to identify that this is a CR-token based
22+
// resource.
23+
return NewTrustedProfileProvider(TrustedProfileProviderName, config, authEndPoint, trustedProfileID, crTokenFilePath, serviceInstanceID, string(ResourceComputeResource))
24+
}
25+
26+
// NewTrustedProfileCredentials constructor for IBM IAM that uses IAM trusted-profile
27+
// credentials passed
28+
// Returns: credentials.NewCredentials(newTrustedProfileProvider()) (AWS type)
29+
func NewTrustedProfileCredentialsCR(config *aws.Config, authEndPoint string, trustedProfileID string, crTokenFilePath string, serviceInstanceID string) *credentials.Credentials {
30+
return credentials.NewCredentials(NewTrustedProfileProviderCR(config, authEndPoint, trustedProfileID, crTokenFilePath, serviceInstanceID))
31+
}

aws/session/session.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ func mergeConfigSrcs(cfg, userCfg *aws.Config,
553553
// Configure credentials if not already set by the user when creating the
554554
// Session.
555555
if cfg.Credentials == credentials.AnonymousCredentials && userCfg.Credentials == nil {
556-
// IBM COS SDK Code -- START
557556
if iBmIamCreds := getIBMIAMCredentials(userCfg); iBmIamCreds != nil {
558557
cfg.Credentials = iBmIamCreds
559558
} else {
@@ -601,6 +600,10 @@ func getIBMIAMCredentials(config *aws.Config) *credentials.Credentials {
601600
return credentials.NewCredentials(provider)
602601
}
603602

603+
if provider := ibmiam.NewEnvProviderTrustedProfile(config); provider.IsValid() {
604+
return credentials.NewCredentials(provider)
605+
}
606+
604607
if provider := ibmiam.NewSharedCredentialsProvider(config, "", ""); provider.IsValid() {
605608
return credentials.NewCredentials(provider)
606609
}

aws/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ package aws
77
const SDKName = "ibm-cos-sdk-go"
88

99
// SDKVersion is the version of this SDK
10-
const SDKVersion = "1.10.3"
10+
const SDKVersion = "1.11.0"
1111

1212
// IBM COS SDK Code -- END

go.mod

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
module github.com/IBM/ibm-cos-sdk-go
22

33
require (
4+
github.com/IBM/go-sdk-core/v5 v5.17.3
45
github.com/jmespath/go-jmespath v0.4.0
56
github.com/stretchr/testify v1.9.0
6-
golang.org/x/net v0.24.0
7+
golang.org/x/net v0.26.0
78
)
89

910
require (
11+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
1012
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
14+
github.com/go-openapi/errors v0.21.0 // indirect
15+
github.com/go-openapi/strfmt v0.22.1 // indirect
16+
github.com/go-playground/locales v0.14.1 // indirect
17+
github.com/go-playground/universal-translator v0.18.1 // indirect
18+
github.com/go-playground/validator/v10 v10.19.0 // indirect
19+
github.com/google/uuid v1.6.0 // indirect
20+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
21+
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
22+
github.com/leodido/go-urn v1.4.0 // indirect
23+
github.com/mitchellh/mapstructure v1.5.0 // indirect
24+
github.com/oklog/ulid v1.3.1 // indirect
1125
github.com/pmezard/go-difflib v1.0.0 // indirect
12-
golang.org/x/text v0.14.0 // indirect
26+
go.mongodb.org/mongo-driver v1.14.0 // indirect
27+
golang.org/x/crypto v0.24.0 // indirect
28+
golang.org/x/sys v0.21.0 // indirect
29+
golang.org/x/text v0.16.0 // indirect
30+
gopkg.in/yaml.v2 v2.4.0 // indirect
1331
gopkg.in/yaml.v3 v3.0.1 // indirect
1432
)
1533

0 commit comments

Comments
 (0)