Skip to content

fix: CredentialProviderConfig matchImages to support registries with port #724

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

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

dkoshkin
Copy link
Contributor

@dkoshkin dkoshkin commented Jun 18, 2024

What problem does this PR solve?:
While debugging another issue where I launched a local registry in a container at https://172.18.0.10:5000, I noticed that Deployments with an image in that registry failed:

  Warning  Failed     7m14s (x4 over 8m47s)   kubelet            Failed to pull image "172.18.0.10:5000/library/nginx:latest": failed to pull and unpack image "172.18.0.10:5000/library/nginx:latest": failed to resolve reference "172.18.0.10:5000/library/nginx:latest": pull access denied, repository does not exist or may require authorization: authorization failed: no basic auth credentials

This is because of a bug in how matchImages in CredentialProviderConfig was generated, the globs don't match images with a port or a path. This PR fixes that by explicitly including the user provided registries in matchImages.

Which issue(s) this PR fixes:
Fixes #

How Has This Been Tested?:

  • Updated unit tests

Special notes for your reviewer:

@github-actions github-actions bot added fix and removed fix labels Jun 18, 2024
@jimmidyson
Copy link
Member

@dkoshkin I can't see - does this include the mirror registry? It will also need to be in the matchImages

@github-actions github-actions bot added fix and removed fix labels Jun 18, 2024
@dkoshkin dkoshkin force-pushed the dkoshkin/fix-for-image-registries-with-port branch from f136d6e to 04c07e3 Compare June 18, 2024 18:29
@dkoshkin
Copy link
Contributor Author

dkoshkin commented Jun 18, 2024

@dkoshkin I can't see - does this include the mirror registry? It will also need to be in the matchImages

Yes @jimmidyson, eventually this function gets called here, where registriesWithOptionalCredentials contains the registries from both vars imageRegistries and globalMirror

files, commands, generateErr := generateFilesAndCommands(
registriesWithOptionalCredentials,
clusterKey.Name,
)

Just tested locally too:

Setting either one:

        imageRegistries:
        - credentials:
            secretRef:
              name: docker-creds-1-image-registry-mirror-credentials
          url: https://172.18.0.10:5000
        globalImageRegistryMirror:
          credentials:
            secretRef:
              name: docker-creds-1-image-registry-mirror-credentials
          url: https://172.18.0.10:5000

Generated config:

    - content: |
        apiVersion: kubelet.config.k8s.io/v1
        kind: CredentialProviderConfig
        providers:
        - name: dynamic-credential-provider
          args:
          - get-credentials
          - -c
          - /etc/kubernetes/dynamic-credential-provider-config.yaml
          matchImages:
          - "172.18.0.10:5000"
          - "*"
          - "*.*"
          - "*.*.*"
          - "*.*.*.*"
          - "*.*.*.*.*"
          - "*.*.*.*.*.*"
          defaultCacheDuration: "0s"
          apiVersion: credentialprovider.kubelet.k8s.io/v1
      path: /etc/kubernetes/image-credential-provider-config.yaml
      permissions: "0600"

@dkoshkin dkoshkin enabled auto-merge (squash) June 18, 2024 19:31
@dkoshkin dkoshkin merged commit 30a98da into main Jun 18, 2024
17 checks passed
@dkoshkin dkoshkin deleted the dkoshkin/fix-for-image-registries-with-port branch June 18, 2024 19:34
@github-actions github-actions bot mentioned this pull request Jun 18, 2024
jimmidyson pushed a commit that referenced this pull request Jun 21, 2024
**What problem does this PR solve?**:
While working on
#724
I noticed that setting imageRegistry CA certificate had no effect on the
generated configuration.

I structured `/mirrors/inject.go` similar to
`/imageregistries/credentials/inject.go` where it reads both the
`globalImageRegistryMirror` and `imageRegistries` variables and handles
them together when generating the necessary files.

**Which issue(s) this PR fixes**:
Fixes #

**How Has This Been Tested?**:
<!--
Please describe the tests that you ran to verify your changes.
Provide output from the tests and any manual steps needed to replicate
the tests.
-->
```
# Tested by setting an imageRegistries. The mirror Pod failure is expected because the cluster is not configured as a mirror
$ kubectl get pods
NAME                                                 READY   STATUS              RESTARTS   AGE
cluster-autoscaler-docker-creds-1-77c5df58c4-gs6m2   0/1     ContainerCreating   0          94s
nginx-latest                                         1/1     Running             0          10s
nginx-mirror                                         0/1     ErrImagePull        0          10s
nginx-stable                                         1/1     Running             0          10s

# Tested by setting an globalImageRegistryMirror
$ kubectl get pods
NAME                                                 READY   STATUS              RESTARTS   AGE
cluster-autoscaler-docker-creds-1-77c5df58c4-nncdc   0/1     ContainerCreating   0          22m
nginx-latest                                         1/1     Running             0          9s
nginx-mirror                                         1/1     Running             0          9s
nginx-stable                                         1/1     Running             0          9s
```

**Special notes for your reviewer**:
<!--
Use this to provide any additional information to the reviewers.
This may include:
- Best way to review the PR.
- Where the author wants the most review attention on.
- etc.
-->
faiq pushed a commit that referenced this pull request Jun 24, 2024
🤖 I have created a release *beep* *boop*
---


## 0.10.0 (2024-06-24)

<!-- Release notes generated using configuration in .github/release.yaml
at main -->

## What's Changed
### Exciting New Features 🎉
* feat: Upgrade to Cilium v1.15.5 by @jimmidyson in
#689
* feat: Upgrade to Calico v3.28.0 by @jimmidyson in
#688
* feat: bumps caaph to v0.2.3 by @faiq in
#691
* feat: Add local-path-provisioner CSI by @jimmidyson in
#693
* feat: cluster-api v1.7.3 by @jimmidyson in
#714
* feat: bumps caaph to 0.2.4 by @faiq in
#718
* feat: Controller that copies ClusterClasses to namespaces by
@dlipovetsky in
#715
* feat: adds a mindthegap container and deployment by @faiq in
#637
* feat: implements BeforeClusterUpgrade hook by @faiq in
#682
### Fixes 🔧
* fix: use external Nutanix API types directly by @dkoshkin in
#698
* fix: Post-process clusterconfig CRDs for supported CSI providers by
@jimmidyson in
#695
* fix: nutanix credentials Secrets owner refs by @dkoshkin in
#711
* fix: credential provider response secret ownership by @dkoshkin in
#709
* fix: static credentials Secret generation by @dkoshkin in
#717
* fix: set ownerReference on imageRegistry and globalMirror Secrets by
@dkoshkin in
#720
* fix: Allow Nutanix CSI snapshot controller & webhook to run on CP
nodes by @dlipovetsky in
#723
* refactor: Use maps for CSI providers and storage classes by
@jimmidyson in
#696
* fix: CredentialProviderConfig matchImages to support registries with
port by @dkoshkin in
#724
* fix: Allow Node Feature Discovery garbage collector to run on
control-plane nodes by @dlipovetsky in
#722
* fix: RBAC role for namespace-sync controller to watch,list namespaces
by @dkoshkin in
#738
* fix: image registries not handling CA certificates by @dkoshkin in
#729
* fix: adds a docker buildx step before release-snapshot by @faiq in
#741
### Other Changes
* docs: Add released version to helm and clusterctl install by
@jimmidyson in
#683
* revert: Temporary lint config fix until next golangci-lint release
(#629) by @jimmidyson in
#686
* refactor: Delete unused code by @jimmidyson in
#687
* refactor: Reduce log verbosity for skipped handlers by @jimmidyson in
#692
* build: update Go to 1.22.4 by @dkoshkin in
#700
* build(deps): Upgrade CAPX version to v1.4.0 by @thunderboltsid in
#707
* build: Move CSI supported provider logic to script by @jimmidyson in
#703
* build: Add testifylint linter by @jimmidyson in
#706
* build: Update all tools by @jimmidyson in
#704
* refactor: rename credential provider response secret by @dkoshkin in
#710
* refactor: Simplify code by using slices.Clone by @jimmidyson in
#712
* refactor: consistently use the same SetOwnerReference function by
@dkoshkin in
#713
* refactor: kube-vip commands by @dkoshkin in
#699
* build: Fix an incorrect make variable passed to goreleaser by
@dlipovetsky in
#716
* build: Add 'chart-docs' make target by @dlipovetsky in
#727
* build: Make CAREN mindthegap reg multiarch by @jimmidyson in
#730
* Add helm values schema plugin by @dlipovetsky in
#728
* test(e2e): Use mesosphere fork with CRSBinding fix by @jimmidyson in
#736

## New Contributors
* @thunderboltsid made their first contribution in
#707

**Full Changelog**:
v0.9.0...v0.10.0

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants