s3storage.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. package storage
  2. // Fork from Thanos S3 Bucket support to reuse configuration options
  3. // Licensed under the Apache License 2.0
  4. // https://github.com/thanos-io/thanos/blob/main/pkg/objstore/s3/s3.go
  5. import (
  6. "bytes"
  7. "context"
  8. "io"
  9. "net"
  10. "net/http"
  11. "os"
  12. "strings"
  13. "time"
  14. "github.com/opencost/opencost/core/pkg/log"
  15. "github.com/aws/aws-sdk-go-v2/aws"
  16. awsconfig "github.com/aws/aws-sdk-go-v2/config"
  17. "github.com/minio/minio-go/v7"
  18. "github.com/minio/minio-go/v7/pkg/credentials"
  19. "github.com/minio/minio-go/v7/pkg/encrypt"
  20. "github.com/pkg/errors"
  21. "gopkg.in/yaml.v2"
  22. )
  23. type ctxKey int
  24. const (
  25. // SSEKMS is the name of the SSE-KMS method for objectstore encryption.
  26. SSEKMS = "SSE-KMS"
  27. // SSEC is the name of the SSE-C method for objstore encryption.
  28. SSEC = "SSE-C"
  29. // SSES3 is the name of the SSE-S3 method for objstore encryption.
  30. SSES3 = "SSE-S3"
  31. // sseConfigKey is the context key to override SSE config. This feature is used by downstream
  32. // projects (eg. Cortex) to inject custom SSE config on a per-request basis. Future work or
  33. // refactoring can introduce breaking changes as far as the functionality is preserved.
  34. // NOTE: we're using a context value only because it's a very specific S3 option. If SSE will
  35. // be available to wider set of backends we should probably add a variadic option to Get() and Upload().
  36. sseConfigKey = ctxKey(0)
  37. )
  38. var defaultS3Config = S3Config{
  39. PutUserMetadata: map[string]string{},
  40. HTTPConfig: S3HTTPConfig{
  41. IdleConnTimeout: time.Duration(90 * time.Second),
  42. ResponseHeaderTimeout: time.Duration(2 * time.Minute),
  43. TLSHandshakeTimeout: time.Duration(10 * time.Second),
  44. ExpectContinueTimeout: time.Duration(1 * time.Second),
  45. MaxIdleConns: 100,
  46. MaxIdleConnsPerHost: 100,
  47. MaxConnsPerHost: 0,
  48. },
  49. PartSize: 1024 * 1024 * 64, // 64MB.
  50. }
  51. // Config stores the configuration for s3 bucket.
  52. type S3Config struct {
  53. Bucket string `yaml:"bucket"`
  54. Endpoint string `yaml:"endpoint"`
  55. Region string `yaml:"region"`
  56. AWSSDKAuth bool `yaml:"aws_sdk_auth"`
  57. AccessKey string `yaml:"access_key"`
  58. Insecure bool `yaml:"insecure"`
  59. SignatureV2 bool `yaml:"signature_version2"`
  60. SecretKey string `yaml:"secret_key"`
  61. PutUserMetadata map[string]string `yaml:"put_user_metadata"`
  62. HTTPConfig S3HTTPConfig `yaml:"http_config"`
  63. TraceConfig TraceConfig `yaml:"trace"`
  64. ListObjectsVersion string `yaml:"list_objects_version"`
  65. // PartSize used for multipart upload. Only used if uploaded object size is known and larger than configured PartSize.
  66. // NOTE we need to make sure this number does not produce more parts than 10 000.
  67. PartSize uint64 `yaml:"part_size"`
  68. SSEConfig SSEConfig `yaml:"sse_config"`
  69. STSEndpoint string `yaml:"sts_endpoint"`
  70. }
  71. // SSEConfig deals with the configuration of SSE for Minio. The following options are valid:
  72. // kmsencryptioncontext == https://docs.aws.amazon.com/kms/latest/developerguide/services-s3.html#s3-encryption-context
  73. type SSEConfig struct {
  74. Type string `yaml:"type"`
  75. KMSKeyID string `yaml:"kms_key_id"`
  76. KMSEncryptionContext map[string]string `yaml:"kms_encryption_context"`
  77. EncryptionKey string `yaml:"encryption_key"`
  78. }
  79. type TraceConfig struct {
  80. Enable bool `yaml:"enable"`
  81. }
  82. // HTTPConfig stores the http.Transport configuration for the s3 minio client.
  83. type S3HTTPConfig struct {
  84. IdleConnTimeout time.Duration `yaml:"idle_conn_timeout"`
  85. ResponseHeaderTimeout time.Duration `yaml:"response_header_timeout"`
  86. InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
  87. TLSHandshakeTimeout time.Duration `yaml:"tls_handshake_timeout"`
  88. ExpectContinueTimeout time.Duration `yaml:"expect_continue_timeout"`
  89. MaxIdleConns int `yaml:"max_idle_conns"`
  90. MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"`
  91. MaxConnsPerHost int `yaml:"max_conns_per_host"`
  92. // Allow upstream callers to inject a round tripper
  93. Transport http.RoundTripper `yaml:"-"`
  94. TLSConfig TLSConfig `yaml:"tls_config"`
  95. }
  96. // DefaultTransport - this default transport is based on the Minio
  97. // DefaultTransport up until the following commit:
  98. // https://githus3.com/minio/minio-go/commit/008c7aa71fc17e11bf980c209a4f8c4d687fc884
  99. // The values have since diverged.
  100. func DefaultS3Transport(config S3Config) (*http.Transport, error) {
  101. tlsConfig, err := NewTLSConfig(&config.HTTPConfig.TLSConfig)
  102. if err != nil {
  103. return nil, err
  104. }
  105. if config.HTTPConfig.InsecureSkipVerify {
  106. tlsConfig.InsecureSkipVerify = true
  107. }
  108. return &http.Transport{
  109. Proxy: http.ProxyFromEnvironment,
  110. DialContext: (&net.Dialer{
  111. Timeout: 30 * time.Second,
  112. KeepAlive: 30 * time.Second,
  113. DualStack: true,
  114. }).DialContext,
  115. MaxIdleConns: config.HTTPConfig.MaxIdleConns,
  116. MaxIdleConnsPerHost: config.HTTPConfig.MaxIdleConnsPerHost,
  117. IdleConnTimeout: time.Duration(config.HTTPConfig.IdleConnTimeout),
  118. MaxConnsPerHost: config.HTTPConfig.MaxConnsPerHost,
  119. TLSHandshakeTimeout: time.Duration(config.HTTPConfig.TLSHandshakeTimeout),
  120. ExpectContinueTimeout: time.Duration(config.HTTPConfig.ExpectContinueTimeout),
  121. // A custom ResponseHeaderTimeout was introduced
  122. // to cover cases where the tcp connection works but
  123. // the server never answers. Defaults to 2 minutes.
  124. ResponseHeaderTimeout: time.Duration(config.HTTPConfig.ResponseHeaderTimeout),
  125. // Set this value so that the underlying transport round-tripper
  126. // doesn't try to auto decode the body of objects with
  127. // content-encoding set to `gzip`.
  128. //
  129. // Refer: https://golang.org/src/net/http/transport.go?h=roundTrip#L1843.
  130. DisableCompression: true,
  131. // #nosec It's up to the user to decide on TLS configs
  132. TLSClientConfig: tlsConfig,
  133. }, nil
  134. }
  135. // S3Storage provides storage via S3
  136. type S3Storage struct {
  137. name string
  138. client *minio.Client
  139. defaultSSE encrypt.ServerSide
  140. putUserMetadata map[string]string
  141. partSize uint64
  142. listObjectsV1 bool
  143. }
  144. // parseConfig unmarshals a buffer into a Config with default HTTPConfig values.
  145. func parseS3Config(conf []byte) (S3Config, error) {
  146. config := defaultS3Config
  147. if err := yaml.Unmarshal(conf, &config); err != nil {
  148. return S3Config{}, err
  149. }
  150. return config, nil
  151. }
  152. // NewBucket returns a new Bucket using the provided s3 config values.
  153. func NewS3Storage(conf []byte) (*S3Storage, error) {
  154. config, err := parseS3Config(conf)
  155. if err != nil {
  156. return nil, err
  157. }
  158. return NewS3StorageWith(config)
  159. }
  160. // NewBucketWithConfig returns a new Bucket using the provided s3 config values.
  161. func NewS3StorageWith(config S3Config) (*S3Storage, error) {
  162. var chain []credentials.Provider
  163. wrapCredentialsProvider := func(p credentials.Provider) credentials.Provider { return p }
  164. if config.SignatureV2 {
  165. wrapCredentialsProvider = func(p credentials.Provider) credentials.Provider {
  166. return &overrideSignerType{Provider: p, signerType: credentials.SignatureV2}
  167. }
  168. }
  169. if err := validate(config); err != nil {
  170. return nil, err
  171. }
  172. if config.AWSSDKAuth {
  173. chain = []credentials.Provider{
  174. wrapCredentialsProvider(&awsAuth{Region: config.Region}),
  175. }
  176. } else if config.AccessKey != "" {
  177. chain = []credentials.Provider{wrapCredentialsProvider(&credentials.Static{
  178. Value: credentials.Value{
  179. AccessKeyID: config.AccessKey,
  180. SecretAccessKey: config.SecretKey,
  181. SignerType: credentials.SignatureV4,
  182. },
  183. })}
  184. } else {
  185. chain = []credentials.Provider{
  186. wrapCredentialsProvider(&credentials.EnvAWS{}),
  187. wrapCredentialsProvider(&credentials.FileAWSCredentials{}),
  188. wrapCredentialsProvider(&credentials.IAM{
  189. Client: &http.Client{
  190. Transport: http.DefaultTransport,
  191. },
  192. Endpoint: config.STSEndpoint,
  193. }),
  194. }
  195. }
  196. // Check if a roundtripper has been set in the config
  197. // otherwise build the default transport.
  198. var rt http.RoundTripper
  199. if config.HTTPConfig.Transport != nil {
  200. rt = config.HTTPConfig.Transport
  201. } else {
  202. var err error
  203. rt, err = DefaultS3Transport(config)
  204. if err != nil {
  205. return nil, err
  206. }
  207. }
  208. client, err := minio.New(config.Endpoint, &minio.Options{
  209. Creds: credentials.NewChainCredentials(chain),
  210. Secure: !config.Insecure,
  211. Region: config.Region,
  212. Transport: rt,
  213. })
  214. if err != nil {
  215. return nil, errors.Wrap(err, "initialize s3 client")
  216. }
  217. var sse encrypt.ServerSide
  218. if config.SSEConfig.Type != "" {
  219. switch config.SSEConfig.Type {
  220. case SSEKMS:
  221. // If the KMSEncryptionContext is a nil map the header that is
  222. // constructed by the encrypt.ServerSide object will be base64
  223. // encoded "nil" which is not accepted by AWS.
  224. if config.SSEConfig.KMSEncryptionContext == nil {
  225. config.SSEConfig.KMSEncryptionContext = make(map[string]string)
  226. }
  227. sse, err = encrypt.NewSSEKMS(config.SSEConfig.KMSKeyID, config.SSEConfig.KMSEncryptionContext)
  228. if err != nil {
  229. return nil, errors.Wrap(err, "initialize s3 client SSE-KMS")
  230. }
  231. case SSEC:
  232. key, err := os.ReadFile(config.SSEConfig.EncryptionKey)
  233. if err != nil {
  234. return nil, err
  235. }
  236. sse, err = encrypt.NewSSEC(key)
  237. if err != nil {
  238. return nil, errors.Wrap(err, "initialize s3 client SSE-C")
  239. }
  240. case SSES3:
  241. sse = encrypt.NewSSE()
  242. default:
  243. sseErrMsg := errors.Errorf("Unsupported type %q was provided. Supported types are SSE-S3, SSE-KMS, SSE-C", config.SSEConfig.Type)
  244. return nil, errors.Wrap(sseErrMsg, "Initialize s3 client SSE Config")
  245. }
  246. }
  247. if config.ListObjectsVersion != "" && config.ListObjectsVersion != "v1" && config.ListObjectsVersion != "v2" {
  248. return nil, errors.Errorf("Initialize s3 client list objects version: Unsupported version %q was provided. Supported values are v1, v2", config.ListObjectsVersion)
  249. }
  250. bkt := &S3Storage{
  251. name: config.Bucket,
  252. client: client,
  253. defaultSSE: sse,
  254. putUserMetadata: config.PutUserMetadata,
  255. partSize: config.PartSize,
  256. listObjectsV1: config.ListObjectsVersion == "v1",
  257. }
  258. return bkt, nil
  259. }
  260. // Name returns the bucket name for s3.
  261. func (s3 *S3Storage) Name() string {
  262. return s3.name
  263. }
  264. // StorageType returns a string identifier for the type of storage used by the implementation.
  265. func (s3 *S3Storage) StorageType() StorageType {
  266. return StorageTypeBucketS3
  267. }
  268. // validate checks to see the config options are set.
  269. func validate(conf S3Config) error {
  270. if conf.Endpoint == "" {
  271. return errors.New("no s3 endpoint in config file")
  272. }
  273. if conf.AWSSDKAuth && conf.AccessKey != "" {
  274. return errors.New("aws_sdk_auth and access_key are mutually exclusive configurations")
  275. }
  276. if conf.AccessKey == "" && conf.SecretKey != "" {
  277. return errors.New("no s3 acccess_key specified while secret_key is present in config file; either both should be present in config or envvars/IAM should be used.")
  278. }
  279. if conf.AccessKey != "" && conf.SecretKey == "" {
  280. return errors.New("no s3 secret_key specified while access_key is present in config file; either both should be present in config or envvars/IAM should be used.")
  281. }
  282. if conf.SSEConfig.Type == SSEC && conf.SSEConfig.EncryptionKey == "" {
  283. return errors.New("encryption_key must be set if sse_config.type is set to 'SSE-C'")
  284. }
  285. if conf.SSEConfig.Type == SSEKMS && conf.SSEConfig.KMSKeyID == "" {
  286. return errors.New("kms_key_id must be set if sse_config.type is set to 'SSE-KMS'")
  287. }
  288. return nil
  289. }
  290. // FullPath returns the storage working path combined with the path provided
  291. func (s3 *S3Storage) FullPath(name string) string {
  292. name = trimLeading(name)
  293. return name
  294. }
  295. // Get returns a reader for the given object name.
  296. func (s3 *S3Storage) Read(name string) ([]byte, error) {
  297. name = trimLeading(name)
  298. log.Debugf("S3Storage::Read(%s)", name)
  299. ctx := context.Background()
  300. return s3.getRange(ctx, name, 0, -1)
  301. }
  302. // Exists checks if the given object exists.
  303. func (s3 *S3Storage) Exists(name string) (bool, error) {
  304. name = trimLeading(name)
  305. //log.Debugf("S3Storage::Exists(%s)", name)
  306. ctx := context.Background()
  307. _, err := s3.client.StatObject(ctx, s3.name, name, minio.StatObjectOptions{})
  308. if err != nil {
  309. if s3.isDoesNotExist(err) {
  310. return false, nil
  311. }
  312. return false, errors.Wrap(err, "stat s3 object")
  313. }
  314. return true, nil
  315. }
  316. // Upload the contents of the reader as an object into the bucket.
  317. func (s3 *S3Storage) Write(name string, data []byte) error {
  318. name = trimLeading(name)
  319. log.Debugf("S3Storage::Write(%s)", name)
  320. ctx := context.Background()
  321. sse, err := s3.getServerSideEncryption(ctx)
  322. if err != nil {
  323. return err
  324. }
  325. var size int64 = int64(len(data))
  326. // Set partSize to 0 to write files in one go. This prevents chunking of
  327. // upload into multiple parts, which requires additional memory for buffering
  328. // the sub-parts. To remain consistent with other storage implementations,
  329. // we would rather attempt to lower cost fast upload and fast-fail.
  330. var partSize uint64 = 0
  331. r := bytes.NewReader(data)
  332. _, err = s3.client.PutObject(ctx, s3.name, name, r, int64(size), minio.PutObjectOptions{
  333. PartSize: partSize,
  334. ServerSideEncryption: sse,
  335. UserMetadata: s3.putUserMetadata,
  336. })
  337. if err != nil {
  338. return errors.Wrap(err, "upload s3 object")
  339. }
  340. return nil
  341. }
  342. // Attributes returns information about the specified object.
  343. func (s3 *S3Storage) Stat(name string) (*StorageInfo, error) {
  344. name = trimLeading(name)
  345. //log.Debugf("S3Storage::Stat(%s)", name)
  346. ctx := context.Background()
  347. objInfo, err := s3.client.StatObject(ctx, s3.name, name, minio.StatObjectOptions{})
  348. if err != nil {
  349. if s3.isDoesNotExist(err) {
  350. return nil, DoesNotExistError
  351. }
  352. return nil, err
  353. }
  354. return &StorageInfo{
  355. Name: trimName(name),
  356. Size: objInfo.Size,
  357. ModTime: objInfo.LastModified,
  358. }, nil
  359. }
  360. // Delete removes the object with the given name.
  361. func (s3 *S3Storage) Remove(name string) error {
  362. name = trimLeading(name)
  363. log.Debugf("S3Storage::Remove(%s)", name)
  364. ctx := context.Background()
  365. return s3.client.RemoveObject(ctx, s3.name, name, minio.RemoveObjectOptions{})
  366. }
  367. func (s3 *S3Storage) List(path string) ([]*StorageInfo, error) {
  368. path = trimLeading(path)
  369. log.Debugf("S3Storage::List(%s)", path)
  370. ctx := context.Background()
  371. // Ensure the object name actually ends with a dir suffix. Otherwise we'll just iterate the
  372. // object itself as one prefix item.
  373. if path != "" {
  374. path = strings.TrimSuffix(path, DirDelim) + DirDelim
  375. }
  376. opts := minio.ListObjectsOptions{
  377. Prefix: path,
  378. Recursive: false,
  379. UseV1: s3.listObjectsV1,
  380. }
  381. var stats []*StorageInfo
  382. for object := range s3.client.ListObjects(ctx, s3.name, opts) {
  383. // Catch the error when failed to list objects.
  384. if object.Err != nil {
  385. return nil, object.Err
  386. }
  387. // The s3 client can also return the directory itself in the ListObjects call above.
  388. if object.Key == path {
  389. continue
  390. }
  391. name := trimName(object.Key)
  392. // This sometimes happens with empty buckets.
  393. if name == "" {
  394. continue
  395. }
  396. stats = append(stats, &StorageInfo{
  397. Name: name,
  398. Size: object.Size,
  399. ModTime: object.LastModified,
  400. })
  401. }
  402. return stats, nil
  403. }
  404. func (s3 *S3Storage) ListDirectories(path string) ([]*StorageInfo, error) {
  405. path = trimLeading(path)
  406. log.Debugf("S3Storage::List(%s)", path)
  407. ctx := context.Background()
  408. if path != "" {
  409. path = strings.TrimSuffix(path, DirDelim) + DirDelim
  410. }
  411. opts := minio.ListObjectsOptions{
  412. Prefix: path,
  413. Recursive: false,
  414. UseV1: s3.listObjectsV1,
  415. }
  416. var stats []*StorageInfo
  417. for object := range s3.client.ListObjects(ctx, s3.name, opts) {
  418. if object.Err != nil {
  419. return nil, object.Err
  420. }
  421. if object.Key == "" {
  422. continue
  423. }
  424. if object.Key == path {
  425. continue
  426. }
  427. // If trim removes the entire name, it's a directory, ergo we list it
  428. if trimName(object.Key) == "" {
  429. stats = append(stats, &StorageInfo{
  430. Name: object.Key,
  431. Size: object.Size,
  432. ModTime: object.LastModified,
  433. })
  434. }
  435. }
  436. return stats, nil
  437. }
  438. // getServerSideEncryption returns the SSE to use.
  439. func (s3 *S3Storage) getServerSideEncryption(ctx context.Context) (encrypt.ServerSide, error) {
  440. if value := ctx.Value(sseConfigKey); value != nil {
  441. if sse, ok := value.(encrypt.ServerSide); ok {
  442. return sse, nil
  443. }
  444. return nil, errors.New("invalid SSE config override provided in the context")
  445. }
  446. return s3.defaultSSE, nil
  447. }
  448. // isDoesNotExist returns true if error means that object key is not found.
  449. func (s3 *S3Storage) isDoesNotExist(err error) bool {
  450. return minio.ToErrorResponse(errors.Cause(err)).Code == "NoSuchKey"
  451. }
  452. // isObjNotFound returns true if the error means that the object was not found
  453. func (s3 *S3Storage) isObjNotFound(err error) bool {
  454. return minio.ToErrorResponse(errors.Cause(err)).Code == "NotFoundObject"
  455. }
  456. func (s3 *S3Storage) getRange(ctx context.Context, name string, off, length int64) ([]byte, error) {
  457. sse, err := s3.getServerSideEncryption(ctx)
  458. if err != nil {
  459. return nil, err
  460. }
  461. opts := &minio.GetObjectOptions{ServerSideEncryption: sse}
  462. if length != -1 {
  463. if err := opts.SetRange(off, off+length-1); err != nil {
  464. return nil, err
  465. }
  466. } else if off > 0 {
  467. if err := opts.SetRange(off, 0); err != nil {
  468. return nil, err
  469. }
  470. }
  471. r, err := s3.client.GetObject(ctx, s3.name, name, *opts)
  472. if err != nil {
  473. if s3.isObjNotFound(err) {
  474. return nil, DoesNotExistError
  475. }
  476. return nil, err
  477. }
  478. defer r.Close()
  479. // NotFoundObject error is revealed only after first Read. This does the initial GetRequest. Prefetch this here
  480. // for convenience.
  481. if _, err := r.Read(nil); err != nil {
  482. if s3.isObjNotFound(err) {
  483. return nil, DoesNotExistError
  484. }
  485. return nil, errors.Wrap(err, "Read from S3 failed")
  486. }
  487. return io.ReadAll(r)
  488. }
  489. // awsAuth retrieves credentials from the aws-sdk-go.
  490. type awsAuth struct {
  491. Region string
  492. creds aws.Credentials
  493. }
  494. // Retrieve retrieves the keys from the environment.
  495. func (a *awsAuth) Retrieve() (credentials.Value, error) {
  496. cfg, err := awsconfig.LoadDefaultConfig(context.TODO(), awsconfig.WithRegion(a.Region))
  497. if err != nil {
  498. return credentials.Value{}, errors.Wrap(err, "load AWS SDK config")
  499. }
  500. creds, err := cfg.Credentials.Retrieve(context.TODO())
  501. if err != nil {
  502. return credentials.Value{}, errors.Wrap(err, "retrieve AWS SDK credentials")
  503. }
  504. a.creds = creds
  505. return credentials.Value{
  506. AccessKeyID: creds.AccessKeyID,
  507. SecretAccessKey: creds.SecretAccessKey,
  508. SessionToken: creds.SessionToken,
  509. SignerType: credentials.SignatureV4,
  510. }, nil
  511. }
  512. // IsExpired returns if the credentials have been retrieved.
  513. func (a *awsAuth) IsExpired() bool {
  514. return a.creds.Expired()
  515. }
  516. type overrideSignerType struct {
  517. credentials.Provider
  518. signerType credentials.SignatureType
  519. }
  520. func (s *overrideSignerType) Retrieve() (credentials.Value, error) {
  521. v, err := s.Provider.Retrieve()
  522. if err != nil {
  523. return v, err
  524. }
  525. if !v.SignerType.IsAnonymous() {
  526. v.SignerType = s.signerType
  527. }
  528. return v, nil
  529. }