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

[CIS-1.5] Move profile flag to common flags #387

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ func NewAgentCommand() cli.Command {
}

func AgentRun(clx *cli.Context) error {
if profile == "" {
switch profile {
Copy link
Member

Choose a reason for hiding this comment

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

This would probably make sense to have in a function in root.go that takes the profile string as an arg and does this logic so it's not needed to be maintained in 2 different places. More easily extensible too if/when we move to 1.6, etc. Not blocking however it'd be cool to have an issue that captures this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree 100%. I had originally moved this into the validateCISreqs function, but Craig asked me to reduce the amount of change so I went for a more minimal approach at the cost of some repetition.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1. He basically had that, but I asked him to minimize the pr to the smallest change possible for the purpose of reviewing and merging as quickly as possible.

Copy link
Member

Choose a reason for hiding this comment

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

Cool. Do we have an issue for this for after GA?

case "cis-1.5":
if err := validateCISreqs(); err != nil {
cjellick marked this conversation as resolved.
Show resolved Hide resolved
logrus.Fatal(err)
}
case "":
logrus.Warn("not running in CIS 1.5 mode")
default:
logrus.Fatal("invalid value provided for --profile flag")
}

return rke2.Agent(clx, config)
}
22 changes: 6 additions & 16 deletions pkg/cli/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ var (
EnvVar: "RKE2_CLOUD_PROVIDER_CONFIG",
Destination: &config.CloudProviderConfig,
},
&cli.StringFlag{
Name: "profile",
Usage: "(security) Validate system configuration against the selected benchmark (valid items: cis-1.5)",
EnvVar: "RKE2_CIS_PROFILE",
Destination: &profile,
},
}
)

Expand Down Expand Up @@ -133,28 +139,12 @@ func NewApp() *cli.App {
Destination: &debug,
EnvVar: "RKE2_DEBUG",
},
cli.StringFlag{
Name: "profile",
Usage: "Indicate we need to run in CIS 1.5 mode",
Destination: &profile,
EnvVar: "RKE2_CIS_PROFILE",
},
}

app.Before = func(clx *cli.Context) error {
if debug {
logrus.SetLevel(logrus.DebugLevel)
}
switch profile {
case "cis-1.5":
if err := validateCISreqs(); err != nil {
logrus.Fatal(err)
}
case "":
// continue. warning output another layer down.
default:
logrus.Fatal("invalid value provided for --profile flag")
}
return nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ func NewServerCommand() cli.Command {
}

func ServerRun(clx *cli.Context) error {
if profile == "" {
switch profile {
case "cis-1.5":
if err := validateCISreqs(); err != nil {
logrus.Fatal(err)
}
case "":
logrus.Warn("not running in CIS 1.5 mode")
default:
logrus.Fatal("invalid value provided for --profile flag")
}

return rke2.Server(clx, config)
}
12 changes: 2 additions & 10 deletions pkg/rke2/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,10 @@ func setup(clx *cli.Context, cfg Config) error {
case cli.StringFlag:
if strings.Contains(t.Name, "data-dir") {
dataDir = *t.Destination
}
}
}

for _, f := range clx.App.Flags {
switch t := f.(type) {
case cli.StringFlag:
if t.Name == "profile" && t.Destination != nil && *t.Destination != "" {
} else if t.Name == "profile" && t.Destination != nil && *t.Destination != "" {
cisMode = true
}
default:
// nothing to do. Keep moving.

}
}

Expand Down