@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "os"
2222
23+ controlplanev1 "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
2324 v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
2425 "github.com/chainloop-dev/chainloop/pkg/casclient"
2526 "github.com/chainloop-dev/chainloop/pkg/policies"
@@ -34,13 +35,14 @@ const (
3435)
3536
3637type EvalOptions struct {
37- PolicyPath string
38- MaterialKind string
39- Annotations map [string ]string
40- MaterialPath string
41- Inputs map [string ]string
42- AllowedHostnames []string
43- Debug bool
38+ PolicyPath string
39+ MaterialKind string
40+ Annotations map [string ]string
41+ MaterialPath string
42+ Inputs map [string ]string
43+ AllowedHostnames []string
44+ Debug bool
45+ AttestationClient controlplanev1.AttestationServiceClient
4446}
4547
4648type EvalResult struct {
@@ -74,7 +76,7 @@ func Evaluate(opts *EvalOptions, logger zerolog.Logger) (*EvalSummary, error) {
7476 material .Annotations = opts .Annotations
7577
7678 // 3. Verify material against policy
77- summary , err := verifyMaterial (policies , material , opts .MaterialPath , opts .Debug , opts .AllowedHostnames , & logger )
79+ summary , err := verifyMaterial (policies , material , opts .MaterialPath , opts .Debug , opts .AllowedHostnames , opts . AttestationClient , & logger )
7880 if err != nil {
7981 return nil , err
8082 }
@@ -83,18 +85,26 @@ func Evaluate(opts *EvalOptions, logger zerolog.Logger) (*EvalSummary, error) {
8385}
8486
8587func createPolicies (policyPath string , inputs map [string ]string ) (* v1.Policies , error ) {
88+ // Check if the policy path already has a scheme (chainloop://, http://, https://, file://)
89+ ref := policyPath
90+ scheme , _ := policies .RefParts (policyPath )
91+ if scheme == "" {
92+ // Default to file://
93+ ref = fmt .Sprintf ("file://%s" , policyPath )
94+ }
95+
8696 return & v1.Policies {
8797 Materials : []* v1.PolicyAttachment {
8898 {
89- Policy : & v1.PolicyAttachment_Ref {Ref : fmt . Sprintf ( "file://%s" , policyPath ) },
99+ Policy : & v1.PolicyAttachment_Ref {Ref : ref },
90100 With : inputs ,
91101 },
92102 },
93103 Attestation : nil ,
94104 }, nil
95105}
96106
97- func verifyMaterial (pol * v1.Policies , material * v12.Attestation_Material , materialPath string , debug bool , allowedHostnames []string , logger * zerolog.Logger ) (* EvalSummary , error ) {
107+ func verifyMaterial (pol * v1.Policies , material * v12.Attestation_Material , materialPath string , debug bool , allowedHostnames []string , attestationClient controlplanev1. AttestationServiceClient , logger * zerolog.Logger ) (* EvalSummary , error ) {
98108 var opts []policies.PolicyVerifierOption
99109 if len (allowedHostnames ) > 0 {
100110 opts = append (opts , policies .WithAllowedHostnames (allowedHostnames ... ))
@@ -103,7 +113,7 @@ func verifyMaterial(pol *v1.Policies, material *v12.Attestation_Material, materi
103113 opts = append (opts , policies .WithIncludeRawData (debug ))
104114 opts = append (opts , policies .WithEnablePrint (enablePrint ))
105115
106- v := policies .NewPolicyVerifier (pol , nil , logger , opts ... )
116+ v := policies .NewPolicyVerifier (pol , attestationClient , logger , opts ... )
107117 policyEvs , err := v .VerifyMaterial (context .Background (), material , materialPath )
108118 if err != nil {
109119 return nil , err
0 commit comments