Skip to content

Commit 7021c95

Browse files
committed
fix all namespace issue
1 parent bfe7a3e commit 7021c95

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

cmd/validate/image.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
322322
log.Debugf("Fetching policy source group '%s'", sourceGroup.Name)
323323
policySources := source.PolicySourcesFrom(sourceGroup)
324324

325+
// ─── DIAGNOSTIC: Log source group details ───────────────────
326+
log.Infof("DIAGNOSTIC: Creating evaluator for source group: %s", sourceGroup.Name)
327+
log.Infof("DIAGNOSTIC: Source group config: %+v", sourceGroup.Config)
328+
log.Infof("DIAGNOSTIC: Source group ruleData: %+v", sourceGroup.RuleData)
329+
// ─────────────────────────────────────────────────────────────
330+
325331
for _, policySource := range policySources {
326332
log.Debugf("policySource: %#v", policySource)
327333
}

internal/evaluator/conftest_evaluator.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ func NewConftestEvaluatorWithNamespace(ctx context.Context, policySources []sour
308308
}
309309

310310
c.include, c.exclude = computeIncludeExclude(source, p)
311+
312+
// ─── DIAGNOSTIC: Log include/exclude criteria ─────────────────────
313+
log.Infof("DIAGNOSTIC: Include criteria: %+v", c.include)
314+
log.Infof("DIAGNOSTIC: Exclude criteria: %+v", c.exclude)
315+
// ───────────────────────────────────────────────────────────────────
316+
311317
dir, err := utils.CreateWorkDir(fs)
312318
if err != nil {
313319
log.Debug("Failed to create work dir!")
@@ -432,6 +438,8 @@ func (c conftestEvaluator) Evaluate(ctx context.Context, target EvaluationTarget
432438
filters := filterFactory.CreateFilters(c.source)
433439
filteredNamespaces := filterNamespaces(rules, filters...)
434440

441+
// ──────────────────────────────────────────────────────────────────
442+
435443
var r testRunner
436444
var ok bool
437445
if r, ok = ctx.Value(runnerKey).(testRunner); r == nil || !ok {
@@ -440,14 +448,34 @@ func (c conftestEvaluator) Evaluate(ctx context.Context, target EvaluationTarget
440448
allNamespaces := true
441449
namespaceToUse := c.namespace
442450

451+
// ─── DIAGNOSTIC: Print type and value of c.namespace ───────────
452+
log.Infof("DEBUG: c.namespace type=%T value=%#v", c.namespace, c.namespace)
453+
// ───────────────────────────────────────────────────────────────
454+
443455
// If we have filtered namespaces from the filtering system, use those
444456
if len(filteredNamespaces) > 0 {
445457
namespaceToUse = filteredNamespaces
446458
allNamespaces = false
459+
log.Infof("DIAGNOSTIC: Using filtered namespaces path")
447460
} else if len(c.namespace) > 0 {
448461
allNamespaces = false
462+
log.Infof("DIAGNOSTIC: Using c.namespace path")
463+
} else {
464+
// ─── FIX: Prevent leak when no namespaces pass filtering ─────
465+
// When filteredNamespaces is empty, we should not run conftest with AllNamespaces=true
466+
// as this would evaluate ALL namespaces, bypassing our filtering.
467+
// Instead, use an empty namespace list to prevent any evaluation.
468+
namespaceToUse = []string{}
469+
allNamespaces = false
470+
log.Infof("DEBUG: Entered FIX path - this should always print if no namespaces are present")
471+
// ─────────────────────────────────────────────────────────────
449472
}
450473

474+
// ─── DIAGNOSTIC: Log namespace configuration ──────────────────
475+
log.Infof("DIAGNOSTIC: namespaceToUse = %v", namespaceToUse)
476+
log.Infof("DIAGNOSTIC: allNamespaces = %v", allNamespaces)
477+
// ───────────────────────────────────────────────────────────────
478+
451479
r = &conftestRunner{
452480
runner.TestRunner{
453481
Data: []string{c.dataDir},
@@ -461,6 +489,13 @@ func (c conftestEvaluator) Evaluate(ctx context.Context, target EvaluationTarget
461489
}
462490
}
463491

492+
// ─── DIAGNOSTIC: Log conftest runner configuration ───────────────
493+
if cr, ok := r.(*conftestRunner); ok {
494+
log.Infof("DIAGNOSTIC: Conftest runner config: Policy=%v, Namespace=%v, AllNamespaces=%v",
495+
cr.TestRunner.Policy, cr.TestRunner.Namespace, cr.TestRunner.AllNamespaces)
496+
}
497+
// ──────────────────────────────────────────────────────────────────
498+
464499
log.Debugf("runner: %#v", r)
465500
log.Debugf("inputs: %#v", target.Inputs)
466501

@@ -504,6 +539,11 @@ func (c conftestEvaluator) Evaluate(ctx context.Context, target EvaluationTarget
504539
warning := result.Warnings[i]
505540
addRuleMetadata(ctx, &warning, rules)
506541

542+
// ─── DIAGNOSTIC: Log warning result filtering ─────────────────
543+
log.Infof("DIAGNOSTIC: Warning result from namespace %s - included: %v",
544+
result.Namespace, c.isResultIncluded(warning, target.Target, missingIncludes))
545+
// ─────────────────────────────────────────────────────────────
546+
507547
if !c.isResultIncluded(warning, target.Target, missingIncludes) {
508548
log.Debugf("Skipping result warning: %#v", warning)
509549
continue
@@ -520,6 +560,11 @@ func (c conftestEvaluator) Evaluate(ctx context.Context, target EvaluationTarget
520560
failure := result.Failures[i]
521561
addRuleMetadata(ctx, &failure, rules)
522562

563+
// ─── DIAGNOSTIC: Log failure result filtering ─────────────────
564+
log.Infof("DIAGNOSTIC: Failure result from namespace %s - included: %v",
565+
result.Namespace, c.isResultIncluded(failure, target.Target, missingIncludes))
566+
// ─────────────────────────────────────────────────────────────
567+
523568
if !c.isResultIncluded(failure, target.Target, missingIncludes) {
524569
log.Debugf("Skipping result failure: %#v", failure)
525570
continue

0 commit comments

Comments
 (0)