validation

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package validation provides shared validation primitives used by both the API layer (pkg/secrets) and the in-pod materializer (pkg/agentd/secrets). Keeping validation here prevents drift between the two code paths.

Index

Constants

View Source
const EnvVarNameMaxLength = 256

EnvVarNameMaxLength is the maximum length of a workspace env-var name. Matches the existing cap in pkg/agentd/secrets/secrets.go:226 (256).

View Source
const EnvVarNamePattern = `^[A-Za-z_][A-Za-z0-9_]*$`

EnvVarNamePattern is the regex pattern (as a string) that POSIX- portable env-var names must match: a letter or underscore, followed by letters, digits, or underscores. Bash, sh, and every common interpreter accept this shape. Matches the existing regex in pkg/agentd/secrets/secrets.go:203 — single source of truth lives here.

View Source
const SecretNamePattern = `^[a-z0-9._-]+$`

SecretNamePattern is the regex pattern (as a string) that secret names must match. Frontend teams SHOULD copy this exact string into their client-side validation (e.g., React Hook Form pattern or zod .regex()). This package is the single source of truth — file an issue against pkg/validation if the pattern needs to change.

Variables

EnvVarNameRE is the compiled regex for EnvVarNamePattern.

View Source
var ErrEnvVarNameBlocked = errors.New("env var name is on the dangerous-names blocklist")

ErrEnvVarNameBlocked is returned by ValidateEnvVarName when the name is on the dangerous-names blocklist. The error message names the offending variable so the user knows it was an intentional rejection rather than a regex miss.

SecretNameRE is the compiled regex for SecretNamePattern. Exported so callers can use it directly in Go.

Functions

func IsBlockedEnvVarName added in v0.4.0

func IsBlockedEnvVarName(name string) bool

IsBlockedEnvVarName reports whether name would be rejected by ValidateEnvVarName solely on the dangerous-names blocklist. Useful for callers that want to surface the blocklist reason separately from the regex/length reasons.

func ValidateEnvVarName added in v0.4.0

func ValidateEnvVarName(s string) error

ValidateEnvVarName validates a workspace env-var name against three rules:

  1. POSIX-portable shape: [A-Za-z_][A-Za-z0-9_]* (case-sensitive on the regex; the dangerous-name check below is case-insensitive).
  2. Length ≤ 256.
  3. Not on the dangerous-names blocklist (G37) — compared case- insensitively because ld.so and several interpreters accept the lowercase form on some platforms.

Shared between the API layer (api/internal/handlers/workspace_env.go) and the in-pod materializer (pkg/agentd/secrets/secrets.go) so the two layers cannot drift.

func ValidateSecretName

func ValidateSecretName(s string) error

ValidateSecretName validates a secret name against the shared rules. Returns nil if valid, or a descriptive error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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