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

add some log messages to inform user when generating the tls certificates #321

Merged
merged 2 commits into from
Sep 5, 2023
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ linters:
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func New(ctx context.Context, opt *options.Common) *cobra.Command {
opt.AddFlags(rootCmd.PersistentFlags())

// Commands
rootCmd.AddCommand(tls.NewTLSCmd())
rootCmd.AddCommand(tls.NewTLSCmd(opt))
rootCmd.AddCommand(version.NewVersionCmd(opt))
rootCmd.AddCommand(registry.NewRegistryCmd(ctx, opt))
rootCmd.AddCommand(index.NewIndexCmd(ctx, opt))
Expand Down
4 changes: 3 additions & 1 deletion cmd/tls/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra"

"github.com/falcosecurity/falcoctl/pkg/install/tls"
commonoptions "github.com/falcosecurity/falcoctl/pkg/options"
)

// Defaults.
Expand All @@ -30,8 +31,9 @@ const (
)

// NewTLSInstallCmd returns the tls install command.
func NewTLSInstallCmd() *cobra.Command {
func NewTLSInstallCmd(opt *commonoptions.Common) *cobra.Command {
options := tls.Options{}
options.Common = opt

cmd := &cobra.Command{
Use: "install",
Expand Down
5 changes: 3 additions & 2 deletions cmd/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"github.com/spf13/cobra"

"github.com/falcosecurity/falcoctl/cmd/tls/install"
commonoptions "github.com/falcosecurity/falcoctl/pkg/options"
)

// NewTLSCmd return the tls command.
func NewTLSCmd() *cobra.Command {
func NewTLSCmd(opt *commonoptions.Common) *cobra.Command {
cmd := &cobra.Command{
Use: "tls",
TraverseChildren: true,
Expand All @@ -30,7 +31,7 @@ func NewTLSCmd() *cobra.Command {
Long: `Generate and install TLS material for Falco`,
}

cmd.AddCommand(install.NewTLSInstallCmd())
cmd.AddCommand(install.NewTLSInstallCmd(opt))

return cmd
}
6 changes: 5 additions & 1 deletion pkg/install/tls/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"os"
"path/filepath"
"time"

"github.com/falcosecurity/falcoctl/pkg/output"
)

// A GRPCTLS represents a TLS Generator for Falco.
Expand Down Expand Up @@ -239,7 +241,7 @@ func (g *GRPCTLS) GenerateClient(caTemplate *x509.Certificate, caKey DSAKey, not
}

// FlushToDisk is used to persist the cert material from a GRPCTLS to disk given a path.
func (g *GRPCTLS) FlushToDisk(path string) error {
func (g *GRPCTLS) FlushToDisk(path string, logger *output.Printer) error {
p, err := satisfyDir(path)
if err != nil {
return fmt.Errorf("invalid path: %w", err)
Expand All @@ -248,11 +250,13 @@ func (g *GRPCTLS) FlushToDisk(path string) error {

for _, name := range certsFilenames {
f := filepath.Join(path, name)
logger.Info.Printf("Saving %s to %s\n", name, path)
if err := os.WriteFile(f, g.certs[name].Bytes(), 0o600); err != nil {
return fmt.Errorf("unable to write %q: %w", name, err)
}
}

logger.Info.Println("Done generating the TLS certificates")
return nil
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/install/tls/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"crypto/elliptic"
"fmt"
"os"

commonoptions "github.com/falcosecurity/falcoctl/pkg/options"
)

// Options represents the `install tls` command o.
Expand All @@ -31,6 +33,8 @@ type Options struct {
DNSSANs []string
IPSANs []string
Algorithm string

Common *commonoptions.Common
}

// Run executes the business logic of the `install tls` command.
Expand All @@ -44,6 +48,8 @@ func (o *Options) Run() error {
o.Path = cwd
}

o.Common.Printer.Info.Printf("Generating certificates in %s directory\n", o.Path)

keyGenerator := NewKeyGenerator(DSAType(o.Algorithm))

switch DSAType(o.Algorithm) {
Expand Down Expand Up @@ -77,10 +83,5 @@ func (o *Options) Run() error {
return err
}

err = generator.FlushToDisk(o.Path)
if err != nil {
return err
}

return nil
return generator.FlushToDisk(o.Path, o.Common.Printer)
}
Loading