Skip to content

Commit f444553

Browse files
jmckulkjkatz
authored andcommitted
Update validation method for storing usernames in Kubernetes Secrets
The username provided in the pgo-conf file will be used to create a Kubernetes Secret for that user. The username must follow the Kube Secret naming requirements so that the secret can be created. Kube secrets can only have lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. These requirements can be validated using the "IsDNS1123Subdomain" function found in the Kubernetes validation library: https://godoc.org/k8s.io/kubernetes/pkg/apis/core/validation#ValidateDNS1123Subdomain
1 parent 75172e7 commit f444553

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

config/pgoconfig.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
log "github.com/sirupsen/logrus"
3030
"gopkg.in/yaml.v2"
3131
v1 "k8s.io/api/core/v1"
32+
"k8s.io/apimachinery/pkg/util/validation"
3233
"k8s.io/client-go/kubernetes"
3334
)
3435

@@ -301,7 +302,7 @@ func (c *PgoConfig) Validate() error {
301302
return errors.New(errPrefix + "Invalid PGBadgerPort: " + err.Error())
302303
}
303304
}
304-
if c.Cluster.ExporterPort == "" {
305+
if c.Cluster.ExporterPort == "" {
305306
c.Cluster.ExporterPort = DEFAULT_EXPORTER_PORT
306307
log.Infof("setting ExporterPort to default %s", c.Cluster.ExporterPort)
307308
} else {
@@ -477,6 +478,18 @@ func (c *PgoConfig) Validate() error {
477478

478479
if c.Cluster.User == "" {
479480
return errors.New(errPrefix + "Cluster.User is required")
481+
} else {
482+
// validates that username can be used as the kubernetes secret name
483+
// Must consist of lower case alphanumeric characters,
484+
// '-' or '.', and must start and end with an alphanumeric character
485+
errs := validation.IsDNS1123Subdomain(c.Cluster.User)
486+
if len(errs) > 0 {
487+
var msg string
488+
for i := range errs{
489+
msg = msg + errs[i]
490+
}
491+
return errors.New(errPrefix + msg)
492+
}
480493
}
481494
return err
482495
}

0 commit comments

Comments
 (0)