Skip to content

Commit

Permalink
Fix hash we use for apko resolver input (#219)
Browse files Browse the repository at this point in the history
We were getting hash collisions (and files overwritten) for configs that
had the same base input but had different extra flags passed in.

Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
  • Loading branch information
jonjohnsonjr authored Jan 4, 2024
1 parent adf38c0 commit 8f88761
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/provider/config_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ func (d *ConfigDataSource) Read(ctx context.Context, req datasource.ReadRequest,
ic.Archs[i] = apkotypes.ParseArchitecture(a.ToAPK())
}

h := sha256.Sum256([]byte(data.ConfigContents.ValueString()))
input, err := yaml.Marshal(ic)
if err != nil {
resp.Diagnostics.AddError("Unable to marshal apko configuration", err.Error())
return
}

h := sha256.Sum256(input)
hash := hex.EncodeToString(h[:])

if out := os.Getenv("TF_APKO_OUT_DIR"); out != "" {
Expand Down

0 comments on commit 8f88761

Please sign in to comment.