cli: attestation validator debug output (#1262)

* Wrote->Written

* Add Validator info logs to debug output

---------

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2023-03-03 16:50:25 +01:00 committed by GitHub
parent 2023edaef0
commit 19507677c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 13 deletions

View File

@ -34,11 +34,12 @@ type Validator struct {
enforceIDKeyDigest bool enforceIDKeyDigest bool
azureCVM bool azureCVM bool
validator atls.Validator validator atls.Validator
log debugLog
} }
// NewValidator creates a new Validator. // NewValidator creates a new Validator.
func NewValidator(provider cloudprovider.Provider, conf *config.Config) (*Validator, error) { func NewValidator(provider cloudprovider.Provider, conf *config.Config, log debugLog) (*Validator, error) {
v := Validator{} v := Validator{log: log}
if provider == cloudprovider.Unknown { if provider == cloudprovider.Unknown {
return nil, errors.New("unknown cloud provider") return nil, errors.New("unknown cloud provider")
} }
@ -140,7 +141,7 @@ func (v *Validator) PCRS() measurements.M {
} }
func (v *Validator) updateValidator(cmd *cobra.Command) { func (v *Validator) updateValidator(cmd *cobra.Command) {
log := warnLogger{cmd: cmd} log := warnLogger{cmd: cmd, log: v.log}
switch v.provider { switch v.provider {
case cloudprovider.GCP: case cloudprovider.GCP:
v.validator = gcp.NewValidator(v.pcrs, log) v.validator = gcp.NewValidator(v.pcrs, log)
@ -160,10 +161,14 @@ func (v *Validator) updateValidator(cmd *cobra.Command) {
// warnLogger implements logging of warnings for validators. // warnLogger implements logging of warnings for validators.
type warnLogger struct { type warnLogger struct {
cmd *cobra.Command cmd *cobra.Command
log debugLog
} }
// Infof is a no-op since we don't want extra info messages when using the CLI. // Infof messages are reduced to debug messages, since we don't want
func (wl warnLogger) Infof(format string, args ...any) {} // the extra info when using the CLI without setting the debug flag.
func (wl warnLogger) Infof(fmtStr string, args ...any) {
wl.log.Debugf(fmtStr, args...)
}
// Warnf prints a formatted warning from the validator. // Warnf prints a formatted warning from the validator.
func (wl warnLogger) Warnf(fmtStr string, args ...any) { func (wl warnLogger) Warnf(fmtStr string, args ...any) {

View File

@ -21,6 +21,7 @@ import (
"github.com/edgelesssys/constellation/v2/internal/attestation/qemu" "github.com/edgelesssys/constellation/v2/internal/attestation/qemu"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/config"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -95,7 +96,7 @@ func TestNewValidator(t *testing.T) {
conf.Provider.QEMU = &config.QEMUConfig{Measurements: tc.pcrs} conf.Provider.QEMU = &config.QEMUConfig{Measurements: tc.pcrs}
} }
validators, err := NewValidator(tc.provider, conf) validators, err := NewValidator(tc.provider, conf, logger.NewTest(t))
if tc.wantErr { if tc.wantErr {
assert.Error(err) assert.Error(err)

View File

@ -129,7 +129,7 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
if err := fileHandler.WriteYAML(flags.configPath, conf, file.OptOverwrite); err != nil { if err := fileHandler.WriteYAML(flags.configPath, conf, file.OptOverwrite); err != nil {
return err return err
} }
cfm.log.Debugf("Wrote configuration to YAML") cfm.log.Debugf("Configuration written to %s", flags.configPath)
return nil return nil
} }

View File

@ -136,7 +136,7 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
cmd.PrintErrf("License check failed: %v", err) cmd.PrintErrf("License check failed: %v", err)
} }
i.log.Debugf("Checked license") i.log.Debugf("Checked license")
validator, err := cloudcmd.NewValidator(provider, conf) validator, err := cloudcmd.NewValidator(provider, conf, i.log)
if err != nil { if err != nil {
return err return err
} }
@ -288,7 +288,7 @@ func (i *initCmd) writeOutput(
if err := fileHandler.Write(constants.AdminConfFilename, resp.Kubeconfig, file.OptNone); err != nil { if err := fileHandler.Write(constants.AdminConfFilename, resp.Kubeconfig, file.OptNone); err != nil {
return fmt.Errorf("writing kubeconfig: %w", err) return fmt.Errorf("writing kubeconfig: %w", err)
} }
i.log.Debugf("Wrote kubeconfig to file: %s", constants.AdminConfFilename) i.log.Debugf("Kubeconfig written to %s", constants.AdminConfFilename)
if mergeConfig { if mergeConfig {
if err := i.merger.mergeConfigs(constants.AdminConfFilename, fileHandler); err != nil { if err := i.merger.mergeConfigs(constants.AdminConfFilename, fileHandler); err != nil {
@ -303,7 +303,7 @@ func (i *initCmd) writeOutput(
if err := fileHandler.WriteJSON(constants.ClusterIDsFileName, idFile, file.OptOverwrite); err != nil { if err := fileHandler.WriteJSON(constants.ClusterIDsFileName, idFile, file.OptOverwrite); err != nil {
return fmt.Errorf("writing Constellation ID file: %w", err) return fmt.Errorf("writing Constellation ID file: %w", err)
} }
i.log.Debugf("Wrote out Constellation ID file") i.log.Debugf("Constellation ID file written to %s", constants.ClusterIDsFileName)
if !mergeConfig { if !mergeConfig {
fmt.Fprintln(wr, "You can now connect to your cluster by executing:") fmt.Fprintln(wr, "You can now connect to your cluster by executing:")

View File

@ -95,7 +95,7 @@ func (r *recoverCmd) recover(
interval = 20 * time.Second // Azure LB takes a while to remove unhealthy instances interval = 20 * time.Second // Azure LB takes a while to remove unhealthy instances
} }
validator, err := cloudcmd.NewValidator(provider, conf) validator, err := cloudcmd.NewValidator(provider, conf, r.log)
if err != nil { if err != nil {
return err return err
} }

View File

@ -188,7 +188,7 @@ func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fileHandler file.Hand
if err := upgrade.writeConfig(conf, fileHandler, flags.configPath); err != nil { if err := upgrade.writeConfig(conf, fileHandler, flags.configPath); err != nil {
return fmt.Errorf("writing config: %w", err) return fmt.Errorf("writing config: %w", err)
} }
cmd.Println("Wrote config successfully.") cmd.Println("Config updated successfully.")
} }
return nil return nil

View File

@ -86,7 +86,7 @@ func (v *verifyCmd) verify(cmd *cobra.Command, fileHandler file.Handler, verifyC
provider := conf.GetProvider() provider := conf.GetProvider()
v.log.Debugf("Creating aTLS Validator for %s", provider) v.log.Debugf("Creating aTLS Validator for %s", provider)
validators, err := cloudcmd.NewValidator(provider, conf) validators, err := cloudcmd.NewValidator(provider, conf, v.log)
if err != nil { if err != nil {
return err return err
} }