Skip to content
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

Validate user provided hostnames do not contain any illegal characters #128

Merged
merged 4 commits into from
Oct 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add valid hostname checks for provided hostnames
  • Loading branch information
YrrepNoj committed Oct 27, 2021
commit 17c419754930d57cdb6307772ff7a4ebf7c3d188
6 changes: 5 additions & 1 deletion cli/cmd/initialize.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@ import (
"path/filepath"

"github.com/defenseunicorns/zarf/cli/internal/k3s"
"github.com/defenseunicorns/zarf/cli/internal/utils"

"github.com/AlecAivazis/survey/v2"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

@@ -23,7 +25,6 @@ var initCmd = &cobra.Command{
}

func handleTLSOptions() {

// Check to see if the certpaths or host entries are set as flags first
if initOptions.PKI.CertPublicPath == "" && initOptions.PKI.Host == "" {

@@ -63,6 +64,9 @@ func handleTLSOptions() {
_ = survey.AskOne(prompt, &initOptions.PKI.CertPrivatePath, survey.WithValidator(survey.Required))
}
}
if !utils.CheckHostName(initOptions.PKI.Host) {
logrus.Fatalf("The hostname provided (%v) was not a valid hostname. The hostname can only contain: 'a-z', 'A-Z', '0-9', '-', and '.' characters.\n", initOptions.PKI.Host)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about passing the regex into the error message but I decided against it in favor of the simple can only contain ... Since Zarf is a tool to simplify setting up clusters/packages some of the people might not be technical enough to decode a regex (I had to use an online tool just to double check it was doing what I though) and I wanted the error message to be simple but clear.

Any other opinions on what might be better?

}
}

func init() {
5 changes: 5 additions & 0 deletions cli/cmd/pki.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package cmd

import (
"github.com/defenseunicorns/zarf/cli/internal/utils"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

@@ -16,6 +17,10 @@ var pkiRegenerate = &cobra.Command{
Use: "regenerate",
Short: "Regenerate the pki certs for the cluster ingress",
Run: func(cmd *cobra.Command, args []string) {
if !utils.CheckHostName(pkiOptions.Host) {
logrus.Fatalf("The hostname provided (%v) was not a valid hostname. The hostname can only contain: 'a-z', 'A-Z', '0-9', '-', and '.' characters.\n", pkiOptions.Host)
}

utils.GeneratePKI(pkiOptions)
},
}