Skip to content

Commit

Permalink
Allow the provider to configure default secrets for default backends. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Nov 21, 2023
1 parent 67d88e7 commit 95b6f4e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 26 deletions.
15 changes: 15 additions & 0 deletions charts/gardener-extension-audit/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ data:
defaultBackends:
{{- toYaml .Values.config.defaultBackends | nindent 6 }}
{{- end }}

{{- range $secret := .Values.config.defaultBackendSecrets }}
---
apiVersion: v1
kind: Secret
metadata:
name: default-backend-secret-{{ $secret.name }}
namespace: {{ $.Release.Namespace }}
labels:
{{ include "labels" $ | indent 4 }}
data:
{{- range $key, $value := $secret.data }}
{{ $key }}: {{ $value | b64enc }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/gardener-extension-audit/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ spec:
- --log-level={{ .Values.logLevel | default "info" }}
- --log-format={{ .Values.logFormat | default "json" }}
env:
- name: BACKEND_SECRET_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BACKEND_SECRET_PREFIX
value: default-backend-secret-
- name: LEADER_ELECTION_NAMESPACE
valueFrom:
fieldRef:
Expand Down
5 changes: 5 additions & 0 deletions charts/gardener-extension-audit/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ config:

defaultBackends:

defaultBackendSecrets:
# - name: my-secret
# data:
# my-key: my-value

gardener:
version: ""
2 changes: 1 addition & 1 deletion example/controller-registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: audit
type: helm
providerConfig:
chart: H4sIAAAAAAAAA+0caW/bOLaf9SsIdwZogZXkOwMB3d20zcwE0yZB0s1gsVgEtETbmkiihqJybNv/vo+HZEqWLTtJk2lrIoBtiu8g+W5SmWEWkIQwm9xwkmQhTWyc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BSn/PLUj50HPKDr8arSy6a4zAhlrV5EchF//lv3vyLDAxkGySPdSd+/E0Vfp4pbx+44nt+9hfjLJF3kMS1AUuee8ppOdNXZP1PONaHoPrXWUhn3RXmMVJ3lgWh3xWku2+od0nYPICUKj921qjKZV5QugjJxfqWn8S18cqfjBSaWOPO0Ol1VEPxX3z6Tr/v3Hzdo+pvjKrzt1d8ZAP5wHEcyyoFga4lbwnkVz14SGl5xaP6d3/q3vzBsTAK3qnLbx/lWr1+C6e2h3g/pt+Th7fq5ZU+qLRV84rIRpt6eUMKlS/a6lZdELLUMbF2txnxp+K+AHyKncEq/keAa+nT1jEbtgEDBgwYMGDAgAEDBgwYMGDAgAEDBgwYMGDAgAEDBgwYMGDAgAEDBgwYMGDAwBeF/wMzaYDUAHgAAA==
values:
image:
tag: v0.1.0
Expand Down
13 changes: 13 additions & 0 deletions example/kustomize/patch-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ providerConfig:
# defaultBackends:
# clusterForwarding:
# enabled: true

# splunk:
# enabled: true
# index: <splunk index>
# host: splunk-endpoint.example.com
# port: "443"
# secretResourceName: splunk
# tls: true

# defaultBackendSecrets:
# - name: splunk
# data:
# token: test
4 changes: 2 additions & 2 deletions pkg/apis/audit/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func SetDefaults_AuditConfig(a *AuditConfig) {
a.Replicas = pointer.Pointer(int32(2))
}

defaultBackends(a.Backends)
DefaultBackends(a.Backends)
}

func defaultBackends(backends *AuditBackends) {
func DefaultBackends(backends *AuditBackends) {
if backends == nil {
return
}
Expand Down
107 changes: 84 additions & 23 deletions pkg/controller/audit/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package audit
import (
"context"
"fmt"
"os"
"path"
"time"

Expand Down Expand Up @@ -77,16 +78,13 @@ func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, ex *extension
}
}

if auditConfig.Backends == nil {
auditConfig.Backends = &v1alpha1.AuditBackends{
Log: &v1alpha1.AuditBackendLog{
Enabled: true,
},
}
backends, defaultBackendSecrets, err := a.applyDefaultBackends(ctx, log, auditConfig.Backends)
if err != nil {
log.Error(err, "unable to apply default backends configured by operator, continuing anyway but configuration of this extension needs to be checked")
} else {
auditConfig.Backends = backends
}

auditConfig.Backends = a.applyDefaultBackends(log, auditConfig.Backends)

namespace := ex.GetNamespace()

cluster, err := controller.GetCluster(ctx, a.client, namespace)
Expand All @@ -96,14 +94,9 @@ func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, ex *extension

splunkSecret := &corev1.Secret{}
if pointer.SafeDeref(auditConfig.Backends.Splunk).Enabled {
secretRef := helper.GetResourceByName(cluster.Shoot.Spec.Resources, auditConfig.Backends.Splunk.SecretResourceName)
if secretRef == nil {
return fmt.Errorf("splunk secret resource with name %q not found in shoot resources", auditConfig.Backends.Splunk.SecretResourceName)
}

err = controller.GetObjectByReference(ctx, a.client, &secretRef.ResourceRef, namespace, splunkSecret)
splunkSecret, err = a.findBackendSecret(ctx, cluster, defaultBackendSecrets, auditConfig.Backends.Splunk.SecretResourceName)
if err != nil {
return fmt.Errorf("unable to get referenced splunk secret: %w", err)
return err
}

_, ok := splunkSecret.Data[v1alpha1.SplunkSecretTokenKey]
Expand All @@ -119,30 +112,61 @@ func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, ex *extension
return nil
}

func (a *actuator) applyDefaultBackends(log logr.Logger, backends *v1alpha1.AuditBackends) *v1alpha1.AuditBackends {
// applyDefaultBackends adds default backends configured by the operator to the audit config in case this backend is not explcitly defined by the user.
// it returns the backends to which defaults were applied and a map of secrets that contains secrets referenced by the operator's default backends.
func (a *actuator) applyDefaultBackends(ctx context.Context, log logr.Logger, backends *v1alpha1.AuditBackends) (*v1alpha1.AuditBackends, map[string]*corev1.Secret, error) {
var (
secrets = map[string]*corev1.Secret{}
addSecret = func(secretName string) error {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: os.Getenv("BACKEND_SECRET_PREFIX") + secretName,
Namespace: os.Getenv("BACKEND_SECRET_NAMESPACE"),
},
}

err := a.client.Get(ctx, client.ObjectKeyFromObject(secret), secret)
if err != nil {
return fmt.Errorf("unable to get default backend secret: %w", err)
}

secrets[secretName] = secret

return nil
}
)

if backends == nil {
backends = &v1alpha1.AuditBackends{}
}
defaultedBackends := backends.DeepCopy()

if a.config.DefaultBackends == nil {
return defaultedBackends
// no default backends configured by the operator, nothing needs to be defaulted
return defaultedBackends, secrets, nil
}

if a.config.DefaultBackends.Log != nil && backends.Log == nil {
log.Info("configuring default backend for log")
log.Info(`configuring default backend "log"`)
defaultedBackends.Log = a.config.DefaultBackends.Log
}
if a.config.DefaultBackends.ClusterForwarding != nil && backends.ClusterForwarding == nil {
log.Info("configuring default backend for cluster forwarding")
log.Info(`configuring default backend "cluster forwarding"`)
defaultedBackends.ClusterForwarding = a.config.DefaultBackends.ClusterForwarding
}
if a.config.DefaultBackends.Splunk != nil && backends.Splunk == nil {
log.Info("configuring default backend for splunk")
log.Info(`configuring default backend "splunk"`)
defaultedBackends.Splunk = a.config.DefaultBackends.Splunk

err := addSecret(defaultedBackends.Splunk.SecretResourceName)
if err != nil {
return defaultedBackends, secrets, err
}
}

return defaultedBackends
v1alpha1.DefaultBackends(defaultedBackends)

return defaultedBackends, secrets, nil
}

// Delete the Extension resource.
Expand Down Expand Up @@ -170,7 +194,7 @@ func (a *actuator) createResources(ctx context.Context, log logr.Logger, auditCo
return err
}

secrets, err := a.generateSecrets(ctx, log, cluster)
secrets, err := a.generateCerts(ctx, log, cluster)
if err != nil {
return err
}
Expand Down Expand Up @@ -235,7 +259,7 @@ func (a *actuator) deleteResources(ctx context.Context, log logr.Logger, namespa
return nil
}

func (a *actuator) generateSecrets(ctx context.Context, log logr.Logger, cluster *extensions.Cluster) (map[string]*corev1.Secret, error) {
func (a *actuator) generateCerts(ctx context.Context, log logr.Logger, cluster *extensions.Cluster) (map[string]*corev1.Secret, error) {
const (
caName = "ca-audittailer"
)
Expand Down Expand Up @@ -1079,6 +1103,43 @@ func shootObjects(auditConfig *v1alpha1.AuditConfig, secrets map[string]*corev1.
}, nil
}

func (a *actuator) findBackendSecret(ctx context.Context, cluster *extensions.Cluster, defaultBackendSecrets map[string]*corev1.Secret, secretName string) (*corev1.Secret, error) {
fromShootResources := func() (*corev1.Secret, error) {
secretRef := helper.GetResourceByName(cluster.Shoot.Spec.Resources, secretName)
if secretRef == nil {
return nil, nil
}

secret := &corev1.Secret{}
err := controller.GetObjectByReference(ctx, a.client, &secretRef.ResourceRef, cluster.ObjectMeta.Name, secret)
if err != nil {
return nil, fmt.Errorf("unable to get referenced secret: %w", err)
}

return secret, nil
}

secret, err := fromShootResources()
if err != nil {
return nil, err
}

if secret == nil {
// if the secret is not referenced in the shoot resources it may be defined in the default backend secrets
if len(defaultBackendSecrets) > 0 {
var ok bool
secret, ok = defaultBackendSecrets[secretName]
if !ok {
return nil, fmt.Errorf("secret resource with name %q not found in default backend secrets", secretName)
}
} else {
return nil, fmt.Errorf("secret resource with name %q not found in shoot resources", secretName)
}
}

return secret, nil
}

func getReplicas(cluster *extensions.Cluster, wokenUp *int32) *int32 {
if controller.IsHibernated(cluster) {
return pointer.Pointer(int32(0))
Expand Down

0 comments on commit 95b6f4e

Please sign in to comment.