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

Revert "fix: add SBOM and S3 caching secrets" #321

Merged
merged 1 commit into from
Mar 5, 2025
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
buf.build/gen/go/depot/api/protocolbuffers/go v1.32.0-20240221184445-e8316610338f.1
connectrpc.com/connect v1.15.0
github.com/adrg/xdg v0.4.0
github.com/aws/aws-sdk-go-v2/config v1.15.5
github.com/briandowns/spinner v1.18.1
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
Expand Down Expand Up @@ -65,6 +64,7 @@ require (
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aws/aws-sdk-go-v2 v1.16.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.15.5 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.10 // indirect
Expand Down
71 changes: 0 additions & 71 deletions pkg/buildx/bake/buildflags/cache.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package buildflags

import (
"context"
"encoding/csv"
"encoding/json"
"maps"
"os"
"strconv"
"strings"

awsconfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/moby/buildkit/client"
"github.com/pkg/errors"
"github.com/zclconf/go-cty/cty"
Expand Down Expand Up @@ -187,9 +183,6 @@ func CreateCaches(entries []*CacheOptionsEntry) []client.CacheOptionsEntry {
return nil
}
for _, entry := range entries {
addGithubToken(entry)
addAwsCredentials(entry)

out := client.CacheOptionsEntry{
Type: entry.Type,
Attrs: map[string]string{},
Expand All @@ -201,67 +194,3 @@ func CreateCaches(entries []*CacheOptionsEntry) []client.CacheOptionsEntry {
}
return outs
}

func addGithubToken(ci *CacheOptionsEntry) {
if ci.Type != "gha" {
return
}
version, ok := ci.Attrs["version"]
if !ok {
// https://github.com/actions/toolkit/blob/2b08dc18f261b9fdd978b70279b85cbef81af8bc/packages/cache/src/internal/config.ts#L19
if v, ok := os.LookupEnv("ACTIONS_CACHE_SERVICE_V2"); ok {
if b, err := strconv.ParseBool(v); err == nil && b {
version = "2"
}
}
}
if _, ok := ci.Attrs["token"]; !ok {
if v, ok := os.LookupEnv("ACTIONS_RUNTIME_TOKEN"); ok {
ci.Attrs["token"] = v
}
}
if _, ok := ci.Attrs["url_v2"]; !ok && version == "2" {
// https://github.com/actions/toolkit/blob/2b08dc18f261b9fdd978b70279b85cbef81af8bc/packages/cache/src/internal/config.ts#L34-L35
if v, ok := os.LookupEnv("ACTIONS_RESULTS_URL"); ok {
ci.Attrs["url_v2"] = v
}
}
if _, ok := ci.Attrs["url"]; !ok {
// https://github.com/actions/toolkit/blob/2b08dc18f261b9fdd978b70279b85cbef81af8bc/packages/cache/src/internal/config.ts#L28-L33
if v, ok := os.LookupEnv("ACTIONS_CACHE_URL"); ok {
ci.Attrs["url"] = v
} else if v, ok := os.LookupEnv("ACTIONS_RESULTS_URL"); ok {
ci.Attrs["url"] = v
}
}
}

func addAwsCredentials(ci *CacheOptionsEntry) {
if ci.Type != "s3" {
return
}
_, okAccessKeyID := ci.Attrs["access_key_id"]
_, okSecretAccessKey := ci.Attrs["secret_access_key"]
// If the user provides access_key_id, secret_access_key, do not override the session token.
if okAccessKeyID && okSecretAccessKey {
return
}
ctx := context.TODO()
awsConfig, err := awsconfig.LoadDefaultConfig(ctx)
if err != nil {
return
}
credentials, err := awsConfig.Credentials.Retrieve(ctx)
if err != nil {
return
}
if !okAccessKeyID && credentials.AccessKeyID != "" {
ci.Attrs["access_key_id"] = credentials.AccessKeyID
}
if !okSecretAccessKey && credentials.SecretAccessKey != "" {
ci.Attrs["secret_access_key"] = credentials.SecretAccessKey
}
if _, ok := ci.Attrs["session_token"]; !ok && credentials.SessionToken != "" {
ci.Attrs["session_token"] = credentials.SessionToken
}
}
2 changes: 1 addition & 1 deletion pkg/buildx/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
supportsAttestations := true
if len(attests) > 0 {
for k, v := range attests {
so.FrontendAttrs["attest:"+k] = v
so.FrontendAttrs[k] = v
}
}
if _, ok := opt.Attests["attest:provenance"]; !ok && supportsAttestations {
Expand Down
8 changes: 3 additions & 5 deletions pkg/helpers/gha.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import "os"
func FixGitHubActionsCacheEnv() {
original := os.Getenv("UPSTREAM_ACTIONS_CACHE_URL")

if original != "" {
os.Setenv("ACTIONS_CACHE_URL", original)
if original == "" {
original = os.Getenv("GACTIONSCACHE_URL")
}

original = os.Getenv("UPSTREAM_ACTIONS_RESULTS_URL")

if original != "" {
os.Setenv("ACTIONS_RESULTS_URL", original)
os.Setenv("ACTIONS_CACHE_URL", original)
}
}
Loading