Skip to content

Commit

Permalink
Merge pull request #2 from Webfleet-Solutions/feature/circumvent-inse…
Browse files Browse the repository at this point in the history
…cure-secrets-listing

Feature/circumvent insecure secrets listing
  • Loading branch information
mowoe authored Dec 13, 2023
2 parents 1d0a6e8 + 9885736 commit 5522d45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions helm/charts/k8s-image-availability-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

This chart bootstraps a [k8s-image-availability-exporter](https://github.com/flant/k8s-image-availability-exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.

> [!WARNING]
> By default, k8s-iae has unconstrained access to **all** secrets in the cluster!
## Prerequisites
- Kubernetes 1.12+
- Helm 2+
Expand Down Expand Up @@ -39,6 +42,7 @@ The following tables list the configurable parameters of the k8s-image-availabil
### General
| Parameter | Description | Default |
| ----- | ----------- | ------ |
| `k8sImageAvailabilityExporter.useSecretsForPrivateRepositories` | Give k8s-iae unconstrained access to all secrets in the cluster. This is necessary if there are images that are referenced from private registries, which are deployed in pods, where the pull secret is not defined in `spec.imagePullSecrets` in plaintext but rather in an external secret. This setting only modifies the RBAC rules. | `true` |
| `k8sImageAvailabilityExporter.image.pullPolicy` | Image pull policy to use for the k8s-image-availability-exporter deployment | `IfNotPresent` |
| `k8sImageAvailabilityExporter.image.repository` | Repository to use for the k8s-image-availability-exporter deployment | `ghcr.io/Webfleet-Solutions/k8s-image-availability-exporter` |
| `k8sImageAvailabilityExporter.image.tag` | Tag to use for the k8s-image-availability-exporter deployment | `latest` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: ClusterRole
metadata:
name: {{ template "k8s-image-availability-exporter.fullname" . }}
rules:
{{- if .Values.k8sImageAvailabilityExporter.useSecretsForPrivateRepositories }}
- apiGroups:
- ""
resources:
Expand All @@ -12,6 +13,7 @@ rules:
- list
- watch
- get
{{- end }}
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions helm/charts/k8s-image-availability-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ k8sImageAvailabilityExporter:
pullPolicy: IfNotPresent
replicas: 1
resources: {}
useSecretsForPrivateRepositories: true # Setting this to false will prevent k8s-iae having unconstrained cluster-wide secret access
args:
- --bind-address=:8080

Expand Down
13 changes: 12 additions & 1 deletion pkg/registry_checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
appsv1informers "k8s.io/client-go/informers/apps/v1"
batchv1informers "k8s.io/client-go/informers/batch/v1"
corev1informers "k8s.io/client-go/informers/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/client-go/informers"

Expand Down Expand Up @@ -193,7 +194,17 @@ func NewRegistryChecker(
}
rc.controllerIndexers.cronJobIndexer = rc.cronJobsInformer.Informer().GetIndexer()

rc.controllerIndexers.secretIndexer = rc.secretsInformer.Informer().GetIndexer()
namespace := "default"
// Create a context
ctx := context.TODO()
// Attempt to list secrets in the default namespace
_, enumerr := kubeClient.CoreV1().Secrets(namespace).List(ctx, metav1.ListOptions{})
if enumerr != nil {
// Not add the secret indexer to automatic cache updater
logrus.Warn("The provided ServiceAccount is not able to list secrets. The check for images in private registries requires 'spec.imagePullSecrets' to be configured correctly.")
} else {
rc.controllerIndexers.secretIndexer = rc.secretsInformer.Informer().GetIndexer()
}

go informerFactory.Start(stopCh)
logrus.Info("Waiting for cache sync")
Expand Down

0 comments on commit 5522d45

Please sign in to comment.