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

harden pull-sandbox-image script #1649

Merged
merged 2 commits into from
Feb 10, 2024
Merged

Conversation

ndbaker1
Copy link
Member

@ndbaker1 ndbaker1 commented Feb 9, 2024

Issue #, if available:

Description of changes:

  • remove the pipefail so that authentication errors don't fast fail the workflow since it is ok if the ecr call fails.
  • add additional bash shell hardening.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Testing Done

an empty credential pull for public repositories:

$ crictl pull --creds "AWS:" registry.k8s.io/pause:3.9
Image is up to date for sha256:e6f1816883972d4be47bd48879a08919b96afcd344132622e4d444987919323c

in the case where a region is malformed or incorrect, this will still succeed for a public image:

$ grep sandbox_image /etc/containerd/config.toml
sandbox_image = "registry.k8s.io/pause:3.9"

$ /etc/eks/containerd/pull-sandbox-image.sh
[root@ip-192-168-5-111 bin]# /etc/eks/containerd/pull-sandbox-image.sh

Provided region_name '9' doesn't match a supported format.
Attempt 1 of 3

Provided region_name '9' doesn't match a supported format.
Attempt 2 of 3

Provided region_name '9' doesn't match a supported format.
Attempt 3 of 3

Provided region_name '9' doesn't match a supported format.
Unable to retrieve the ECR password. Image pull may not be properly authenticated.

Image is up to date for sha256:e6f1816883972d4be47bd48879a08919b96afcd344132622e4d444987919323c

# verify "caching" works
$ /etc/eks/containerd/pull-sandbox-image.sh
Skipping ... sandbox_image 'registry.k8s.io/pause:3.9' is already present

existing ecr uris:

$ grep sandbox_image /etc/containerd/config.toml
sandbox_image = "602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/pause:3.5"

$ /etc/eks/containerd/pull-sandbox-image.sh
Image is up to date for sha256:6996f8da07bd405c6f82a549ef041deda57d1d658ec20a78584f9f436c9a3bb7

$ /etc/eks/containerd/pull-sandbox-image.sh
Skipping ... sandbox_image '602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/pause:3.5' is already present

See this guide for recommended testing for PRs. Some tests may not apply. Completing tests and providing additional validation steps are not required, but it is recommended and may reduce review time and time to merge.

@ndbaker1 ndbaker1 changed the title update method to get region and improve shell substitutions harden pull-sandbox-image script Feb 9, 2024
@ndbaker1
Copy link
Member Author

ndbaker1 commented Feb 9, 2024

built on top of #1648 and #1646
@dims @cartermckinnon can you guys check me that this covers all the bases?

# see: https://github.com/awslabs/amazon-eks-ami/blob/baef6f0860f60dbec366de30853e47418e3fb430/files/bootstrap.sh#L320-L338
# if the image is customer provided, then this is just a sane default for the
# region when attempting to get ecr credentials.
region=$(imds 'latest/dynamic/instance-identity/document' | jq .region -r)
Copy link
Member

Choose a reason for hiding this comment

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

one problem here is ... if the sandbox_image is specified from another region ( different from where the node is running in :( )

Copy link
Member

Choose a reason for hiding this comment

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

could we check if the echo/cut version (from the sandbox_image) is present in aws account list-regions? and skip if not?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh but this would require new permissions on the role 😖

Copy link
Member Author

@ndbaker1 ndbaker1 Feb 9, 2024

Choose a reason for hiding this comment

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

are there docs stating required naming conventions of ecr registries? I'm not 100% sure what i can/can't check for

Copy link
Member Author

Choose a reason for hiding this comment

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

if the sandbox_image is specified from another region

but this is only for user provided images right (based on the assumptions for the eks generated uri), which I'm not sure had a solution even prior to this 🤔

Copy link
Member

Choose a reason for hiding this comment

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

then we can let it slide and leave it to the imds variation. (cross fingers!)

Copy link
Member

@cartermckinnon cartermckinnon Feb 9, 2024

Choose a reason for hiding this comment

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

I'm hesitant to touch this in this PR. Cutting the region out of the image reference has its caveats, for sure; but that logic has been in prod for over a year and it's proven solid. I think we should consider this change in a separate PR, since this one is mostly for mitigation

Copy link
Member Author

@ndbaker1 ndbaker1 Feb 9, 2024

Choose a reason for hiding this comment

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

that logic has been in prod for over a year and it's proven solid.

This logic has existed yes (https://github.com/awslabs/amazon-eks-ami/blame/master/files/pull-image.sh#L4), but its only been used in context where the image source was already known and decided by us right?

The only prior usage i know of is in

if /etc/eks/containerd/pull-image.sh "${img}"; then

Copy link
Member

@cartermckinnon cartermckinnon Feb 9, 2024

Choose a reason for hiding this comment

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

pull-sandbox-image.sh used to call pull-image.sh instead of using crictl: 7fa037a#diff-57a6aadbbb1d3df65f4675ae80c562f7e406bcb11e41f6afb974043a2ede0aa0L11

Copy link
Member Author

Choose a reason for hiding this comment

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

🤦 that escaped my mind (and my github searches)
yea i think pulling it out makes sense then since it won't break the expectation beyond whats already changed in last commit

@cartermckinnon
Copy link
Member

/ci launch

Copy link
Contributor

github-actions bot commented Feb 9, 2024

@cartermckinnon roger that! I've dispatched a workflow. 👍

Copy link
Contributor

github-actions bot commented Feb 9, 2024

@cartermckinnon the workflow that you requested has completed. 🎉

Kubernetes versionBuildLaunchTest
1.23success ✅success ✅skipped ⏭️
1.24success ✅success ✅skipped ⏭️
1.25success ✅success ✅skipped ⏭️
1.26success ✅success ✅skipped ⏭️
1.27success ✅success ✅skipped ⏭️
1.28success ✅success ✅skipped ⏭️
1.29success ✅success ✅skipped ⏭️

@ndbaker1 ndbaker1 merged commit 976fe67 into awslabs:master Feb 10, 2024
2 checks passed
@ndbaker1 ndbaker1 deleted the sandbox-hardening branch February 10, 2024 00:34
atmosx pushed a commit to gathertown/amazon-eks-ami that referenced this pull request Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants