Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(attestation): change default to NOT download cosign outside of setup flow #49

Merged
merged 7 commits into from
Oct 11, 2023
10 changes: 7 additions & 3 deletions src/attestation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import api, base64, chalkjson, config, httpclient, net, os, selfextract,
const
attestationObfuscator = staticExec(
"dd status=none if=/dev/random bs=1 count=16 | base64").decode()
cosignLoader = "load_attestation_binary() -> string"
cosignLoader = "load_attestation_binary(bool) -> string"
#c4mAttest = "push_attestation(string, string, string) -> bool"

var
Expand Down Expand Up @@ -217,9 +217,13 @@ proc loadFromSecretManager*(prkey: string, apikey: string): bool =

return true

proc getCosignLocation*(): string =
proc getCosignLocation*(downloadCosign = false): string =
once:
cosignLoc = unpack[string](runCallback(cosignLoader, @[]).get())
var args = @[pack(false)]
if downloadCosign == true:
args = @[pack(true)]
MyNameIsMeerkat marked this conversation as resolved.
Show resolved Hide resolved

cosignLoc = unpack[string](runCallback(cosignLoader, args).get())

if cosignLoc == "":
warn("Could not find or install cosign; cannot sign or verify.")
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_setup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ proc runCmdSetup*(gen, load: bool) =
selfChalk.addToAllChalks()
info("Ensuring cosign is present to setup attestation.")

if getCosignLocation() == "":
if getCosignLocation(downloadCosign = true) == "":
quitChalk(1)
if load:
# If we fall back to 'gen' we don't want attemptToLoadKeys
Expand Down
6 changes: 4 additions & 2 deletions src/configs/attestation.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func install_cosign() {
go_path := find_exe("go", [])

if go_path != "" {
info("Go-install'ing cosign.....")
install_out, ok := system("go install github.com/sigstore/cosign/v2/cmd/cosign@latest")
if ok != 0 {
warn("unable to install attestation into $GOPATH/bin/cosign; " +
Expand All @@ -37,6 +38,7 @@ func install_cosign() {

install_name := "cosign-" + host_os + "-" + host_arch
install_url := "https://github.com/sigstore/cosign/releases/latest/download/" + install_name
info("Downloading cosign.....")
contents := url_get(install_url)

trace("Downloaded cosign.")
Expand All @@ -54,12 +56,12 @@ func install_cosign() {
return false
}

func load_attestation_binary() {
func load_attestation_binary(download_if_not_present: bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The : bool there should be redundant; I'd expect it to be inferred from the body since the body is unambiguous, but let me know if it does break (it certainly is fine to be explicit about the type here, I don't
think this needs to change).

result := ""
supplemental_path := [env("GOPATH") + "/bin", "~/go/bin", "/tmp"]
attestation_binary := find_exe("cosign", supplemental_path)

if attestation_binary == "" {
if attestation_binary == "" and download_if_not_present == true {
if install_cosign() {
attestation_binary := find_exe("cosign", supplemental_path)
if attestation_binary == "" {
Expand Down