@@ -18,6 +18,9 @@ package image
1818
1919import (
2020 "context"
21+ "encoding/json"
22+ "errors"
23+ "io/ioutil"
2124
2225 conftestOutput "github.com/open-policy-agent/conftest/output"
2326 log "github.com/sirupsen/logrus"
@@ -73,6 +76,20 @@ func ValidateImage(ctx context.Context, imageRef, policyConfiguration, publicKey
7376 return nil , err
7477 }
7578
79+ attStatements := make ([]attestation , 0 , len (a .Attestations ()))
80+ for _ , att := range a .Attestations () {
81+ attStatement , err := SignatureToAttestation (ctx , att )
82+ if err != nil {
83+ return nil , err
84+ }
85+ attStatements = append (attStatements , attStatement )
86+ }
87+
88+ commitFile := "/tmp/commit.json"
89+ writeCommitData (attStatements , commitFile )
90+
91+ inputs = append (inputs , commitFile )
92+
7693 results , err := a .Evaluator .Evaluate (ctx , inputs )
7794
7895 if err != nil {
@@ -85,3 +102,33 @@ func ValidateImage(ctx context.Context, imageRef, policyConfiguration, publicKey
85102
86103 return out , nil
87104}
105+
106+ func writeCommitData (attestations []attestation , commitFile string ) error {
107+ payloads := make ([]string , 0 , len (attestations ))
108+ for _ , att := range attestations {
109+ signoffSource , err := att .NewSignOffSource ()
110+ if err != nil {
111+ return err
112+ }
113+ if signoffSource == nil {
114+ return errors .New ("there is no signoff source in attestation" )
115+ }
116+
117+ signOff , err := signoffSource .GetSignOff ()
118+ if err != nil {
119+ return err
120+ }
121+
122+ if signOff != nil {
123+ payload , err := json .MarshalIndent (signOff , "" , " " )
124+ if err != nil {
125+ return err
126+ }
127+ payloads = append (payloads , string (payload ))
128+ }
129+ }
130+
131+ payloadJson , _ := json .Marshal (payloads )
132+ _ = ioutil .WriteFile (commitFile , payloadJson , 0644 )
133+ return nil
134+ }
0 commit comments