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

Add signer to CI to resign artifacts #1011

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/build.yaml.gomplate
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -556,7 +556,7 @@
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
95 changes: 95 additions & 0 deletions .github/resign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"fmt"
"github.com/mudler/luet/pkg/api/client"
"github.com/mudler/luet/pkg/api/core/types"
"github.com/mudler/luet/pkg/installer"
"io/ioutil"
"os"
"os/exec"
)

func getRepositoryPackages(repo string, ctx *types.Context) (searchResult client.SearchResult) {
tmpdir, err := ioutil.TempDir(os.TempDir(), "ci")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpdir)
referenceID := os.Getenv("REFERENCEID")
if referenceID == "" {
referenceID = "repository.yaml"
}
d := installer.NewSystemRepository(types.LuetRepository{
Name: "cOS",
Type: "docker",
Cached: true,
Urls: []string{repo},
ReferenceID: referenceID,
})
ctx.Config.GetSystem().Rootfs = "/"
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, actually if we bump the luet module now this is changed and much easier to work with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont even know what that is used for, I blindly copied it from the build.go and it didnt gave me any issues so working as intended LOL

ctx.Config.GetSystem().TmpDirBase = tmpdir
re, err := d.Sync(ctx, false)
if err != nil {
panic(err)
} else {
for _, p := range re.GetTree().GetDatabase().World() {
searchResult.Packages = append(searchResult.Packages, client.Package{
Name: p.GetName(),
Category: p.GetCategory(),
Version: p.GetVersion(),
})
}
return
}
}

func main() {
// We want to be cool and keep the same format as luet, so we create the context here to pass around and use the logging functions
ctx := types.NewContext()
finalRepo := os.Getenv("FINAL_REPO")
if finalRepo == "" {
ctx.Error("A container repository must be specified with FINAL_REPO")
os.Exit(1)
}
cosignRepo := os.Getenv("COSIGN_REPOSITORY")
if cosignRepo == "" {
ctx.Error("A signature repository must be specified with COSIGN_REPOSITORY")
os.Exit(1)
}
packages := getRepositoryPackages(finalRepo, ctx)
for _, val := range packages.Packages {
imageTag := fmt.Sprintf("%s:%s", finalRepo, val.ImageTag())
checkAndSign(imageTag, ctx)
}
return
}

func checkAndSign(tag string, ctx *types.Context) {
var fulcioFlag string

ctx.Info("Checking artifact", tag)
tmpDir, _ := os.MkdirTemp("", "sign-*")
defer os.RemoveAll(tmpDir)

_ = os.Setenv("TUF_ROOT", tmpDir) // TUF_DIR per run, we dont want to access the same files as another process
_ = os.Setenv("COSIGN_EXPERIMENTAL", "1") // Set keyless verify/sign

fulcioURL := os.Getenv("FULCIO_URL") // Allow to set a fulcio url
if fulcioURL != "" {
fulcioFlag = fmt.Sprintf("--fulcio-url=%s", fulcioURL)
}

_, err := exec.Command("cosign", "verify", tag).CombinedOutput()
if err != nil {
ctx.Warning("Artifact", tag, "has no signature, signing it")
out, err := exec.Command("cosign", fulcioFlag, "sign", tag).CombinedOutput()
if err != nil {
ctx.Error("Error signing", tag, ":", string(out))
} else {
ctx.Success("Artifact", tag, "signed")
}
} else {
ctx.Success("Artifact", tag, "has signature")
}
}
4 changes: 2 additions & 2 deletions .github/workflows/build-master-blue-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-master-blue-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-master-green-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -471,7 +471,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-master-green-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -688,7 +688,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-master-orange-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-master-orange-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-nightly-blue-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-nightly-green-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-nightly-orange-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr-blue-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr-blue-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr-green-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr-green-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr-orange-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr-orange-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-releases-blue-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-releases-blue-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-releases-green-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -471,7 +471,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-releases-green-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -688,7 +688,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-releases-orange-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
export PATH=$PATH:/usr/local/go/bin
mkdir build || true
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
run: |
export PATH=$PATH:/usr/local/go/bin
pushd ./.github
go build -o build
go build -o build build.go
popd
sudo -E ./.github/build
ls -liah $PWD/build
Expand Down
Loading