Skip to content

fix: Correctly configure non-mirror registry certificates #1039

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 3 commits into from
Feb 11, 2025

Conversation

jimmidyson
Copy link
Member

@jimmidyson jimmidyson commented Feb 10, 2025

This PR updates the runtime extensions to include two mutation handlers for Nutanix clusters:

  • nutanixclusterconfigpatch-gp.cluster-api-runtime-extensions-nutanix - original name and original (buggy functionality). This will still be referenced from existing CCs and so must retain the same name.
  • nutanixclusterv2configpatch-gp.cluster-api-runtime-extensions-nutanix - new name with fixed functionality. This is now referenced from the example CC in this project and can be used by existing clusters by rebasing on a CC that references this handler name.

The new handler fixes are:

CA certificates are now written to `/etc/containerd/certs.d/<registryHost>/ca.crt`
as required.

Remove non-mirror registry config from `/etc/containerd/certs.d/_default/hosts.toml`
which was causing all registries to be configured as mirror registry.
@github-actions github-actions bot added the fix label Feb 10, 2025
@dkoshkin dkoshkin requested a review from dlipovetsky February 10, 2025 17:09
@github-actions github-actions bot added fix and removed fix labels Feb 10, 2025
@dlipovetsky
Copy link
Contributor

Thanks!

I think this makes

// This handler reads input from two user provided variables: globalImageRegistryMirror and imageRegistries.
// The handler will be used to either add configuration for a global mirror or CA certificates for image registries.
func needContainerdConfiguration(configs []containerdConfig) bool {
unused, and I don't think there's a future need for it.

If that's correct, can I can push a commit that removes it, and related test code?

@jimmidyson
Copy link
Member Author

@dlipovetsky

If that's correct, can I can push a commit that removes it, and related test code?

No this is still used in https://github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/blob/jimmi/fix-registry-ca-certs/pkg/handlers/generic/mutation/mirrors/inject.go#L124-L131

@dkoshkin
Copy link
Contributor

I configured my test docker cluster like:

      value:
        imageRegistries:
          - url: https://172.18.0.10:5000
            credentials:
              secretRef:
                name: local-registry
          - url: https://docker.io
            credentials:
              secretRef:
                name: dockerhub

And the resulting KCP includes an extra file:

      - 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"
            - "docker.io"
            - "*"
            - "*.*"
            - "*.*.*"
            - "*.*.*.*"
            - "*.*.*.*.*"
            - "*.*.*.*.*.*"
            defaultCacheDuration: "0s"
            apiVersion: credentialprovider.kubelet.k8s.io/v1
        path: /etc/kubernetes/image-credential-provider-config.yaml
        permissions: "0600"
      - content: |
          apiVersion: credentialprovider.d2iq.com/v1alpha1
          kind: DynamicCredentialProviderConfig
          credentialProviderPluginBinDir: /etc/kubernetes/image-credential-provider/
          credentialProviders:
            apiVersion: kubelet.config.k8s.io/v1
            kind: CredentialProviderConfig
            providers:
            - name: static-credential-provider
              args:
              - /etc/kubernetes/static-image-credentials.json
              matchImages:
              - "172.18.0.10:5000"
              defaultCacheDuration: "0s"
              apiVersion: credentialprovider.kubelet.k8s.io/v1
            - name: static-credential-provider
              args:
              - /etc/kubernetes/static-image-credentials.json
              matchImages:
              - "docker.io"
              defaultCacheDuration: "0s"
              apiVersion: credentialprovider.kubelet.k8s.io/v1
        path: /etc/kubernetes/dynamic-credential-provider-config.yaml
        permissions: "0600"
      - contentFrom:
          secret:
            key: static-credential-provider
            name: dkoshkin-mutliple-registires-static-credential-provider-response
        path: /etc/kubernetes/static-image-credentials.json
        permissions: "0600"
      - content: |2+

        path: /etc/containerd/certs.d/_default/hosts.toml
        permissions: "0600"
      - contentFrom:
          secret:
            key: ca.crt
            name: local-registry
        path: /etc/containerd/certs.d/172.18.0.10:5000/ca.crt
        permissions: "0600"

(still trying to actually test and pull images)

@dlipovetsky
Copy link
Contributor

This is confirmed to work for a single configured registry. There are issues with two or more configured registries, but we'll address that in a follow-up PR.

@dlipovetsky
Copy link
Contributor

@jimmidyson Can you update the PR description, please? I think we'll have two different patches (nutanixclusterconfigpatch-gp.cluster-api-runtime-extensions-nutanix and nutanixclusterv2configpatch-gp.cluster-api-runtime-extensions-nutanix)?

@jimmidyson
Copy link
Member Author

Updated PR description.

@dlipovetsky
Copy link
Contributor

I verified the configuration, and functionality using a Docker cluster.

@dlipovetsky dlipovetsky merged commit 9dc7c36 into main Feb 11, 2025
27 checks passed
@dlipovetsky dlipovetsky deleted the jimmi/fix-registry-ca-certs branch February 11, 2025 22:49
dlipovetsky pushed a commit that referenced this pull request Feb 12, 2025
**What problem does this PR solve?**:
Now that we're fixing how the `_default` file is being generated just
for mirrors, we should skip creating the file if only registries are
provided.

Depends on #1039.

**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.
-->

**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.
-->
dlipovetsky pushed a commit that referenced this pull request Feb 12, 2025
Only allowed a single configuration per provider binary so match up
the image hosts per binary in the config.

Depends on #1039.
jimmidyson added a commit that referenced this pull request Feb 12, 2025
🤖 I have created a release *beep* *boop*
---


## 0.27.0 (2025-02-12)

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

## What's Changed
### Exciting New Features 🎉
* feat: Update COSI controller Addon by @dlipovetsky in
#1043
* feat: Build with Go 1.24.0 by @jimmidyson in
#1047
### Fixes 🔧
* fix: Specify PriorityClass for Node Feature Discovery components by
@dlipovetsky in
#1041
* fix: Correctly configure non-mirror registry certificates by
@jimmidyson in
#1039
* fix: Configure priorityClassName for Cilium Hubble by @dlipovetsky in
#1045
* fix: don't generate empty _default containerd mirror file by @dkoshkin
in
#1042
* fix: set priority class name for metallb by @supershal in
#1046
* fix: Correctly configure dynamic credential provider by @jimmidyson in
#1040


**Full Changelog**:
v0.26.0...v0.27.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