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

Container provenance #88

Merged
merged 23 commits into from
Dec 24, 2021
Merged

Container provenance #88

merged 23 commits into from
Dec 24, 2021

Conversation

marcofranssen
Copy link
Member

@marcofranssen marcofranssen commented Nov 11, 2021

resolves #73

@marcofranssen marcofranssen requested a review from a team as a code owner November 11, 2021 15:55
@marcofranssen marcofranssen marked this pull request as draft November 11, 2021 15:55
@marcofranssen marcofranssen mentioned this pull request Nov 18, 2021
3 tasks
@marcofranssen marcofranssen force-pushed the container-provenance branch 5 times, most recently from d4a0eb4 to 7c55097 Compare November 22, 2021 11:29
@marcofranssen
Copy link
Member Author

Generating the provenance works now.

$ bin/slsa-provenance generate -github_context "{… left for brevity … }" -runner_context '{}' -container_repo ghcr.io/philips-labs/slsa-provenance -container_tags 'v0.4.0 33ba3da2213c83ce02df0f2f6ba925ec79037f9d' -artifact_path README.md -container_digest sha256:194b471a878add368bf02a7935fa099024576c029491bcefaeb87f81efa093a3
Generating provenance for 'ghcr.io/philips-labs/slsa-provenance' tags:
         - v0.4.0
         - 33ba3da2213c83ce02df0f2f6ba925ec79037f9d
Saving provenance to build.provenance

$ cat build.provenance 
{
  "_type": "https://in-toto.io/Statement/v0.1",
  "subject": [
    {
      "name": "ghcr.io/philips-labs/slsa-provenance:v0.4.0",
      "digest": {
        "sha256": "194b471a878add368bf02a7935fa099024576c029491bcefaeb87f81efa093a3"
      }
    },
    {
      "name": "ghcr.io/philips-labs/slsa-provenance:33ba3da2213c83ce02df0f2f6ba925ec79037f9d",
      "digest": {
        "sha256": "194b471a878add368bf02a7935fa099024576c029491bcefaeb87f81efa093a3"
      }
    }
  ],
  "predicateType": "https://slsa.dev/provenance/v0.2",
  "predicate": {
    "builder": {
      "id": "https://github.com/philips-labs/slsa-provenance-action/Attestations/SelfHostedActions@v1"
    },
    "buildType": "https://github.com/Attestations/GitHubActionsWorkflow@v1",
    "invocation": {
      "configSource": {
        "entryPoint": "Integration test file provenance",
        "uri": "git+https://github.com/philips-labs/slsa-provenance-action",
        "digest": {
          "sha1": "c4f679f131dfb7f810fd411ac9475549d1c393df"
        }
      },
      "parameters": null,
      "environment": null
    },
    "metadata": {
      "buildInvocationId": "https://github.com/philips-labs/slsa-provenance-action/actions/runs/1332651620",
      "buildFinishedOn": "2021-11-22T15:35:01Z",
      "completeness": {
        "parameters": true,
        "environment": false,
        "materials": false
      },
      "reproducible": false
    },
    "materials": [
      {
        "uri": "git+https://github.com/philips-labs/slsa-provenance-action",
        "digest": {
          "sha1": "c4f679f131dfb7f810fd411ac9475549d1c393df"
        }
      }
    ]
  }
}

Codebase needs cleanup before merge as explained in #93 to make this more predictable.

@marcofranssen marcofranssen force-pushed the container-provenance branch 2 times, most recently from c1a49e7 to 0e46eaa Compare November 29, 2021 13:51
@codecov
Copy link

codecov bot commented Nov 29, 2021

Codecov Report

Merging #88 (204d953) into main (33a20a0) will increase coverage by 0.11%.
The diff coverage is 79.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   78.21%   78.33%   +0.11%     
==========================================
  Files          12       15       +3     
  Lines         505      623     +118     
==========================================
+ Hits          395      488      +93     
- Misses         76       95      +19     
- Partials       34       40       +6     
Flag Coverage Δ
unittests 78.33% <79.85%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/intoto/intoto.go 100.00% <ø> (ø)
cmd/slsa-provenance/cli/container.go 73.68% <73.68%> (ø)
lib/oci/registry.go 78.12% <78.12%> (ø)
lib/oci/subjects.go 80.00% <80.00%> (ø)
lib/github/provenance.go 70.49% <92.30%> (+1.38%) ⬆️
cmd/slsa-provenance/cli/files.go 93.02% <100.00%> (+0.16%) ⬆️
cmd/slsa-provenance/cli/generate.go 100.00% <100.00%> (ø)
cmd/slsa-provenance/cli/github-release.go 55.55% <100.00%> (+0.83%) ⬆️
lib/intoto/subjects.go 80.64% <100.00%> (+1.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33a20a0...204d953. Read the comment docs.

@marcofranssen marcofranssen force-pushed the container-provenance branch 2 times, most recently from 4d7e48c to a5f7cb7 Compare December 2, 2021 09:30
Makefile Outdated Show resolved Hide resolved
@marcofranssen marcofranssen force-pushed the container-provenance branch 2 times, most recently from 791aaf0 to 512b525 Compare December 2, 2021 17:34
@marcofranssen marcofranssen force-pushed the container-provenance branch 3 times, most recently from 0d8322c to 90b6047 Compare December 10, 2021 11:41
@ChaosInTheCRD
Copy link

Hey Marco! Quick question.. if a tag is specified, wouldn't it be possible to determine the digest of the image outwith the binary? and therefore no need for a parameter?

@marcofranssen marcofranssen force-pushed the container-provenance branch 3 times, most recently from 31d9068 to b6d870d Compare December 14, 2021 10:12
@marcofranssen
Copy link
Member Author

@ChaosInTheCRD I have been trying to get the image digest in various ways. The image digest is only available after pushing the image to a registry. Currently we use the approach to run the provenance in a clean Github actions runner, by running that step in a separate job to not have any side effects from prior steps.

Besides that consumers of this Github Action might have their own versioning strategy of their docker images. So in that case we do not know for which tags we have to do the provenance. Therefore I decided to take the input arguments for now, to keep that flexibility. Then my code is verifying that image digest matches up with the tags to have some kind of validation.

Totally agree this is not the cleanest and easiest approach, but it also seems docker/oci registries have a way to pull all image tags for a given digest. Preferably I would have pulled all the tags from a given repository by digest. In that case I only need 2 arguments to pull all the images by digest and have this integrated in our CLI.

@ChaosInTheCRD
Copy link

ChaosInTheCRD commented Dec 14, 2021

@marcofranssen thanks for the reply. I think the decision to allow the user to pass in the digest, and compare it (see here) against the tags provided is a good idea for validation purposes. I guess you could argue that getting the digest for the image built in the workflow is out-with the scope of the action.

@ChaosInTheCRD
Copy link

ChaosInTheCRD commented Dec 14, 2021

I am considering whether expanding this command to also include flags that allow the user to present a provenance key to sign and upload the image to the registry would be worthwhile. However, this would clash with #91

@marcofranssen
Copy link
Member Author

Once both PRs are ready I would love to reuse the signing logic and also do the attaching to docker image automagically. Just like we do with the github-release subcommand that auto uploads the provenance to the github release

@ChaosInTheCRD
Copy link

What I want to know @marcofranssen is whether the SLSA framework advocates for knitting the provenance generation, signing and uploading as close as possible.

My rationale is, if I create the provenance with slsa-provenance-action in one step, save it to disk, and then sign it and upload it in follow up steps... does that go against what is described in the "Service Generated" requirement:

The data in the provenance MUST be obtained from the build service (either because the generator is the build service or because the provenance generator reads the data directly from the build service). Regular users of the service MUST NOT be able to inject or alter the contents, except as noted below.

Maybe someone from the SLSA team could comment 😊

@ChaosInTheCRD
Copy link

Oh I see I am confused here. Does the github-release subcommand auto-upload the provenance straight after its generation? Meaning no need to save the provenance to disk?

@marcofranssen marcofranssen force-pushed the container-provenance branch 2 times, most recently from cdccf62 to 474fee8 Compare December 22, 2021 16:18
Signed-off-by: Marco Franssen <[email protected]>
marcofranssen and others added 5 commits December 24, 2021 11:59
Co-authored-by: Jeroen Knoops <[email protected]>
Signed-off-by: Marco Franssen <[email protected]>
Co-authored-by: Jeroen Knoops <[email protected]>
Signed-off-by: Marco Franssen <[email protected]>
Signed-off-by: Marco Franssen <[email protected]>
Signed-off-by: Marco Franssen <[email protected]>
@marcofranssen marcofranssen force-pushed the container-provenance branch 4 times, most recently from 7d14248 to 7b62f2c Compare December 24, 2021 14:56
@marcofranssen marcofranssen marked this pull request as ready for review December 24, 2021 15:17
Copy link
Member

@JeroenKnoops JeroenKnoops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add capability to add provenance for building docker images
3 participants