Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(deps): upgrade to aws-sdk-go-v2 #529

Merged
merged 6 commits into from
Nov 2, 2023

Conversation

agilgur5
Copy link
Contributor

@agilgur5 agilgur5 commented Oct 20, 2023

Partial fix for argoproj/argo-workflows#12031, Vulnerabilities

  • aws-sdk-go v1 is only used from pkg for Workflows

Motivation

  • aws-sdk-go has a vuln in the v1 EncryptionClient
    • it's fixed in the v2 client
    • we don't use this functionality, but still get reported this vuln
      • instead of adding an ignore for the vuln, figured I might as well make the upgrade to v2

Modifications

  • follow the migration instructions

    • migrate all session usage to config.LoadDefaultConfig per instructions
      • this includes shared config handling, so I believe session.SharedConfigEnable is no longer necessary per instructions
      • see also config.WithRegion mention in the instructions
    • migrate credential usage
      • Config.Credentials still exists, but the function is now Retrieve(context) instead of Get
        • the Credentials struct otherwise looks the same, has the AccessKeyId, SecretAccessKey, and SessionToken that were used in v1
      • STS credentials are retrieved a bit differently now per instructions
        • use a config instead of a session to create a client, then use NewAssumeRoleProvider instead of `NewCredentials
  • NOTE: I used context.Background() for all of the contexts that are now required

Verification

  • confirmed that go.mod has latest versions (e.g. config released v1.19.0 this week)
  • Tested make build and make test pass successfully. Did not test this live however as that needs to be done downstream

- `aws-sdk-go` has [a vuln](https://osv.dev/vulnerability/GO-2022-0646) in the v1 EncryptionClient
  - it's fixed in the v2 client
  - we don't use this functionality, but still get reported this vuln
    - instead add an ignore for the vuln, figured I might as well make the upgrade to v2
- confirmed that `go.mod` has latest versions (e.g. `config` [released v1.19.0](https://github.com/aws/aws-sdk-go-v2/releases/tag/release-2023-10-16) this week)

- follow the [migration instructions](https://aws.github.io/aws-sdk-go-v2/docs/migrating/)
  - migrate all `session` usage to `config.LoadDefaultConfig` per [instructions](https://aws.github.io/aws-sdk-go-v2/docs/migrating/#configuration-loading)
    - this includes shared config handling, so I believe `session.SharedConfigEnable` is no longer necessary per [instructions](https://aws.github.io/aws-sdk-go-v2/docs/migrating/#migrating-from-newsessionwithoptions)
      - the docs on ["Speciyfing Credentials"](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials) seem to state this as well, if I'm understanding correctly
    - see also `config.WithRegion` mention in the [instructions](https://aws.github.io/aws-sdk-go-v2/docs/migrating/#migrating-from-newsession-with-awsconfig-options)
  - migrate credential usage
    - [`Config.Credentials`](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#Config) still exists, but the function is now [`Retrieve(context)`](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#CredentialsProvider) instead of `Get`
      - the [`Credentials` struct](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#Credentials) otherwise looks the same, has the `AccessKeyId`, `SecretAccessKey`, and `SessionToken` that were used in v1
    - STS credentials are retrieved a bit differently now [per instructions](https://aws.github.io/aws-sdk-go-v2/docs/migrating/#aws-security-token-service-credentials)
      - use a `config` instead of a `session` to create a client, then use `NewAssumeRoleProvider` instead of `NewCredentials

- NOTE: I used `context.Background()` for all of the contexts that are now required
  - it may make more sense for context to be passed into these functions, but that would be a breaking change and require downstream changes in Argo projects, so I left that out for now and just went with `Background` as a default

Signed-off-by: Anton Gilgur <[email protected]>
- this was just straight up missing from the migration guide's imports
  - found it myself: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/sts

Signed-off-by: Anton Gilgur <[email protected]>
agilgur5 and others added 2 commits October 29, 2023 21:02
- more idiomatic Go, less memory use, and makes it easier to replace with an argument later

Signed-off-by: Anton Gilgur <[email protected]>
@crenshaw-dev
Copy link
Member

@agilgur5 can you rebase?

@agilgur5
Copy link
Contributor Author

Aw dang, another conflict with dependabot. Fixed conflicts now if we could get this in before the next conflict 😅

@agilgur5
Copy link
Contributor Author

agilgur5 commented Oct 31, 2023

There's an aws-sdk-go bump like every other day apparently; the large majority of PRs in this repo are actually from aws-sdk-go bumps (which, er, seems a tad excessive 🙃)

Copy link

sonarcloud bot commented Nov 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@agilgur5
Copy link
Contributor Author

agilgur5 commented Nov 2, 2023

3rd+ merge conflict fixed now 😕

@terrytangyuan @crenshaw-dev could either of you merge this? it will conflict with dependabot about every other day per above

@terrytangyuan terrytangyuan merged commit 74bde92 into argoproj:master Nov 2, 2023
6 checks passed
@agilgur5 agilgur5 deleted the deps-update-aws-sdk-go-v2 branch November 2, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies PRs and issues specific to updating dependencies go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants