-
Notifications
You must be signed in to change notification settings - Fork 497
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
Attestations from buildx #1412
Merged
Merged
Attestations from buildx #1412
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c0c9a0
chore: sort buildOptions alphabetically
jedevc f8b673e
build: pass attestation attributes to build request
jedevc f0262dd
build: add attestations to build options
jedevc b270a20
build: add attests flag and sbom/provenance shorthands
jedevc 25aa893
bake: add attests field
jedevc 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
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,76 @@ | ||
package buildflags | ||
|
||
import ( | ||
"encoding/csv" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func CanonicalizeAttest(attestType string, in string) string { | ||
if in == "" { | ||
return "" | ||
} | ||
if b, err := strconv.ParseBool(in); err == nil { | ||
return fmt.Sprintf("type=%s,enabled=%t", attestType, b) | ||
} | ||
return fmt.Sprintf("type=%s,%s", attestType, in) | ||
} | ||
|
||
func ParseAttests(in []string) (map[string]*string, error) { | ||
out := map[string]*string{} | ||
for _, in := range in { | ||
in := in | ||
attestType, enabled, err := parseAttest(in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
k := "attest:" + attestType | ||
if enabled { | ||
out[k] = &in | ||
} else { | ||
out[k] = nil | ||
} | ||
} | ||
return out, nil | ||
} | ||
|
||
func parseAttest(in string) (string, bool, error) { | ||
if in == "" { | ||
return "", false, nil | ||
} | ||
|
||
csvReader := csv.NewReader(strings.NewReader(in)) | ||
fields, err := csvReader.Read() | ||
if err != nil { | ||
return "", false, err | ||
} | ||
|
||
attestType := "" | ||
enabled := true | ||
for _, field := range fields { | ||
key, value, ok := strings.Cut(field, "=") | ||
if !ok { | ||
return "", false, errors.Errorf("invalid value %s", field) | ||
} | ||
key = strings.TrimSpace(strings.ToLower(key)) | ||
|
||
switch key { | ||
case "type": | ||
attestType = value | ||
case "enabled": | ||
enabled, err = strconv.ParseBool(value) | ||
if err != nil { | ||
return "", false, err | ||
} | ||
} | ||
} | ||
if attestType == "" { | ||
return "", false, errors.Errorf("attestation type not specified") | ||
} | ||
|
||
return attestType, enabled, nil | ||
} |
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.
Quick note to avoid confusion: we need
opt.Attests
to have some way of signalling a value that was explicitly disabled - we do that withnil
.This needs to be done here, so that we can ensure to only check the caps if we want something other than the default - otherwise, we want the
mode=min,inline-only=true
provenance to be attached on a best-effort basis, since the user hasn't explicitly opted in.