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

Use podTemplate ImagePullSecrets for Entrypoint Image Lookup #4496

Merged
merged 1 commit into from
Feb 11, 2022

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Jan 19, 2022

Changes

This PR aims at closing the #3799.
Prior to this commit, we don't use imagePullSecrets from podTemplate to fetch secrets and resolve entrypoints for images. This commit aims at passing the imagePullSecrets to k8schain so it can append the imagePullSecrets into key chain.

This PR also adds unit test for EntrypointCache.get() implementation and improves the test coverage from 0% to 58%.

Note that the controller's service account has the access to secrets. If it is deprecated or the access is removed, the Rolebinding is required for users to avoid errors when calling k8schain. See comments in #3799.

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in or deleted (only if no user facing changes)

Release Notes

This PR is fixing an issue where entrypoint image lookup did not have access to or ignored the secrets specified in the podTemplate. 

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jan 19, 2022
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 19, 2022
@Yongxuanzhang

This comment has been minimized.

1 similar comment
@Yongxuanzhang
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

@Yongxuanzhang Yongxuanzhang marked this pull request as ready for review January 25, 2022 02:05
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 25, 2022
@wlynch
Copy link
Member

wlynch commented Jan 25, 2022

/assign @wlynch

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

Impl looks reasonable - though there aren't really tests for the remote behavior. :(

The kubeclient should be easy enough to fake out (https://pkg.go.dev/k8s.io/client-go/kubernetes/fake), but I'm not sure off the top of my head how we would fake out the remote containerregistry call.

ref, err := test.CreateImageWithAnnotations(fmt.Sprintf("%s/testociresolve/%s", u.Host, tc.name), tc.mapper, tc.objs...)
if err != nil {
t.Fatalf("could not push image: %#v", err)
}
resolver := oci.NewResolver(ref, authn.DefaultKeychain)
something we can copy for this?

/cc @imjasonh In case you have any other ideas.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 27, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 54.5% 54.5

Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

Looks good, and thanks for adding tests! Just a few small comments, otherwise lgtm.

docs/podtemplates.md Outdated Show resolved Hide resolved
@@ -95,6 +95,40 @@ Pod templates support fields listed in the table below.
</tbody>
</table>

## Use <code>imagePullSecrets</code> to lookup entrypoint

If no command is configured in <code>task</code> and <code>imagePullSecrets</code> is configured in <code>podTemplate</code>, the Tekton Controller will look up the entrypoint of image with <code>imagePullSecrets</code>. If the Tekton controller's service account is not granted the access to secrets in different namespace. You need to grant the access via RoleBinding:
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary, since the SA already has cluster-wide read access to secrets?

If this is meant to document what's necessary for folks that explicitly disable Tekton's cluster-wide secrets access, I think we can just assume that users sophisticated/paranoid enough to do that are able to figure out what else they'd need to do to re-enable it for required secrets.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in case the access may be removed in the future, Billy told me that it might be removed so it would be better to document it.

pkg/pod/entrypoint_lookup_impl_test.go Show resolved Hide resolved
fakeclient "k8s.io/client-go/kubernetes/fake"
)

func TestGet(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm always glad to have more tests, and this should ensure the code is at least exercised, but it doesn't currently really ensure that the specified imagePullSecret is used when making requests to the registry. I think it's worth keeping, but maybe we should document its limitations so we don't get a false sense of security here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have been working on trying to address. Please let me know if the latest change makes sense or not. 😄
Thanks!

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 54.5% 54.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 54.5% 54.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 54.5% 54.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 54.5% 54.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 54.5% 54.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 56.4% 56.4

@Yongxuanzhang Yongxuanzhang requested a review from wlynch February 1, 2022 16:38
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
username: "",
password: "",
},
} {
Copy link
Member

Choose a reason for hiding this comment

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

Might also be worth testing a secret that exists but isn't authorized, no secret (in case empty string is different than nil), and a secret that does exist at all.

pkg/pod/entrypoint_lookup_impl_test.go Outdated Show resolved Hide resolved
pkg/pod/entrypoint_lookup_impl_test.go Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 56.4% 56.4

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 56.4% 56.4

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 56.4% 56.4

@Yongxuanzhang
Copy link
Member Author

/test pull-tekton-pipeline-alpha-integration-tests

Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

This change looks great! Thanks for working on this. 👍

docs/podtemplates.md Outdated Show resolved Hide resolved
docs/podtemplates.md Outdated Show resolved Hide resolved
basicSecret: generateSecret(u.Host, username, password),
imagePullSecrets: []corev1.LocalObjectReference{},
wantErr: true,
}} {
Copy link
Member

Choose a reason for hiding this comment

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

The secret is created from .docker/config.json, the file is written only when user has successfully login.

FWIW, this isn't technically true. You can edit that file to contain any username/password, and many tools implement "login" simply be editing that file without validating that the username/password is correct at all.

If there are improvements we can make to that keychain, especially if it helps Tekton users, we should consider them. I'll happily approve :)

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 58.2% 58.2

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 58.2% 58.2

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

/lgtm

🎉

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2022
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/entrypoint_lookup_impl.go 0.0% 58.2% 58.2

@Yongxuanzhang Yongxuanzhang requested a review from wlynch February 4, 2022 20:48
@Yongxuanzhang
Copy link
Member Author

/lgtm

🎉

Sorry the squash cleared the review, may you review it again. 😄

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 7, 2022
@Yongxuanzhang
Copy link
Member Author

/assign @bobcatfish

@imjasonh
Copy link
Member

imjasonh commented Feb 8, 2022

/lgtm

@pritidesai
Copy link
Member

hey @imjasonh will you be able to approve it, @wlynch has lgtmed this 🙏

@pritidesai
Copy link
Member

Please kindly let me know if I need to add any release note.

@Yongxuanzhang please add the release notes. This PR is fixing an issue where entrypoint image lookup did not have access to or ignored the secrets specified in the podTemplate. The users can opt in by creating appropriate role binding to allow image lookup using these secrets.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesnt merit a release note. labels Feb 11, 2022
@Yongxuanzhang
Copy link
Member Author

Yongxuanzhang commented Feb 11, 2022

Please kindly let me know if I need to add any release note.

@Yongxuanzhang please add the release notes. This PR is fixing an issue where entrypoint image lookup did not have access to or ignored the secrets specified in the podTemplate. The users can opt in by creating appropriate role binding to allow image lookup using these secrets.

Hi, @pritidesai Thank you for reminding me of the release note!

@imjasonh
Copy link
Member

Thanks!

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: imjasonh, wlynch

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 11, 2022
@tekton-robot tekton-robot merged commit c6bdf38 into tektoncd:main Feb 11, 2022
@Yongxuanzhang
Copy link
Member Author

Fixes #3799

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants