Skip to content
Closed
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
43 changes: 1 addition & 42 deletions internal/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package internal

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

policyManager "github.com/compliance-framework/agent/policy-manager"
Expand Down Expand Up @@ -117,10 +114,6 @@ func (pe *PolicyEvaluator) Eval(ctx context.Context, cert CertificateContext, po
}

for _, policyPath := range policyPaths {
rootData, err := loadBundleRootData(policyPath, policyData)
if err != nil {
return nil, fmt.Errorf("loading bundle data for %s: %w", policyPath, err)
}
processor := policyManager.NewPolicyProcessor(
pe.logger,
labels,
Expand All @@ -129,7 +122,7 @@ func (pe *PolicyEvaluator) Eval(ctx context.Context, cert CertificateContext, po
inventory,
actors,
pe.stepActivities,
rootData,
policyData,
)

evidence, perr := processor.GenerateResults(ctx, policyPath, input)
Expand All @@ -153,40 +146,6 @@ func certificateBaseLabels() map[string]string {
}
}

// loadBundleRootData reads data.json from the OPA bundle root and merges it
// with base. When the agent downloads a policy OCI artifact it returns the
// policies/ subdirectory as policyPath; the bundle's data.json lives one level
// up in the bundle root. For local source trees the data.json lives inside the
// policies/ directory itself, so we check both locations.
func loadBundleRootData(policyPath string, base map[string]interface{}) (map[string]interface{}, error) {
candidates := []string{
filepath.Join(filepath.Dir(policyPath), "data.json"),
filepath.Join(policyPath, "data.json"),
}
for _, p := range candidates {
raw, err := os.ReadFile(p)
if errors.Is(err, os.ErrNotExist) {
continue
}
if err != nil {
return nil, fmt.Errorf("reading bundle data %s: %w", p, err)
}
var bundleData map[string]interface{}
if err := json.Unmarshal(raw, &bundleData); err != nil {
return nil, fmt.Errorf("parsing bundle data %s: %w", p, err)
}
merged := make(map[string]interface{}, len(bundleData)+len(base))
for k, v := range bundleData {
merged[k] = v
}
for k, v := range base {
merged[k] = v
}
return merged, nil
}
return base, nil
}

// arnCertID extracts the certificate UUID from an ACM ARN.
// ARN format: arn:aws:acm:<region>:<account-id>:certificate/<uuid>
func arnCertID(arn string) string {
Expand Down
Loading