kube-openapi: Validator for `byte` does not match mashalling behavior
kube-openapi code generator encodes all []byte types as a string with byte format: https://github.com/kubernetes/kube-openapi/blob/34a5c6ab6a70d85502e2e15190fa5cf1b8f29d37/pkg/common/common.go#L218-L240
(Side-note: Most of the formats referred to in this list arent even supported by our openapi-validator and have no meaning: int32, int64, double, float)
The schema validator uses IsBase64 from github.com/asaskevich/govalidator to determine if a string fits byte format.
This validates the string against the regex:
^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$
However, native types deserialize []byte types using the standard go library, which internally uses base64.StdEncoding. base64.StdEncoding follows RFC4648.
Problem: RFC4648 allows empty string, but the pattern does not. There may be other differences.
Paths forward:
- Change IsBase64 to accept empty string and conform to RFC4648
- Pros:
byteformat has a well-defined meaningbytehas same meaning between k8s native and CRD types
- Cons:
- API Breaking without CRD Validation Ratcheting. Even with ratcheting, regex change would be surprising to users.
- Mitigation (suggested by @apelisse): Inject
maxLength: 1into all usages offormat: byteby users upon decode.
- Mitigation (suggested by @apelisse): Inject
- If we wait for CRD Validation Ratcheting we will have a long time before this is fixed
- API Breaking without CRD Validation Ratcheting. Even with ratcheting, regex change would be surprising to users.
- Pros:
- Add new
base64-rfc4648format. Change code-generator to use new different format for[]byte- Pros:
- API compatible change
- Cons:
- New format addition might require we wait for CRD validation ratcheting
- Mitigation: Use an inline schema rather than adding a new format, and refer to it using
$refuntil format is added
- Mitigation: Use an inline schema rather than adding a new format, and refer to it using
- CRDs who want to use RFC4648 are stuck with unspecified
byteformat- Mitigation: After CRD-Validation Ratcheting is stable, we add new formats for the specific byte RFC. We then migrate native types to use the new format and deprecate old
byteformat.
- Mitigation: After CRD-Validation Ratcheting is stable, we add new formats for the specific byte RFC. We then migrate native types to use the new format and deprecate old
- New format addition might require we wait for CRD validation ratcheting
- Pros:
Impact: Making the schemas accurate for native types is a prerequisite to KEP-4153: Declarative Validation. This is a blocker to using schemas to validate native types.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (13 by maintainers)
Offline discussion between Jordan, Alex and I. Conclusions:
we should obviously only do that once ratcheting would keep from breaking existing data