Help us shape the future of Go! Take the 2026 Go Developer Survey

kubernetes

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 9 Imported by: 0

README

Kubernetes Secret Source (k8s://)

The Kubernetes secret source retrieves secrets directly from the Kubernetes API.

Status

Plugin: This source is opt-in. It is not enabled by default and requires explicit configuration using WithKubernetes().

Dependencies

This plugin requires the Kubernetes client libraries:

  • k8s.io/client-go
  • k8s.io/apimachinery
  • k8s.io/api

Usage

To use the Kubernetes source, use the k8s:// scheme followed by the namespace (optional), secret name, and key.

Syntax

Format 1: With Namespace

k8s://<NAMESPACE>/<SECRET_NAME>/<KEY>

Format 2: Default Namespace

k8s://<SECRET_NAME>/<KEY>

(Defaults to namespace default)

Examples

Retrieve key password from secret db-creds in namespace prod:

k8s://prod/db-creds/password

Retrieve key token from secret api-access in namespace default:

k8s://api-access/token

Configuration

To use this source, you must initialize spelunk with a Kubernetes client:

import (
    "github.com/detro/spelunk"
    "github.com/detro/spelunk/plugin/source/kubernetes"
    "k8s.io/client-go/kubernetes"
    "k8s.io/client-go/rest"
)

func main() {
    // 1. Create Kubernetes client
    config, _ := rest.InClusterConfig() // or BuildConfigFromFlags
    clientset, _ := kubernetes.NewForConfig(config)

    // 2. Initialize Spelunker with the Kubernetes plugin
    s := spelunk.NewSpelunker(
        kubernetes.WithKubernetes(clientset.CoreV1()),
    )

    // 3. Dig up secrets
    secret, _ := s.DigUp(ctx, coord)
}

Behavior

  1. Parsing: Splits the location into Namespace, Name, and Key.
  2. Validation: Checks if Namespace and Name are valid DNS subdomains (RFC 1123).
  3. Retrieval: Uses k8sClient.Secrets(namespace).Get() to fetch the secret resource.
  4. Extraction: Looks up the specific Key in the secret's Data map.
  5. Errors:
    • Returns ErrSecretNotFound if the Secret resource doesn't exist.
    • Returns ErrSecretKeyNotFound if the Secret exists but the Key does not.

Use Cases

  • Kubernetes Operators/Controllers: Retrieving secrets dynamically without mounting them.
  • In-Cluster Applications: accessing secrets from other namespaces (if RBAC permits).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSecretSourceKubernetesInvalidLocation = fmt.Errorf(
		"invalid kubernetes secret location format",
	)
	ErrSecretSourceKubernetesInvalidName = fmt.Errorf("invalid kubernetes name")
)

Functions

func WithKubernetes

func WithKubernetes(k8sClient corev1.SecretsGetter) spelunk.SpelunkerOption

WithKubernetes enables the SecretSourceKubernetes.

Types

type SecretSourceKubernetes

type SecretSourceKubernetes struct {
	// contains filtered or unexported fields
}

SecretSourceKubernetes digs up secrets from Kubernetes Secrets. The URI scheme for this source is "k8s".

k8s://NAMESPACE/NAME/KEY
k8s://NAME/KEY (where NAMESPACE is "default")

This types.SecretSource is a plug-in to spelunker.Spelunker and must be enabled explicitly.

func (*SecretSourceKubernetes) DigUp

func (s *SecretSourceKubernetes) DigUp(
	ctx context.Context,
	coord types.SecretCoord,
) (string, error)

func (*SecretSourceKubernetes) Type

func (s *SecretSourceKubernetes) Type() string

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

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