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

Handle duplicates in subjects and materials consistently #926

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

chuangw6
Copy link
Member

Changes

/kind bug

Fixes #925

Prior, deduplication handling for subjects and materials is different.

Now, we use consistent approach to handle the deduplication.

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

Release Notes

NONE

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 15, 2023
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 15, 2023
@chuangw6
Copy link
Member Author

cc @lcarva could we possibly include this fix in the upcoming release? Thanks a lot!

@chuangw6 chuangw6 force-pushed the deduplication branch 2 times, most recently from a1a6b6e to 193d493 Compare September 15, 2023 21:45
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-chains-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/chains/formats/slsa/extract/extract.go 69.1% 61.5% -7.6
pkg/chains/formats/slsa/internal/artifact/append.go Do not exist 100.0%
pkg/chains/formats/slsa/internal/material/material.go 91.2% 92.2% 1.0

@chuangw6
Copy link
Member Author

This failure seems like a flaky unit test 😮

func TestBuildConfigSource(t *testing.T) {
provenance := &v1beta1.Provenance{
RefSource: &v1beta1.RefSource{
Digest: map[string]string{"alg1": "hex1", "alg2": "hex2"},
URI: "https://tekton.com",
EntryPoint: "/path/to/entry",
},
}
want := map[string]string{
"ref": "alg1:hex1",
"repository": "https://tekton.com",
"path": "/path/to/entry",
}
got := buildConfigSource(provenance)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("buildConfigSource(): -want +got: %s", diff)
}
}

In the implementation, it always gets the first entry in the map and the unit test assumes it's always the first entry in the test map. But golang maps are unordered data structure, so the first entry is non-deterministic. That's why the test is flaky.

cc @joejstuart

@joejstuart
Copy link
Contributor

This failure seems like a flaky unit test 😮

func TestBuildConfigSource(t *testing.T) {
provenance := &v1beta1.Provenance{
RefSource: &v1beta1.RefSource{
Digest: map[string]string{"alg1": "hex1", "alg2": "hex2"},
URI: "https://tekton.com",
EntryPoint: "/path/to/entry",
},
}
want := map[string]string{
"ref": "alg1:hex1",
"repository": "https://tekton.com",
"path": "/path/to/entry",
}
got := buildConfigSource(provenance)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("buildConfigSource(): -want +got: %s", diff)
}
}

In the implementation, it always gets the first entry in the map and the unit test assumes it's always the first entry in the test map. But golang maps are unordered data structure, so the first entry is non-deterministic. That's why the test is flaky.

cc @joejstuart

I'm unsure why the implementation only wants the first entry. It's existing code I moved. I'm wondering if we should just copy the whole provenance.RefSource to externalParams["buildConfigSource"]?

 // PipelineRun adds the pipeline run spec and provenance if available
 func PipelineRun(pro *objects.PipelineRunObject) map[string]any {
        externalParams := make(map[string]any)
 
        if provenance := pro.GetRemoteProvenance(); provenance != nil {
-               externalParams["buildConfigSource"] = buildConfigSource(provenance)
+               externalParams["buildConfigSource"] = provenance.RefSource
        }
        externalParams["runSpec"] = pro.Spec
        return externalParams

@chuangw6
Copy link
Member Author

That's a good idea, but currently slsa defines the ref field for other ci/cd as string i.e. workflow.ref for github

Maybe something we can flag to slsa team in this generic proposal? slsa-framework/slsa#940

cc @chitrangpatel for thoughts.

@chitrangpatel
Copy link
Contributor

That's a good idea, but currently slsa defines the ref field for other ci/cd as string i.e. workflow.ref for github

Maybe something we can flag to slsa team in this generic proposal? slsa-framework/slsa#940

cc @chitrangpatel for thoughts.

I think we should add it to the generic propossal. RefSource is a very Tekton Specific field. I think a more generic format for cicd based systems will be more useful for verifiers.

@joejstuart
Copy link
Contributor

joejstuart commented Sep 18, 2023

That's a good idea, but currently slsa defines the ref field for other ci/cd as string i.e. workflow.ref for github
Maybe something we can flag to slsa team in this generic proposal? slsa-framework/slsa#940
cc @chitrangpatel for thoughts.

I think we should add it to the generic propossal. RefSource is a very Tekton Specific field. I think a more generic format for cicd based systems will be more useful for verifiers.

Here's a test that should work. #928.

+1 for adding the whole RefSource to the generic proposal.

Fixes tektoncd#925

Prior, deduplication handling for subjects and materials is different.

Now, we use consistent approach to handle the deduplication.

Signed-off-by: Chuang Wang <[email protected]>
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-chains-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/chains/formats/slsa/extract/extract.go 69.1% 61.5% -7.6
pkg/chains/formats/slsa/internal/artifact/append.go Do not exist 100.0%
pkg/chains/formats/slsa/internal/material/material.go 91.2% 92.2% 1.0

@chitrangpatel
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2023
@chitrangpatel
Copy link
Contributor

Thanks @chuangw6!

@chitrangpatel
Copy link
Contributor

/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chitrangpatel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 10, 2023
@tekton-robot tekton-robot merged commit b41436b into tektoncd:main Oct 10, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent deduplication handing in subjects and materials
4 participants