Skip to content

aws auth use default creds when none are supplied#17932

Merged
Vad1mo merged 2 commits intogoharbor:mainfrom
caleblloyd:aws-auth-use-creds-default
Feb 3, 2023
Merged

aws auth use default creds when none are supplied#17932
Vad1mo merged 2 commits intogoharbor:mainfrom
caleblloyd:aws-auth-use-creds-default

Conversation

@caleblloyd
Copy link
Contributor

@caleblloyd caleblloyd commented Dec 6, 2022

Comprehensive Summary of your change

Harbor should not assume that if AWS Credentials are not defined that the user wants to use ec2rolecreds. Rather, it should allow the AWS SDK to resolve credentials by passing nil Credentials:

https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials

This should be backwards compatible because the defualt provider chain does look for: 4. If your application is running on an Amazon EC2 instance, IAM role for Amazon EC2.

Issue being fixed

Fixes #15007

Related to #17962

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

@caleblloyd caleblloyd requested a review from a team as a code owner December 6, 2022 20:52
@Vad1mo Vad1mo added the release-note/enhancement Label to mark PR to be added under release notes as enhancement label Dec 8, 2022
Copy link
Member

@Vad1mo Vad1mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, any idea or guide how to easily test this on AWS?

@caleblloyd
Copy link
Contributor Author

caleblloyd commented Dec 8, 2022

A little tough to unit test because you need actual creds to run through the SDK. But I purpose-built a couple test binaries in branches on my fork. This run demonstrates that Before, the Shared credentials file is not loaded per AWS' default credential chain, but After it is.

I also tested Good/Bad static creds after the change and there are no regressions there.

Before Change:

Test source: https://github.com/caleblloyd/harbor/tree/aws-test-before-change/src/awssecrettest

Auto Detect

$ export AWS_PROFILE=my-profile-name
$ export AWS_SDK_LOAD_CONFIG=true
$ ./run.sh https://123456.dkr.ecr.us-east-2.amazonaws.com
2022-12-08T13:21:24-05:00 [INFO] [/pkg/reg/adapter/native/adapter.go:36]: the factory for adapter docker-registry registered
2022-12-08T13:21:24-05:00 [INFO] [/pkg/reg/adapter/awsecr/adapter.go:44]: the factory for adapter aws-ecr registered
2022-12-08T13:21:30-05:00 [FATAL] [/awssecrettest/awssecrettest.go:38]: EC2RoleRequestError: no EC2 instance role found
caused by: RequestError: send request failed
caused by: Get "http://169.254.169.254/latest/meta-data/iam/security-credentials/": dial tcp 169.254.169.254:80: connect: no route to host

After Change:

Test source: https://github.com/caleblloyd/harbor/tree/aws-test-after-change/src/awssecrettest

Auto Detect

$ export AWS_PROFILE=my-profile-name
$ export AWS_SDK_LOAD_CONFIG=true
$ ./run.sh https://123456.dkr.ecr.us-east-2.amazonaws.com
2022-12-08T13:18:08-05:00 [INFO] [/pkg/reg/adapter/native/adapter.go:36]: the factory for adapter docker-registry registered
2022-12-08T13:18:08-05:00 [INFO] [/pkg/reg/adapter/awsecr/adapter.go:44]: the factory for adapter aws-ecr registered
<valid token>

With Bad Static Token:

$ ./run.sh https://123456.dkr.ecr.us-east-2.amazonaws.com "bad" "bad"
2022-12-08T13:32:40-05:00 [INFO] [/pkg/reg/adapter/native/adapter.go:36]: the factory for adapter docker-registry registered
2022-12-08T13:32:40-05:00 [INFO] [/pkg/reg/adapter/awsecr/adapter.go:44]: the factory for adapter aws-ecr registered
2022-12-08T13:32:41-05:00 [FATAL] [/awssecrettest/awssecrettest.go:38]: UnrecognizedClientException: The security token included in the request is invalid.
        status code: 400, request id: 7c3a3f19-95c8-4cdd-9b39-a1cb07edab2b
exit status 1

With Good Static Token:

$ ./run.sh https://123456.dkr.ecr.us-east-2.amazonaws.com "xxxxxx" "xxxxxx"
2022-12-08T13:35:15-05:00 [INFO] [/pkg/reg/adapter/native/adapter.go:36]: the factory for adapter docker-registry registered
2022-12-08T13:35:15-05:00 [INFO] [/pkg/reg/adapter/awsecr/adapter.go:44]: the factory for adapter aws-ecr registered
<valid token>

@caleblloyd
Copy link
Contributor Author

After Change - EC2 Instance Metadata Allows getting token:

image

After Change - EC2 Instance Metadata Does Not Allow getting token:

image

Copy link
Contributor

@stonezdj stonezdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@stonezdj stonezdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slacki123
Copy link

Hey @Vad1mo, are you the other reviewer on this PR? We're really excited to get this released

@slacki123
Copy link

Hi @caleblloyd @Vad1mo, what is the status on this PR?

@OrlinVasilev OrlinVasilev marked this pull request as draft January 26, 2023 11:11
@OrlinVasilev OrlinVasilev marked this pull request as ready for review January 26, 2023 11:12
@OrlinVasilev
Copy link
Member

Will close and re-open the PR so we can try to unblock GH actions!

@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #17932 (95350b3) into main (bfe4362) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17932      +/-   ##
==========================================
- Coverage   66.41%   66.41%   -0.01%     
==========================================
  Files        1012     1012              
  Lines      108684   108682       -2     
  Branches     2676     2676              
==========================================
- Hits        72186    72184       -2     
+ Misses      32534    32531       -3     
- Partials     3964     3967       +3     
Flag Coverage Δ
unittests 66.41% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pkg/reg/adapter/awsecr/auth.go 71.00% <ø> (-0.57%) ⬇️
...es/vulnerability/vulnerability-config.component.ts 58.51% <0.00%> (-4.45%) ⬇️
...ortal/src/app/shared/pipes/harbor-datetime.pipe.ts 32.00% <0.00%> (-4.00%) ⬇️
src/jobservice/sync/schedule.go 54.54% <0.00%> (-2.38%) ⬇️
src/server/v2.0/handler/user.go 13.43% <0.00%> (+1.55%) ⬆️
src/common/utils/passports.go 90.19% <0.00%> (+3.92%) ⬆️
...-job/gc-page/gc/gc-history/gc-history.component.ts 46.51% <0.00%> (+5.81%) ⬆️

@Vad1mo
Copy link
Member

Vad1mo commented Jan 26, 2023

@caleblloyd, seems the test fail, can you rebase and we try again. We merge if it becomes green.

@caleblloyd
Copy link
Contributor Author

Yes I will rebase, I also had a change in here to upgrade aws-sdk-go, but now I am seeing this in CONTRIBUTING.md:

The official maintainers will take the responsibility for managing the code in vendor directory.

So I will remove the go.mod change also and open another issue for that

@caleblloyd
Copy link
Contributor Author

Opened #18134 requesting the dependency update

@slacki123
Copy link

@caleblloyd looks like test coverage decreased by 0.01% and failed the checks. Can we do anything about it?

Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
@caleblloyd
Copy link
Contributor Author

All the checks were green, but it was complaining that the commit was not signed, so I have re-pushed the same code except with a signed commit now. I think the workflows may need to be manually approved again because I am a first-time contributor?

@Vad1mo Vad1mo merged commit 901cc17 into goharbor:main Feb 3, 2023
tpoxa pushed a commit to container-registry/temp_harbor-next that referenced this pull request Feb 8, 2023
Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
Co-authored-by: Vadim Bauer <vb@container-registry.com>
Signed-off-by: Maksym <maksym@container-registry.com>
mcsage pushed a commit to mcsage/harbor that referenced this pull request Feb 16, 2023
Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
Co-authored-by: Vadim Bauer <vb@container-registry.com>
Signed-off-by: Stephan Hohn <stephan.hohn@tech11.com>
sebglon pushed a commit to sebglon/harbor that referenced this pull request Mar 6, 2023
Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
Co-authored-by: Vadim Bauer <vb@container-registry.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/enhancement Label to mark PR to be added under release notes as enhancement target/2.8.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to create replication for ECR on harbor running under kubernetes

10 participants