-
Notifications
You must be signed in to change notification settings - Fork 54
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,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 = "/" | ||
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") | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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