Giter Site home page Giter Site logo

imagepullsecret-patcher's Introduction

imagepullsecret-patcher

Build Status Go Report Card Codecov GitHub tag (latest SemVer) GitHub issues

A simple Kubernetes controller, that creates and reconciles imagePullSecrets and attaches them to ServiceAccounts in all namespaces, to allow authenticated access to a private container registry.

Installation and configuration

A helm chart is available in the deploy directory.

# fetch chart version
skopeo list-tags docker://ghcr.io/tamcore/charts/imagepullsecret-patcher
# or
crane ls ghcr.io/tamcore/charts/imagepullsecret-patcher

# deploy
helm upgrade --install \
    imagepullsecret-patcher \
    oci://ghcr.io/tamcore/charts/imagepullsecret-patcher \
    --version ${CHART_VERSION} \
    --namespace ${NAMESPACE}

Available configuration options are

Config name ENV Command flag Default value Description
debug CONFIG_DEBUG -debug false show DEBUG logs
serviceaccounts CONFIG_SERVICEACCOUNTS -serviceaccounts "default" comma-separated list of ServiceAccounts to reconcile
dockerconfigjson CONFIG_DOCKERCONFIGJSON -dockerconfigjson "" json credentials for authenticating to container registry
dockerconfigjsonpath CONFIG_DOCKERCONFIGJSONPATH -dockerconfigjsonpath "" absolute path to mounted json credentials
secret name CONFIG_SECRETNAME -secretname "global-imagepullsecret" name of managed secrets
excluded namespaces CONFIG_EXCLUDED_NAMESPACES -excluded-namespaces "kube-*" comma-separated namespaces excluded from processing
And here are the annotations available:
Annotation Object Description
pborn.eu/imagepullsecret-patcher-exclude namespace, secret If this annotation is set to true, the object is excluded from reconciling.

Providing credentials

The desired credentials (or to be more specific, contents of the .dockerconfigjson) can be provided in 2 ways.

Either by passing the environment variable CONFIG_DOCKERCONFIGJSON containing the raw json, or CONFIG_DOCKERCONFIGJSONPATH pointing to the path, where the controller can access the provided credentials from a file. For example from a Secret that has been mounted into the Pod.

The 2nd option also has the advantage, that mounted secrets can be dynamically updated. Therefore it is not required to restart the controller, when the secret is updated.

Why

To deploy images from a private container registry, we have to provide Kubernetes with credentials to pull them. This is done by providing so called imagePullSecrets.

They're either attached to a

This is done manually by executing the command for each namespace (kubectl create secret..) and each ServiceAccount in it (kubectl patch..)

kubectl create secret docker-registry image-pull-secret \
  -n <your-namespace> \
  --docker-server=<your-registry-server> \
  --docker-username=<your-name> \
  --docker-password=<your-pword> \
  --docker-email=<your-email>

kubectl patch serviceaccount default \
  -p "{\"imagePullSecrets\": [{\"name\": \"image-pull-secret\"}]}" \
  -n <your-namespace>

or.. we could automate with a small controller like this imagepullsecret-patcher.

Using the imagepullsecret-patcher also has the advantage, that deployments via ArgoCD for example are automatically caught and newly created ServiceAccounts are automatically patched, as the controller issues a WATCH on ServiceAccount resources and therefore is notified by Kubernetes, if something changes. The same goes for unwanted changes to managed Secrets. That way we can ensure they're not tampered with and always match our source.

imagepullsecret-patcher's People

Contributors

tamcore avatar pb-renovate[bot] avatar

Watchers

 avatar  avatar

imagepullsecret-patcher's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

Renovate tried to run on this repository, but found these problems.

  • WARN: File contents are invalid JSON but parse using JSON5. Support for this will be removed in a future release so please change to a support .json5 file name or ensure correct JSON syntax.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/go.yaml
  • actions/checkout v4
  • actions/setup-go v5
.github/workflows/release.yaml
  • actions/checkout v4
  • azure/setup-helm v4
  • docker/login-action v3
  • actions/setup-go v5
  • ko-build/setup-ko v0.7
  • goreleaser/goreleaser-action v6
  • actions/checkout v4
  • azure/setup-helm v4
  • svenstaro/upload-release-action v2
gomod
go.mod
  • go 1.22.0
  • go 1.22.2
  • github.com/KimMachineGun/automemlimit v0.6.1
  • github.com/caitlinelfring/go-env-default v1.1.0
  • github.com/onsi/ginkgo/v2 v2.20.0
  • github.com/onsi/gomega v1.34.1
  • go.uber.org/automaxprocs v1.5.3
  • k8s.io/api v0.31.0
  • k8s.io/apimachinery v0.31.0
  • k8s.io/client-go v0.31.0
  • sigs.k8s.io/controller-runtime v0.19.0
helm-values
deploy/helm/values.yaml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.