-
Notifications
You must be signed in to change notification settings - Fork 819
Use regex instead of format help for KMS secret name validation #2966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,7 +171,7 @@ const ( | |
| // alphanumeric characters, '-', '_', or '.', starting and ending with | ||
| // an alphanumeric character. | ||
| // +kubebuilder:validation:MaxLength=63 | ||
| // +kubebuilder:validation:XValidation:rule="!format.labelValue().validate(self).hasValue()",message="label values must be valid Kubernetes label values (at most 63 characters, alphanumeric, '-', '_', or '.', must start and end with alphanumeric)" | ||
| // +kubebuilder:validation:XValidation:rule="self.matches('^[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$')",message="label values must be valid Kubernetes label values (at most 63 characters, alphanumeric, '-', '_', or '.', must start and end with alphanumeric)" | ||
| type LabelValue string | ||
|
|
||
| // ConsumingUser is an alias for string which we add validation to. Currently only service accounts are supported. | ||
|
|
@@ -278,7 +278,7 @@ type ComponentRouteSpec struct { | |
| // +mapType=granular | ||
| // +kubebuilder:validation:MinProperties=1 | ||
| // +kubebuilder:validation:MaxProperties=8 | ||
| // +kubebuilder:validation:XValidation:rule="self.all(key, !format.qualifiedName().validate(key).hasValue())",message="label keys must be valid qualified names, consisting of an optional DNS subdomain prefix of up to 253 characters followed by a slash and a name segment of 1-63 characters, that consists only of alphanumeric characters, dashes, underscores, and dots, and must start and end with an alphanumeric character" | ||
| // +kubebuilder:validation:XValidation:rule="self.all(key, key.matches('^([a-z0-9]([a-z0-9\\\\-]*[a-z0-9])?(\\\\.[a-z0-9]([a-z0-9\\\\-]*[a-z0-9])?)*\\\\/)?[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$') && key.size() <= 253)",message="label keys must be valid qualified names, consisting of an optional DNS subdomain prefix of up to 253 characters followed by a slash and a name segment of 1-63 characters, that consists only of alphanumeric characters, dashes, underscores, and dots, and must start and end with an alphanumeric character" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
files=(
config/v1/types_ingress.go
payload-manifests/crds/0000_10_config-operator_01_ingresses-CustomNoUpgrade.crd.yaml
payload-manifests/crds/0000_10_config-operator_01_ingresses-DevPreviewNoUpgrade.crd.yaml
payload-manifests/crds/0000_10_config-operator_01_ingresses-TechPreviewNoUpgrade.crd.yaml
)
if rg -n --fixed-strings 'key.size() <= 253' "${files[@]}"; then
echo "The total-key length check is still present." >&2
exit 1
fi
python - <<'PY'
prefix = ".".join(["a" * 63, "b" * 63, "c" * 63, "d" * 61])
assert len(prefix) == 253
assert len(prefix + "/x") == 255
assert len("a" * 64) == 64
print("Qualified-name boundary fixtures are ready for API-server validation tests.")
PYRepository: openshift/api Length of output: 1184 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- source and generated rules ---'
sed -n '270,288p' config/v1/types_ingress.go
for f in \
payload-manifests/crds/0000_10_config-operator_01_ingresses-CustomNoUpgrade.crd.yaml \
payload-manifests/crds/0000_10_config-operator_01_ingresses-DevPreviewNoUpgrade.crd.yaml \
payload-manifests/crds/0000_10_config-operator_01_ingresses-TechPreviewNoUpgrade.crd.yaml
do
echo "--- $f ---"
sed -n '115,128p' "$f"
done
echo '--- related validation and tests ---'
rg -n -S 'key\.size\(\)|qualified name|QualifiedName|label keys|types_ingress|Ingress' \
config payload-manifests --glob '*.go' --glob '*.yaml' --glob '*_test.go' \
| head -200Repository: openshift/api Length of output: 43807 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
import re
# The Go annotation and CRDs express this same logical regex after escaping.
pattern = re.compile(
r'^([a-z0-9]([a-z0-9\-]*[a-z0-9])?'
r'(\.[a-z0-9]([a-z0-9\-]*[a-z0-9])?)*\/)?'
r'[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$'
)
def current_accepts(key):
return bool(pattern.fullmatch(key)) and len(key) <= 253
cases = {
"64-character name": "n" * 64,
"64-character DNS label": ("a" * 64) + "/x",
"253-character prefix plus /x":
".".join(["a" * 63, "b" * 63, "c" * 63, "d" * 61]) + "/x",
"valid 63-character name": "n" * 63,
"valid 63-character DNS label": ("a" * 63) + "/x",
}
for name, key in cases.items():
print(f"{name}: key_length={len(key)} regex={bool(pattern.fullmatch(key))} current_rule={current_accepts(key)}")
PYRepository: openshift/api Length of output: 496 Validate qualified-name segments independently. The rule accepts 64-character name and DNS-label segments and rejects a valid 253-character prefix followed by 📍 Affects 4 files
🤖 Prompt for AI Agents |
||
| // +kubebuilder:validation:XValidation:rule="self.all(key, !key.startsWith('kubernetes.io/') && !key.startsWith('k8s.io/') && !key.startsWith('openshift.io/'))",message="kubernetes.io/, k8s.io/, and openshift.io/ prefixed label keys are reserved and may not be used" | ||
| Labels map[string]LabelValue `json:"labels,omitempty"` | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/api
Length of output: 268
🏁 Script executed:
Repository: openshift/api
Length of output: 16795
🏁 Script executed:
Repository: openshift/api
Length of output: 5632
🏁 Script executed:
Repository: openshift/api
Length of output: 16722
Allow empty
LabelValuevalues in all generated CRDs.The current validation rejects
"", although the type documentation and Kubernetes label rules permit empty values. Make the complete non-empty regex alternative optional, regenerate the affected CRDs underconfig/v1/zz_generated*andpayload-manifests/crds, and add regression coverage for empty, one-character, valid, and trailing-separator values.📍 Affects 4 files
config/v1/types_ingress.go#L174-L174(this comment)payload-manifests/crds/0000_10_config-operator_01_ingresses-CustomNoUpgrade.crd.yaml#L93-L93payload-manifests/crds/0000_10_config-operator_01_ingresses-DevPreviewNoUpgrade.crd.yaml#L93-L93payload-manifests/crds/0000_10_config-operator_01_ingresses-TechPreviewNoUpgrade.crd.yaml#L93-L93🤖 Prompt for AI Agents