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

fix(credential-provider): check acr pattern to avoid spoofing #8255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mainred
Copy link
Contributor

@mainred mainred commented Feb 8, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

There's a potential spoofing when the image
".azurecr.io.example.com/ubuntu2:latest when sent to the credential provider plugin, it will fetch credential from .azurecr.io unexpectedly
Currently it's not possible considering kubelet will not call credential provider plugin since the ".azurecr.io.example.com/ubuntu2:latest" does not match the matchImages defined below.
Also the credential provider plugin as a binary is installed on k8s node, is currently only called by kubelet if there's no manual operation.

apiVersion: kubelet.config.k8s.io/v1
kind: CredentialProviderConfig
providers:
  - name: acr-credential-provider
    matchImages:
      - "*.azurecr.io"
      - "*.azurecr.cn"
      - "*.azurecr.de"
      - "*.azurecr.us"
    defaultCacheDuration: "10m" // follow in-tree setting
    apiVersion: credentialprovider.kubelet.k8s.io/v1
    args:
      - /etc/kubernetes/azure.json

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

fix(credential-provider): check acr pattern to avoid spoofing

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 8, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mainred
Once this PR has been reviewed and has the lgtm label, please assign martinforreal for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot
Copy link
Contributor

Hi @mainred. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 8, 2025
@mainred
Copy link
Contributor Author

mainred commented Feb 8, 2025

@bahe-msft I did not use the function you suggested https://github.com/kubernetes/kubernetes/blob/2bda5dd8c794d933145938affca30f012986e8fa/pkg/credentialprovider/keyring.go#L184-L194 because when it comes down credential provider from kubelet, it's a determined acr image, so we just need to follow acr pattern to do the match and validation

@MartinForReal
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2025
@feiskyer
Copy link
Member

Looks good, let's wait for e2e validation results

imageWithoutRegistry := strings.Trim(targetImage, targetRegistry)
// for non customer cloud case, return registry only when:
// - the acr pattern match
// - the left string is empty or // credential provider authenticates the image pull request, but not validates the existence of the image
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fortunately, use acr with repo will raise authorization failure because kubelet will pull this kind of image from docker hub

Failed to pull image "qingchuanhao.azurecr.io": failed to pull and unpack image "docker.io/library/qingchuanhao.azurecr.io:latest": failed to resolve reference "docker.io/library/qingchuanhao.azurecr.io:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  containers:
  - name: container
    image: qingchuanhao.azurecr.io

@@ -205,8 +205,8 @@ func TestProcessImageWithMirrorMapping(t *testing.T) {
for _, test := range testcases {
t.Run(test.description, func(t *testing.T) {
targetloginServer, sourceloginServer := acrProvider.parseACRLoginServerFromImage(test.image)
assert.Equal(t, targetloginServer, test.expectedLoginServer)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For assert.Equal, expected variable comes before actual variable.
https://github.com/stretchr/testify/blob/master/assert/assertions.go#L460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants