mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-14 11:08:47 +00:00
Merge pull request #25458 from errm/env-var-style-config-keys
Automatic merge from submit-queue Allow Secret & ConfigMap keys to contain caps, dots, and underscores []() Re: #23722 This makes loosens the regex used in in Secrets and ConfigMap, in order to make environment variable style keys valid
This commit is contained in:
@@ -247,19 +247,26 @@ func IsHTTPHeaderName(value string) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
const configMapKeyFmt = "\\.?" + dns1123SubdomainFmt
|
||||
const configMapKeyFmt = `[-._a-zA-Z0-9]+`
|
||||
|
||||
var configMapKeyRegexp = regexp.MustCompile("^" + configMapKeyFmt + "$")
|
||||
|
||||
// IsConfigMapKey tests for a string that conforms to the definition of a
|
||||
// subdomain in DNS (RFC 1123), except that a leading dot is allowed
|
||||
// IsConfigMapKey tests for a string that is a valid key for a ConfigMap or Secret
|
||||
func IsConfigMapKey(value string) []string {
|
||||
var errs []string
|
||||
if len(value) > DNS1123SubdomainMaxLength {
|
||||
errs = append(errs, MaxLenError(DNS1123SubdomainMaxLength))
|
||||
}
|
||||
if !configMapKeyRegexp.MatchString(value) {
|
||||
errs = append(errs, RegexError(configMapKeyFmt, "key.name"))
|
||||
errs = append(errs, RegexError(configMapKeyFmt, "key.name", "KEY_NAME", "key-name"))
|
||||
}
|
||||
if value == "." {
|
||||
errs = append(errs, `must not be '.'`)
|
||||
}
|
||||
if value == ".." {
|
||||
errs = append(errs, `must not be '..'`)
|
||||
} else if strings.HasPrefix(value, "..") {
|
||||
errs = append(errs, `must not start with '..'`)
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
Reference in New Issue
Block a user