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

[POC] Provisioner for SBOM #13171

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft

Conversation

devashish-patel
Copy link
Contributor

@devashish-patel devashish-patel commented Sep 25, 2024

Example templates:

JSON:

{
  "builders": [
    {
      "type": "docker",
      "image": "ubuntu:20.04",
      "commit": true
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "apt-get update -y",
        "apt-get install -y curl",
        "bash -c \"$(curl -sSL https://install.mondoo.com/sh)\""
      ]
    },
    {
      "type": "shell",
      "inline": [
        "cnquery sbom --output cyclonedx-json --output-target /tmp/sbom_cyclonedx.json"
      ]
    },
    {
      "type": "hcp-sbom",
      "source": "/tmp/sbom_cyclonedx.json"
    }
  ]
}

HCL:

packer {
  required_plugins {
    docker = {
      version = ">= 1.0.0"
      source  = "github.com/hashicorp/docker"
    }
  }
}

source "docker" "ubuntu" {
  image  = "ubuntu:20.04"
  commit = true
}

build {
  sources = ["source.docker.ubuntu"]

  provisioner "shell" {
    inline = [
      "apt-get update -y",
      "apt-get install -y curl",
      "bash -c \"$(curl -sSL https://install.mondoo.com/sh)\""
    ]
  }

  provisioner "shell" {
    inline = [
      //"cnquery sbom --output cyclonedx-json | tee /tmp/sbom_cyclonedx.json",
      "cnquery sbom --output cyclonedx-json --output-target /tmp/sbom_cyclonedx.json",
      "cnquery sbom --output spdx-json --output-target /tmp/sbom_spdx.json",
    ]
  }

  provisioner "hcp-sbom" {
      source      = "/tmp/sbom_cyclonedx.json"
      destination = "./sbom/sbom_cyclonedx.json"
  }

  provisioner "hcp-sbom" {
    source      = "/tmp/sbom_spdx.json"
    destination = "./sbom/sbom_spdx.json"
  }
}

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

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

Left a bunch of comments on the code, I think we can simplify the download to have it done once only, technically once we've copied the file locally for Packer, we can copy it to the user-specified destination (if specified). That or we can factorise the code for downloading since it's very similar.
I'll let you address those comments and do another pass of review after that.

packer/provisioner.go Outdated Show resolved Hide resolved
packer/provisioner.go Outdated Show resolved Hide resolved
packer/provisioner.go Outdated Show resolved Hide resolved
packer/provisioner.go Outdated Show resolved Hide resolved
packer/provisioner.go Outdated Show resolved Hide resolved
packer/build.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/provisioner.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/provisioner.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/provisioner.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/provisioner.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/validate.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/validate.go Outdated Show resolved Hide resolved
provisioner/hcp_sbom/provisioner.go Outdated Show resolved Hide resolved
packer/provisioner.go Outdated Show resolved Hide resolved
website/content/docs/provisioners/hcp-sbom.mdx Outdated Show resolved Hide resolved
website/content/docs/provisioners/hcp-sbom.mdx Outdated Show resolved Hide resolved
website/content/docs/provisioners/hcp-sbom.mdx Outdated Show resolved Hide resolved
website/content/docs/provisioners/hcp-sbom.mdx Outdated Show resolved Hide resolved
website/content/docs/provisioners/hcp-sbom.mdx Outdated Show resolved Hide resolved
website/content/docs/provisioners/hcp-sbom.mdx Outdated Show resolved Hide resolved
`destination` option in the provisioner.

Currently, we support `CycloneDX` and `SPDX` SBOM formats in `JSON`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBA: Add more details about max number of files allowed to download, and if we are going to add the file name field!

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.

2 participants