secretgenerator

package
v2.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

README

Secrets generator controller

Uploading secrets in plain text to git repositories is a common security issue in public repositories. Kustomize doesn't have a proper way of generating secrets on-demand, this controller adds the capability of generating random secrets in Openshift that can be used by other apps.

Basic usage

Create a Kubernetes secret with the secret-generator.opendatahub.io/name annotation, for example:

apiVersion: v1
kind: Secret
metadata:
  name: example
  annotations:
    secret-generator.opendatahub.io/name: "password"
    secret-generator.opendatahub.io/type: "random"
    secret-generator.opendatahub.io/complexity: "16"
type: Opaque

The controller will generate a new secret, with the same name and appending the suffix -generated, including the generated random value in the .data field:

apiVersion: v1
kind: Secret
metadata:
  name: example-generated
data:
  password: jgKGv6grDaLEMo6r
type: Opaque

Secret types

Generate different secret types based on the secret-generator.opendatahub.io/type annotation:

  • random: Generate a random string of the length specified in the complexity annotation. For example, jgKGv6grDaLEMo6r (complexity 16).
  • oauth: Generate an OAuth cookie secret. For example dURVM2VrQVI5cnZmK0ZkZXFsNDQrdz09 (complexity 16).

Documentation

Overview

Package secretgenerator contains generator logic of secret resources used in Open Data Hub operator

Index

Constants

View Source
const (
	SECRET_DEFAULT_COMPLEXITY = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Secret

type Secret struct {
	Name             string
	Type             string
	Complexity       int
	Value            string
	OAuthClientRoute string
}

func NewSecret added in v2.4.0

func NewSecret(name, secretType string, complexity int) (*Secret, error)

func NewSecretFrom added in v2.4.0

func NewSecretFrom(annotations map[string]string) (*Secret, error)

type SecretGeneratorReconciler

type SecretGeneratorReconciler struct {
	Client client.Client
	Scheme *runtime.Scheme
	Log    logr.Logger
}

SecretGeneratorReconciler holds the controller configuration.

func (*SecretGeneratorReconciler) Reconcile

func (r *SecretGeneratorReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error)

Reconcile will generate new secret with random data for the annotated secret based on the specified type and complexity. This will avoid possible race conditions when a deployment mounts the secret before it is reconciled.

func (*SecretGeneratorReconciler) SetupWithManager

func (r *SecretGeneratorReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL