Skip to content

Commit

Permalink
fix(install_panels): use IsDNS1123Subdomain to validate hostname
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Yang <poan.yang@suse.com>
  • Loading branch information
FrankYang0529 authored and guangbochen committed Sep 27, 2021
1 parent 85d7574 commit 212059f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,10 @@ func addNetworkPanel(c *Console) error {
if hostName == "" {
return "must specify hostname", nil
}
if errs := validation.IsQualifiedName(hostName); len(errs) > 0 {
return fmt.Sprintf("%s is not a valid hostname", hostName), nil
// ref: https://github.com/kubernetes/kubernetes/blob/b15f788d29df34337fedc4d75efe5580c191cbf3/pkg/apis/core/validation/validation.go#L242-L245
if errs := validation.IsDNS1123Subdomain(hostName); len(errs) > 0 {
// TODO: show regexp for validation to users
return "Invalid hostname. A lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.'.", nil
}
c.config.Hostname = hostName
return "", nil
Expand Down
7 changes: 7 additions & 0 deletions pkg/console/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ func checkVip(vip, vipHwAddr, vipMode string) error {
}

func (v ConfigValidator) Validate(cfg *config.HarvesterConfig) error {
// check hostname
// ref: https://github.com/kubernetes/kubernetes/blob/b15f788d29df34337fedc4d75efe5580c191cbf3/pkg/apis/core/validation/validation.go#L242-L245
if errs := validation.IsDNS1123Subdomain(cfg.OS.Hostname); len(errs) > 0 {
// TODO: show regexp for validation to users
return errors.Errorf("Invalid hostname. A lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.'.")
}

if err := checkDevice(cfg.Install.Device); err != nil {
return err
}
Expand Down

0 comments on commit 212059f

Please sign in to comment.