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

Release process: stage SLSA provenance metadata #2273

Merged
merged 12 commits into from
Oct 5, 2021

Conversation

puerco
Copy link
Member

@puerco puerco commented Oct 3, 2021

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds the first stage of provenance metadata generation during the staging phase of the Kubernetes release process. To push towards SLSA1 compliance, our release process needs to generate provenance metadata. This PR adds the necessary packages and functionality to make the stage phase SLSA1 compliant.

It adds a new Go package provenance which creates in-toto attestations with SLSA compliant predicates. Using the package, krel/anago now writes an attestation file with the build environment information and all artifacts from stage as subjects of the attestation.

We need to complete the chain, consuming this file and verifying in the release phase, and afterwards, produce the provenance metadata for each version we release. This PR represents roughly 2/3 of the work to make the Kubernetes release process SLSA1 compliant.

Which issue(s) this PR fixes:

Part of: #2267

Special notes for your reviewer:

This first push is the first rough iteration of the code. I will run a few tests until the provenance file is correctly staged and then remove the WIP label. I'm opening the PR now to provide an early look and visibility on the effort.

/cc @justaugustus @cpanato @Verolop @palnabarun
/cc @kubernetes/release-engineering

Does this PR introduce a user-facing change?

- **The stage phase of the Kubernetes release process is now SLSA compliant!** :tada: 
- The anago state object now registers the time the release process starts.
- We now make the GCB BUILD_ID identifier available to krel as an env var to include it in the provenance metadata.
- New go pkg: `provenance`. This new package allows projects to generate provenance metadata in in-toto attestations with SLSA compliant predicates. The new package features a scanner to easily add files as subjects in the statement.
- The `provenance` package now has tests and mocks
- The staging phase of anago which krel runs now has a new step: `GenerateProvenance()`. This step writes a provenance attestation file to make `stage` SLSA1 compliant. The file describes the building environment and adds the artifacts that will be consumed from `release` as subjects in the statement.
- The deletion of the Kubernetes source in the staging workspace is now decoupled from the `StageLocalSourceTree()` function
- `PushReleaseArtifacts()` in the build package now supports uploading single files to the release bucket. Previously only directories could be uploaded with this function.
- Optimized the artifact publishing logic to only create the Kubernetes source tarball once. Previously we tarred, compressed and uploaded the whole source tree once for each tag in the release. This is not needed as all releases share the same source.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. needs-priority cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/release-eng Issues or PRs related to the Release Engineering subproject size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/release Categorizes an issue or PR as relevant to SIG Release. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 3, 2021
@puerco puerco added this to the v1.23 milestone Oct 3, 2021
Copy link
Member

@justaugustus justaugustus left a comment

Choose a reason for hiding this comment

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

@puerco -- This is a nice treat to see over the weekend!

When you're happy with testing, we'll want to move the provenance package to sigs.k8s.io/release-sdk. Most, if not all of it, looks fit to be generally useful (as opposed to krel-specific).

@puerco
Copy link
Member Author

puerco commented Oct 3, 2021

Definitely, once it has the base features we need, I'll ship it over there. There is only one big one left to write and off it goes.

@puerco puerco force-pushed the provenance branch 2 times, most recently from 2721499 to 995ee00 Compare October 3, 2021 06:20
@justaugustus
Copy link
Member

@puerco -- Also, just to make sure we're not reinventing the wheel, can you look into https://github.com/in-toto/in-toto-golang and see if there's functionality overlap?

@justaugustus
Copy link
Member

@puerco -- Also, just to make sure we're not reinventing the wheel, can you look into https://github.com/in-toto/in-toto-golang and see if there's functionality overlap?

Yep, see similar usage in sigstore/cosign#582.
h/t @developer-guy!

@puerco
Copy link
Member Author

puerco commented Oct 3, 2021

@justaugustus originally that's where I lifted the types from, I was expecting to replicate just one or two but in the end there were more than a few. I reverted to the original code that embeds them.

@puerco puerco force-pushed the provenance branch 3 times, most recently from f6071c7 to 9e9957f Compare October 3, 2021 23:57
puerco added 4 commits October 3, 2021 18:58
The anago state now registers the beggining of stage/release as it is
needed to generate the provenance metadata.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
Add a constant for the provenance filename `provenance.json`

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
We now make the GCB BUILD_ID identifier available to krel
as an envvar to include it in the provenance metadata.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
This commit adds a new go package: provenance

This code contains the types and functions to generate provenance
metadata. It currently includes code to generate SLSA compliant
predicates and automatically scan direcories to add files as
subjects in a provenance attestation.

Signing is currently not supported but the envelope type is already
in the package for the next itearation, the push towards SLSA2 in
the Kubernetes release process.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
This commits adds testing for the provenance package. It depends on
the next commit which generates the fakes.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
@puerco puerco force-pushed the provenance branch 8 times, most recently from 8a890dd to 999bfd6 Compare October 4, 2021 04:09
puerco added 6 commits October 3, 2021 23:32
To be able to work with the source tarball, anago/stage now deletes
the source tarball after staging the rest of the artifacts.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
When running a multi-tag release (eg official + rc), krel would compress and
upload the whole kubernetes source for each version. Now, we only do it once as
the tarball is exactly the same for all release in a single run. This should
speed the release process.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
anago/stage will now generate the provenance metadata of the artifacts produced
after building. While staging the files, an in-toto attestation is built and
uploaded with the release.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
Regenerate the stage implementation fakes with the new provenance functions

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
This commit adds the new provenance functions in anago/stage to the
integration tests in TestStageArtifacts()

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
This commit modifies the function Instance.PushReleaseArtifacts() in
the build package to support pushing single files to the release buckets.

Before, PushReleaseArtifacts() would fail if applied to a single file.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
@puerco
Copy link
Member Author

puerco commented Oct 4, 2021

OK, this os ready to go! PTAL @justaugustus 🚀

That run was hacked to run faster, I'll kick off a full stage to test but it should not have any difference.

The generated metadata is in the test bucket, here:
gs://kubernetes-release-gcb/stage/v1.23.0-alpha.3.105+0ac956ff2bef9c/provenance.json

The next step will be to read that file during release and, after validation, propagate the provenance metadata in subsequent attestation files for each tag we release 🥳

@puerco puerco changed the title [WIP] Release process: stage SLSA provenance metadata Release process: stage SLSA provenance metadata Oct 4, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 4, 2021
@puerco
Copy link
Member Author

puerco commented Oct 4, 2021

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority labels Oct 4, 2021
Copy link
Member

@justaugustus justaugustus left a comment

Choose a reason for hiding this comment

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

@puerco -- Phenomenal work!

I've left a set of non-blocking comments that we should address in a follow-up.
In addition, to capture the "in-person" review we did earlier...

  1. Let's emit a SHA512 for all artifacts, not just src.tar.gz
  "subject": [
    {
      "name": "gs://kubernetes-release-gcb/stage/v1.23.0-alpha.3.105+0ac956ff2bef9c/src.tar.gz",
      "digest": {
        "sha256": "a9ac55b2fe04c940d1755bd63e0be95565930046a9f79207ac2a6b7a375788a5",
        "sha512": "d99203a4480697e5e6f5624d77a296ca8686065b6669dd25d05a6e6e389ad49b2a374fbed0697e267bf81b5fe1a3d318460186e5818ab3707204d5e86445aaa5"
      }
    },
    {
      "name": "gs://kubernetes-release-gcb/stage/v1.23.0-alpha.3.105+0ac956ff2bef9c/v1.23.0-alpha.4/gcs-stage/v1.23.0-alpha.4/SHA256SUMS",
      "digest": {
        "sha256": "71d47a3948d18f3fdee6c88ee3b254663f40be9f5598aa8841b9ab0fb78d7c60"
      }
    },
  1. In:
    "materials": [
      {
        "uri": "git+https://github.com/kubernetes/kubernetes",
        "digest": {
          "sha1": "commit 94db9bed6b7c56420e722d1b15db4610c9cacd3f"
        }
      }
    ]

Should sha1 be:

commit 94db9bed6b7c56420e722d1b15db4610c9cacd3f

OR

94db9bed6b7c56420e722d1b15db4610c9cacd3f


"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

intoto "github.com/in-toto/in-toto-golang/in_toto"
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: This should be in the previous import group

@@ -740,40 +753,53 @@ func (d *DefaultStage) GenerateBillOfMaterials() error {
}

func (d *DefaultStage) StageArtifacts() error {
// Generat the intoto attestation, reloaded with the current run data
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking:

Suggested change
// Generat the intoto attestation, reloaded with the current run data
// Generate the in-toto attestation, reloaded with the current run data

if err != nil {
return errors.Wrap(err, "generating the provenance attestation")
}
// Init a the push options we will use
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking:

Suggested change
// Init a the push options we will use
// Init push options for provenance document

Comment on lines +870 to +872
"--type=": options.ReleaseType,
"--branch=": options.ReleaseBranch,
"--build-version=": options.BuildVersion,
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking:

Suggested change
"--type=": options.ReleaseType,
"--branch=": options.ReleaseBranch,
"--build-version=": options.BuildVersion,
"release-type": options.ReleaseType,
"branch": options.ReleaseBranch,
"build-version": options.BuildVersion,

Otherwise, we get:

    "recipe": {
      "type": "https://cloudbuild.googleapis.com/CloudBuildYaml@v1",
      "definedInMaterial": 0,
      "entryPoint": "https://github.com/kubernetes/release/blob/master/gcb/stage/cloudbuild.yaml",
      "arguments": {
        "--branch=": "master",
        "--build-version=": "v1.23.0-alpha.3.105+0ac956ff2bef9c",
        "--type=": "alpha"
      }
    },

(Note the extraneous -- and = in the arguments.)

Comment on lines +874 to +876
if options.NoMock {
arguments["--nomock"] = "true"
}
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking:

(Similar to previous review comment)

Suggested change
if options.NoMock {
arguments["--nomock"] = "true"
}
if options.NoMock {
arguments["nomock"] = "true"
}

Hmmmm... do we want "true" (string) or true (bool) / does it matter?

Comment on lines +402 to 416
finfo, err := os.Stat(srcPath)
if err != nil {
return errors.Wrap(err, "checking if source path is a directory")
}

// If we are handling a single file copy instead of rsync
if !finfo.IsDir() {
return errors.Wrap(
bi.objStore.CopyToRemote(srcPath, dstPath), "copying file to GCS",
)
}

return errors.Wrap(
bi.objStore.RsyncRecursive(srcPath, dstPath), "rsync artifacts to GCS",
)
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: Let's handle "this" (dir vs file logic) in the sigs.k8s.io/release-sdk/object package instead.

)
}

// AddMaterial adds a material to the entry
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// AddMaterial adds a material to the entry
// AddMaterial adds material to the entry


type defaultPredicateImplementation struct{}

// Write dumps the predicate data into a JSON file
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Write dumps the predicate data into a JSON file
// Write dumps the predicate data as a JSON file

"errors"
"testing"

"github.com/stretchr/testify/require"
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking:

Suggested change
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"

Comment on lines +31 to +34
"github.com/pkg/errors"
"sigs.k8s.io/release-utils/hash"

intoto "github.com/in-toto/in-toto-golang/in_toto"
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: Separate import groups

Suggested change
"github.com/pkg/errors"
"sigs.k8s.io/release-utils/hash"
intoto "github.com/in-toto/in-toto-golang/in_toto"
intoto "github.com/in-toto/in-toto-golang/in_toto"
"github.com/pkg/errors"
"sigs.k8s.io/release-utils/hash"

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 5, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justaugustus, puerco

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:
  • OWNERS [justaugustus,puerco]

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

@k8s-ci-robot k8s-ci-robot merged commit eff921b into kubernetes:master Oct 5, 2021
@puerco puerco deleted the provenance branch January 2, 2022 04:14
puerco added a commit to puerco/release that referenced this pull request Jan 2, 2022
This commit addresses nits noted in kubernetes#2273.

Signed-off-by: Adolfo García Veytia <[email protected]>
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. area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants