Skip to content

Commit f0b016e

Browse files
authored
Protect emitting of confidential information (#65)
1 parent 878de21 commit f0b016e

3 files changed

Lines changed: 44 additions & 13 deletions

File tree

internal/deployer/deploy_via_helm.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"gopkg.in/yaml.v3"
1313

14+
"github.com/stackrox/roxie/internal/env"
1415
"github.com/stackrox/roxie/internal/helpers"
1516
)
1617

@@ -54,8 +55,12 @@ func (d *Deployer) deployCentralHelm(ctx context.Context, resources, exposure st
5455
valuesFile.Close()
5556

5657
if d.verbose {
57-
d.logger.Dim("Central values YAML:")
58-
d.logger.Dim(helmValuesYaml)
58+
if env.RunningInteractively {
59+
d.logger.Dim("Central values YAML:")
60+
d.logger.Dim(helmValuesYaml)
61+
} else {
62+
d.logger.Dim("Skipping emitting Central values in non-interactive mode, because it could leak confidential information")
63+
}
5964
}
6065

6166
if err := d.verifyHelmChartImages(ctx, chartDir, valuesFile.Name()); err != nil {
@@ -143,8 +148,12 @@ func (d *Deployer) deploySecuredClusterHelm(ctx context.Context, resources strin
143148
crsFile.Close()
144149

145150
if d.verbose {
146-
d.logger.Dim("SecuredCluster values YAML:")
147-
d.logger.Dim(helmValuesYaml)
151+
if env.RunningInteractively {
152+
d.logger.Dim("SecuredCluster values YAML:")
153+
d.logger.Dim(helmValuesYaml)
154+
} else {
155+
d.logger.Dim("Skipping emitting SecuredCluster values in non-interactive mode, because it could leak confidential information")
156+
}
148157
}
149158

150159
if err := d.ensureNamespaceExists(d.sensorNamespace); err != nil {

internal/deployer/deploy_via_operator.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,12 @@ func (d *Deployer) applyCentralCR(ctx context.Context, cr map[string]interface{}
408408
}
409409

410410
if d.verbose {
411-
d.logger.Dim("Central CR YAML:")
412-
d.logger.Dim(string(yamlData))
411+
if env.RunningInteractively {
412+
d.logger.Dim("Central CR YAML:")
413+
d.logger.Dim(string(yamlData))
414+
} else {
415+
d.logger.Dim("Skipping emitting Central CR in non-interactive mode, because it could leak confidential information")
416+
}
413417
}
414418

415419
result, err := d.runKubectl(ctx, KubectlOptions{
@@ -486,7 +490,11 @@ func (d *Deployer) waitForLoadBalancer(ctx context.Context, namespace, serviceNa
486490
if err == nil && result.Stdout != "" {
487491
ip := strings.TrimSpace(result.Stdout)
488492
if ip != "" && ip != "<pending>" {
489-
d.logger.Successf("✓ LoadBalancer IP: %s", ip)
493+
if env.RunningInteractively {
494+
d.logger.Successf("✓ LoadBalancer IP: %s", ip)
495+
} else {
496+
d.logger.Success("✓ LoadBalancer IP")
497+
}
490498
return fmt.Sprintf("https://%s:443", ip), nil
491499
}
492500
}
@@ -498,7 +506,11 @@ func (d *Deployer) waitForLoadBalancer(ctx context.Context, namespace, serviceNa
498506
if err == nil && result.Stdout != "" {
499507
hostname := strings.TrimSpace(result.Stdout)
500508
if hostname != "" && hostname != "<pending>" {
501-
d.logger.Successf("✓ LoadBalancer hostname: %s", hostname)
509+
if env.RunningInteractively {
510+
d.logger.Successf("✓ LoadBalancer hostname: %s", hostname)
511+
} else {
512+
d.logger.Success("✓ LoadBalancer hostname")
513+
}
502514
return fmt.Sprintf("https://%s:443", hostname), nil
503515
}
504516
}
@@ -580,8 +592,10 @@ func (d *Deployer) configureCentralEndpoint(ctx context.Context, exposure string
580592
d.logger.Warningf("Could not fetch CA cert: %v", err)
581593
}
582594

583-
d.logger.Successf("✓ Central is ready at: %s", d.centralEndpoint)
584-
d.logger.Successf("✓ Admin password: %s", d.centralPassword)
595+
if env.RunningInteractively {
596+
d.logger.Successf("✓ Central is ready at: %s", d.centralEndpoint)
597+
d.logger.Successf("✓ Admin password: %s", d.centralPassword)
598+
}
585599

586600
return nil
587601
}
@@ -743,8 +757,12 @@ func (d *Deployer) applySecuredClusterCR(ctx context.Context, cr map[string]inte
743757
}
744758

745759
if d.verbose {
746-
d.logger.Dim("SecuredCluster CR YAML:")
747-
d.logger.Dim(string(yamlData))
760+
if env.RunningInteractively {
761+
d.logger.Dim("SecuredCluster CR YAML:")
762+
d.logger.Dim(string(yamlData))
763+
} else {
764+
d.logger.Dim("Skipping emitting SecuredCluster CR in non-interactive mode, because it could leak confidential information")
765+
}
748766
}
749767

750768
result, err := d.runKubectl(ctx, KubectlOptions{

internal/deployer/deployer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,11 @@ func (d *Deployer) WaitForCentral(timeout time.Duration) bool {
826826
return false
827827
}
828828

829-
d.logger.Infof("⏳ Waiting for Central to be ready at %s (timeout: %v)", d.centralEndpoint, timeout)
829+
if env.RunningInteractively {
830+
d.logger.Infof("⏳ Waiting for Central to be ready at %s (timeout: %v)", d.centralEndpoint, timeout)
831+
} else {
832+
d.logger.Infof("⏳ Waiting for Central to be ready (timeout: %v)", timeout)
833+
}
830834

831835
deadline := time.Now().Add(timeout)
832836
checkInterval := 5 * time.Second

0 commit comments

Comments
 (0)