Validation webhook
Intercept and validate custom resource specifications before they persist in the cluster.
The Splunk Operator includes an optional validation webhook that validates Splunk Enterprise custom resource specifications before the Kubernetes API server persists them.
The validation webhook intercepts CREATE and UPDATE operations on Splunk Enterprise CRDs and validates the spec fields according to predefined rules. If validation fails, the request is rejected with a descriptive error message.
Supported CRDs
The webhook validates the following Custom Resource Definitions:
StandaloneIndexerClusterSearchHeadClusterClusterManagerLicenseManagerMonitoringConsole
Architecture
The validation webhook consists of the following components:
| Component | Description |
|---|---|
| Webhook server | HTTP server listening on port 9443 with TLS |
| Validator registry | Maps CRD types to their validation functions |
| ValidatingWebhookConfiguration | Kubernetes resource that registers the webhook |
| Certificate | TLS certificate managed by cert-manager |
| Service | Kubernetes service exposing the webhook endpoint |
Request flow
- A user submits a CREATE or UPDATE request for a Splunk CRD.
- The Kubernetes API server intercepts the request.
- The API server sends an AdmissionReview to the webhook service.
- The webhook server validates the spec fields.
- The webhook returns an Allowed or Denied response.
- If the webhook allows the request, the resource persists. If the webhook denies the request, the user receives an error.
Turn on the validation webhook
Turn om the validation webhook to validate Splunk Enterprise custom resource specifications before the Kubernetes API server persists them. The webhook is turned off by default and requires explicit opt-in.
Prerequisite
Install cert-manager in your cluster for TLS certificate management:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.0/cert-manager.yaml
kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager -n cert-manager
kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager-webhook -n cert-manager
You can enable the validation webhook by using one of the following deployment options.
Option 1: Use the webhook-enabled Kustomize overlay
Deploy using the config/default-with-webhook overlay, which includes all webhook components:
kustomize build config/default-with-webhook | kubectl apply -f -
Option 2: Enable the webhook on an existing deployment
If you already have the operator deployed, enable the webhook by setting the ENABLE_VALIDATION_WEBHOOK environment variable:
kubectl set env deployment/splunk-operator-controller-manager \
ENABLE_VALIDATION_WEBHOOK=true -n splunk-operator
Option 3: Modify the default Kustomization
Edit config/default/kustomization.yaml to uncomment the webhook-related sections:
- Uncomment
- ../webhookin thebasessection. - Uncomment
- ../certmanagerin thebasessection. - Uncomment
- manager_webhook_patch.yamlinpatchesStrategicMerge. - Uncomment
- webhookcainjection_patch.yamlinpatchesStrategicMerge. - Uncomment the
varssection for certificate injection.
Then deploy:
make deploy IMG=your-image SPLUNK_GENERAL_TERMS="--accept-sgt-current-at-splunk-com"
Validated fields: common fields for all CRDs
The validation webhook checks common and CRD-specific spec fields, including SmartStore and AppFramework configurations, when you submit custom resources.
| Field | Validation rule | Error message |
|---|---|---|
spec.etcVolumeStorageConfig.storageCapacity |
Must match format ^[0-9]+Gi$ (for example, "10Gi", "100Gi") |
must be in Gi format (e.g., '10Gi', '100Gi') |
spec.varVolumeStorageConfig.storageCapacity |
Must match format ^[0-9]+Gi$ |
must be in Gi format (e.g., '10Gi', '100Gi') |
spec.etcVolumeStorageConfig.storageClassName |
Required when ephemeralStorage=false and storageCapacity has a value |
storageClassName is required when using persistent storage |
spec.varVolumeStorageConfig.storageClassName |
Required when ephemeralStorage=false and storageCapacity has a value |
storageClassName is required when using persistent storage |
Validated fields: CRD-specific fields
| CRD | Field | Validation rule |
|---|---|---|
Standalone |
spec.replicas |
Must be greater than or equal to 0 |
IndexerCluster |
spec.replicas |
Must be greater than or equal to 3 |
SearchHeadCluster |
spec.replicas |
Must be greater than or equal to 3 |
Validated fields: SmartStore (Standalone and ClusterManager)
The webhook validates SmartStore configuration only when you provide it:
| Field | Validation rule |
|---|---|
spec.smartstore.volumes[*].name |
Required (non-empty) |
spec.smartstore.volumes[*] |
You must specify either endpoint or path |
spec.smartstore.indexes[*].name |
Required (non-empty) |
spec.smartstore.indexes[*].volumeName |
Required (non-empty) |
Validated fields: AppFramework (Standalone, ClusterManager, and SearchHeadCluster)
The webhook validates AppFramework configuration only when you provide it:
| Field | Validation rule |
|---|---|
spec.appRepo.appSources[*].name |
Required (non-empty) |
spec.appRepo.appSources[*].location |
Required (non-empty) |
spec.appRepo.volumes[*].name |
Required (non-empty) |
Validation error examples
The following examples show common validation errors that the webhook returns when you submit invalid custom resource specifications.
Invalid replicas
A negative value for spec.replicas causes a validation error:
apiVersion: enterprise.splunk.com/v4
kind: Standalone
metadata:
name: example
spec:
replicas: -1
Error:
The Standalone "example" is invalid: .spec.replicas: Invalid value: -1: should be a non-negative integer
Invalid storage configuration
Using an incorrect storage capacity suffix causes a validation error:
apiVersion: enterprise.splunk.com/v4
kind: Standalone
metadata:
name: example
spec:
etcVolumeStorageConfig:
storageCapacity: "10GB"
Error:
The Standalone "example" is invalid: spec.etcVolumeStorageConfig.storageCapacity: Invalid value: "10GB": must be in Gi format (e.g., '10Gi', '100Gi')
Missing SmartStore volume name
An empty name field for a SmartStore volume causes a validation error:
apiVersion: enterprise.splunk.com/v4
kind: Standalone
metadata:
name: example
spec:
smartstore:
volumes:
- name: ""
endpoint: "s3://bucket"
Error:
The Standalone "example" is invalid: spec.smartstore.volumes[0].name: Required value: volume name is required
Verify webhook deployment
After you enable the validation webhook, verify that the webhook pod, TLS certificate, webhook registration, and operator logs indicate a successful deployment. Run the following commands to confirm that all webhook components are operational.
- Check that the webhook pod is running:
CODE
kubectl get pods -n splunk-operatorExpected output:
CODEsplunk-operator-controller-manager-xxx 1/1 Running - Check that the certificate is ready:
CODE
kubectl get certificate -n splunk-operatorExpected output:
CODEsplunk-operator-serving-cert True webhook-server-cert - Check that the webhook is registered:
CODE
kubectl get validatingwebhookconfiguration splunk-operator-validating-webhook-configuration - Check the operator logs for webhook startup messages:
CODE
kubectl logs -n splunk-operator deployment/splunk-operator-controller-manager | grep -i webhookLook for the following messages:
- Validation webhook enabled via ENABLE_VALIDATION_WEBHOOK=true
- Starting webhook server {"port": 9443}
Troubleshoot the validation webhook
Diagnose and resolve common issues with the validation webhook, including registration failures, certificate problems, and configuration errors. The following issues can prevent the webhook from functioning correctly.
Issue: Webhook does not intercept requests
The webhook is not being called because the ValidatingWebhookConfiguration does not exist, the CA bundle is not injected, or the webhook service has no endpoints.
- Verify that the ValidatingWebhookConfiguration exists:
CODE
kubectl get validatingwebhookconfiguration splunk-operator-validating-webhook-configuration -o yaml - Check that the CA bundle is injected:
CODE
kubectl get validatingwebhookconfiguration splunk-operator-validating-webhook-configuration \ -o jsonpath='{.webhooks[0].clientConfig.caBundle}' | base64 -d | head -1The output should display -----BEGIN CERTIFICATE-----.
- Verify that the webhook service has endpoints:
CODE
kubectl get endpoints -n splunk-operator splunk-operator-webhook-serviceThe output should display an IP address.
Issue: Certificate problems
Certificate issues prevent the webhook from establishing TLS connections. The cert-manager might not have issued the certificate or the issuer might not exist.
- Check the cert-manager logs:
CODE
kubectl logs -n cert-manager deployment/cert-manager - Check the certificate status:
CODE
kubectl describe certificate -n splunk-operator splunk-operator-serving-cert - Check the issuer:
CODE
kubectl get issuer -n splunk-operator
Issue: Webhook is not enabled
The webhook is turned off because the ENABLE_VALIDATION_WEBHOOK environment variable is not set to true, or the deployment does not use the webhook-enabled Kustomize overlay.
- Verify that the
ENABLE_VALIDATION_WEBHOOKenvironment variable is set totrue. - Verify that you deployed with the correct Kustomize overlay (config/default-with-webhook).
Turn off the validation webhook
Turn off the validation webhook by updating the environment variable or by redeploying without the webhook overlay. Use one of the following methods.
Set the environment variable to false
kubectl set env deployment/splunk-operator-controller-manager \
ENABLE_VALIDATION_WEBHOOK=false -n splunk-operator
Redeploy without the webhook overlay
Redeploy using the default Kustomization, which does not include the webhook:
make deploy IMG=your-image SPLUNK_GENERAL_TERMS="--accept-sgt-current-at-splunk-com"