-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sign image and attach SBOM attestation
Closes #11.
- Loading branch information
1 parent
ca5f75d
commit bee9418
Showing
13 changed files
with
154 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.ods/ | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type CosignClient struct { | ||
exe string | ||
key string | ||
} | ||
|
||
func NewCosignClient(key string) *CosignClient { | ||
return &CosignClient{exe: "cosign", key: key} | ||
} | ||
|
||
func (c *CosignClient) Sign(imageRef string) error { | ||
args := append([]string{"sign"}, c.commonArgs(imageRef)...) | ||
return c.runCmd(append(args, imageRef)...) | ||
} | ||
|
||
func (c *CosignClient) Attest(imageRef, aType, aPredicate string) error { | ||
args := append([]string{"attest"}, c.commonArgs(imageRef)...) | ||
return c.runCmd(append(args, "--type", aType, "--predicate", aPredicate, imageRef)...) | ||
} | ||
|
||
func (c *CosignClient) commonArgs(imageRef string) []string { | ||
args := []string{"--tlog-upload=false", "--key", c.key} | ||
if strings.HasPrefix(imageRef, kindRegistry) { | ||
args = append(args, "--allow-insecure-registry=true", "--allow-http-registry=true") | ||
} | ||
return args | ||
} | ||
|
||
func (c *CosignClient) runCmd(args ...string) error { | ||
cmd := exec.Command(c.exe, args...) | ||
buf := new(bytes.Buffer) | ||
cmd.Stderr = buf | ||
err := cmd.Run() | ||
if err != nil { | ||
return fmt.Errorf("cosign cmd: %s - %s", err, buf.String()) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters