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

Backport missing SBOM docs to stable-website #13274

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
2e42761
backport of commit 47b7813def7bd477ac64fc037bbd0f5b96de9fe6
lbajolet-hashicorp May 30, 2024
acb4219
backport of commit 9079371765c395d8c7d783744a5b4863ec481158
lbajolet-hashicorp May 30, 2024
556876c
Merge pull request #13003 from hashicorp/backport/bump_changelog_1.11…
hc-github-team-packer May 30, 2024
4b1e82f
backport of commit f06612d846b1318994756ca7c1341b19f433cbb4
lbajolet-hashicorp May 30, 2024
10febf4
backport of commit b23c7af217345b70bcf06727175d59c7d6dadf92
trujillo-adam May 24, 2024
ff4a472
backport of commit d52159953c0e64929546511c80607994236c2bca
trujillo-adam May 24, 2024
aed9b48
backport of commit 7faf8bc1946dca642fa38e3c545e654a33e6e2ea
trujillo-adam May 24, 2024
f828d3d
backport of commit 4dd5f818fb748ed7b787e9568897a338c5a0f218
trujillo-adam May 24, 2024
41c092f
backport of commit b78b9a43f502ab878b81b85cbd482281f15833d0
trujillo-adam May 24, 2024
043d4f0
backport of commit 54a45f1acf56b9c917f92b9d49d8ded5fb3f7706
trujillo-adam May 24, 2024
46c6b29
backport of commit e6ea5d0900565410bed8b4cf1631f961b2ddec84
trujillo-adam May 24, 2024
5cb18b0
backport of commit d60bb25687b138ae824c01f5ce77c60e4af75a1f
trujillo-adam May 24, 2024
dbc716a
backport of commit e6a40238f76701877d6d3a8bddfb470c9a4c3c60
trujillo-adam May 24, 2024
a7ecbb7
backport of commit 5ba4f885e44d4aec346069113999e1fde3830039
trujillo-adam May 24, 2024
2450204
backport of commit 0cdaab6474cfd241f6b882f551706abdf514e649
trujillo-adam May 24, 2024
45f2d01
backport of commit bb83c82d4895267443ddbcd48930ae54dcc1f961
trujillo-adam May 24, 2024
5f02f37
backport of commit 3eb6e1ebe50a1fd492c605a9a7ec9a9a7e45e47b
trujillo-adam May 28, 2024
6a05d3c
backport of commit 9e7078dbb70002e7751e1a96982d607401710805
trujillo-adam May 28, 2024
49ce239
backport of commit 8796c74d71e6f4cfddfa86358cccad8ec89d29a8
trujillo-adam May 28, 2024
848cb91
backport of commit 05696b6d087cf5e4f5c36bdb2a83567fc608eec3
trujillo-adam May 28, 2024
43acf99
backport of commit 6db692bffc7d2e25dba3604b3550cb1b67a44724
trujillo-adam May 28, 2024
71b12ea
backport of commit e878cac25de5a74db14c6f3e569cd992ba453b1e
trujillo-adam May 29, 2024
355de63
backport of commit 61b2cda4962e358f6d321920b6a4e4f5c363182f
trujillo-adam May 29, 2024
0611a8e
backport of commit a61220a8a6d13a9b05d369719a384af5c1fc9ee9
lbajolet-hashicorp May 30, 2024
d11a0e9
Merge pull request #13005 from hashicorp/backport/script_prep_changel…
hc-github-team-packer May 31, 2024
17942cd
backport of commit 2cd68ee99e307ddce5cdf263059a5495ae15da60
nywilken May 31, 2024
8bbfa7b
version: cut release 1.11.0
lbajolet-hashicorp May 30, 2024
097c3a4
Merge pull request #13007 from hashicorp/backport/bump-1.11-release-d…
hc-github-team-packer May 31, 2024
4ec49bf
backport of commit db28daa33f3613b06354c593fd51965157801f38
SKalt May 31, 2024
bb5cdbe
backport of commit db28daa33f3613b06354c593fd51965157801f38
SKalt May 31, 2024
fd40b14
Merge pull request #13010 from hashicorp/backport/patch-1/slowly-suit…
hc-github-team-packer May 31, 2024
aecec97
Merge pull request #13011 from hashicorp/backport/patch-1/vastly-ace-…
hc-github-team-packer May 31, 2024
87fdd82
backport of commit 187ed85c5c2ee58f5f234da5314e2e42e6bc77df
trujillo-adam May 31, 2024
2fb88ca
backport of commit b5618bf82ff0391666c56ecc47c4da64d3117064
trujillo-adam May 31, 2024
62897e9
backport of commit f7e9ed4732d2ed3d87264c5250dd13c1f605c62e
May 31, 2024
4ee3ed6
backport of commit 47a92575d3006b909dd466299d56b2090993652d
May 31, 2024
ad61b9b
Merge pull request #13012 from hashicorp/backport/docs/install-plugin…
hc-github-team-packer May 31, 2024
a3cf9e1
backport of commit c2219bdf740d7aa64942e8397f23c77ef2a950e6
graevy Jun 6, 2024
0d5435b
backport of commit 309c4528af8c9aadd44a85dfcdb9d140cfb1e279
lbajolet-hashicorp Jun 6, 2024
03a1e08
backport of commit 50106ce90fd82d99274625faa2bf9281a1707455
Jun 6, 2024
7c2c83a
backport of commit cf4a6016c9eaf73525bc5acd0e4b9cc81bf94ac1
nywilken Jun 6, 2024
fa04308
Merge pull request #13029 from hashicorp/backport/plugin_load_spec_do…
hc-github-team-packer Jun 10, 2024
2bae376
backport of commit 27ec05bc9fa3c7645f7ca930d606aed18ca14261
tenthirtyam Jun 13, 2024
584b06d
backport of commit 71c1afa767e2db8fafef8885e222b70438464764
tenthirtyam Jun 13, 2024
e840cd8
backport of commit 8ba0485a8b0ddd586f3ea8c167c01bf2cc42980b
tenthirtyam Jun 13, 2024
90ed76f
Merge pull request #13045 from hashicorp/backport/docs/packer-init/he…
hc-github-team-packer Jun 13, 2024
fe82cbe
Merge pull request #13047 from hashicorp/backport/docs/update-ssh/mis…
hc-github-team-packer Jun 13, 2024
4dff797
backport of commit 75c5c78c8190a85becdb73ac805b720f24077202
tenthirtyam Jun 13, 2024
a298137
Merge pull request #13050 from hashicorp/backport/docs/string-templat…
hc-github-team-packer Jun 14, 2024
c45287d
Merge pull request #13052 from hashicorp/backport/doca/update-provisi…
hc-github-team-packer Jun 17, 2024
eba16fb
backport of commit bd39423be54d7e01c216c7e5ead74503c9253e01
nywilken Jun 17, 2024
7c7693e
backport of commit bab3f16513d7d2c95e75733f6aea9f1b380f12f2
Jun 17, 2024
4334874
Merge pull request #13057 from hashicorp/backport/nywilken.document-t…
hc-github-team-packer Jun 17, 2024
3393ea4
backport of commit 9ecb83e805a35383d924031d4719b861770e5d5a
nywilken Jun 21, 2024
84cc8a5
backport of commit 89b1d57f34639537eb8504f4b2c67b4a7d5c5cbf
nywilken Jun 21, 2024
695998c
Merge pull request #13067 from hashicorp/backport/patch-1/completely-…
hc-github-team-packer Jun 21, 2024
834fdbf
backport of commit b43f004d53eee846a599d44664287c6b3db44675
lbajolet-hashicorp Aug 7, 2024
0b58c66
backport of commit 6e54a4dc9edec0c64d59b9e9602b8656dbf26e9b
lbajolet-hashicorp Aug 7, 2024
6a52193
Merge pull request #13138 from hashicorp/backport/docs_update_manual_…
hc-github-team-packer Aug 8, 2024
4ec9f6e
backport of commit 0f20ff52af496eeb7b36b7650c98934869c52a33
freggy Sep 29, 2024
bc88df5
Merge pull request #13179 from hashicorp/backport/s3-community-provis…
hc-github-team-packer Oct 7, 2024
be6d982
backport of commit 90022dcabbf19485223c34f4f246d8dfd68ff83e
DevopsMercenary Oct 12, 2024
be42248
Merge pull request #13185 from hashicorp/backport/patch-1/centrally-c…
hc-github-team-packer Oct 15, 2024
45fc579
Add missing dash on `recursive` `fmt` command
laurentgoudet Oct 16, 2024
97e9be0
docs: add upgrade/release notes for 1.12.0
lbajolet-hashicorp Jan 23, 2025
04695fd
website: add docs for the hcp-sbom provisioner
devashish-patel Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.11.0 (Upcoming)
## 1.11.0 (2024-05-31)

### NOTES:
* A LICENSE.txt file has been added to the Packer release artifacts.
Expand Down Expand Up @@ -31,20 +31,34 @@
* Packer users can now track Packer version and plugin versions used for each
build artifact in HCP Packer.
[GH-12866](https://github.com/hashicorp/packer/pull/12866)

* hcl2: add textencodebase64 and textdecodebase64 funcs
For feature parity with Terraform, and since having access to strings
encoded in something that is not UTF-8 is required in some cases, we add
both the textencodebase64 and textdecodebase64 functions to HCL2 templates.
Please note these functions return base64 encoded byte slices because of how
cty/hcl defines strings (NFC normalised, UTF-8 encoded).
[GH-12997](https://github.com/hashicorp/packer/pull/12997)

### SECURITY:
* Bump github.com/go-jose/go-jose/v3 to address GHSA-c5q2-7r4c-mv6g.
[GH-12880](https://github.com/hashicorp/packer/pull/12880)
* Bump golang.org/x/net to v0.24.0 to address GO-2024-2687.
[GH-12924](https://github.com/hashicorp/packer/pull/12924)


### IMPROVEMENTS:
* core: Bump github.com/hashicorp/hcp-sdk-go from 0.90.0 to 0.92.0.
* core: Bump github.com/hashicorp/hcp-sdk-go from 0.90.0 to 0.96.0.
[GH-12935](https://github.com/hashicorp/packer/pull/12935)
[GH-12942](https://github.com/hashicorp/packer/pull/12942)
[GH-12960](https://github.com/hashicorp/packer/pull/12960)
[GH-12979](https://github.com/hashicorp/packer/pull/12979)
* core: Bump github.com/hashicorp/packer-plugin-sdk from 0.5.2 to 0.5.3
[GH-12932](https://github.com/hashicorp/packer/pull/12932)
* core: Bump go-getter/v2 from 2.2.1 to v2.2.2
[GH-12988](https://github.com/hashicorp/packer/pull/12988)
* datasource/http: don't error on 2xx code
Previous versions of Packer only supported 200 as a success case for the http
datasource. This change makes any status code from 200 to 299 successful.
[GH-12989](https://github.com/hashicorp/packer/pull/12989)
* core: Move to predictable plugin loading schema - Packer will now only load
plugins stored under the [Packer plugin directory](https://developer.hashicorp.com/packer/docs/configure#packer-s-plugin-directory) using the expected namespaced
directory and CHECKSUM files.
Expand Down Expand Up @@ -77,7 +91,19 @@
1.0.0-dev). Users are encouraged to notify plugin maintainers of any
version mismatches.
[GH-12915](https://github.com/hashicorp/packer/pull/12915), [GH-12953](https://github.com/hashicorp/packer/pull/12953), [GH-12972](https://github.com/hashicorp/packer/pull/12972)

* core: don't load plugins with metadata in name
To avoid confusion with multiple plugins that report the same effective version,
plugins installed need to have no metadata in their name.
When installed through Packer commands, the metadata is scrubbed from the name of the
installed plugin binary, but manually it may still be possible, so we enforce
that scrubbing at load-time as well.
[GH-12980](https://github.com/hashicorp/packer/pull/12980)
* core: Error when multiple paths are specified for PACKER_PLUGIN_PATH
Since Packer 1.11 removed the capability for PACKER_PLUGIN_PATH to specify
multiple directories separated by `:` or `;` (depending on the platform), we
are explicitly erroring when this is discovered, with suggestions as to how
to fix the problem.
[GH-12967](https://github.com/hashicorp/packer/pull/12967)
* core: Version metadata support for plugins. Plugins may now formally have metadata
in their versions, Packer supports it, and applies the semver recommendations on
them, i.e. they are ignored for comparison/sorting purposes, but allowed for
Expand Down Expand Up @@ -133,7 +159,11 @@ If, however, a 1.1.1 release version of the plugin is available, it will have pr
* core/hcp: fix potential race condition when storing plugin details to the HCP
Packer metadata storage map.
[GH-12936](https://github.com/hashicorp/packer/pull/12936)

* core: fix plugin listing on Windows
This fix addresses bugs present in the alpha releases of 1.11, where
the discovery of Windows binaries were not matching against the
filename extension (.exe).
[GH-12981](https://github.com/hashicorp/packer/pull/12981)

## 1.10.3 (April 22, 2024)

Expand Down
224 changes: 224 additions & 0 deletions provisioner/hcp-sbom/provisioner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:generate packer-sdc mapstructure-to-hcl2 -type Config
//go:generate packer-sdc struct-markdown

package hcp_sbom

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
"os"
"regexp"
"strings"

"path/filepath"

"github.com/hashicorp/hcl/v2/hcldec"
hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
"github.com/hashicorp/packer-plugin-sdk/common"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

type Config struct {
common.PackerConfig `mapstructure:",squash"`

// The file path or URL to the SBOM file in the Packer artifact.
// This file must either be in the SPDX or CycloneDX format.
Source string `mapstructure:"source" required:"true"`

// The path on the local machine to store a copy of the SBOM file.
// You can specify an absolute or a path relative to the working directory
// when you execute the Packer build. If the file already exists on the
// local machine, Packer overwrites the file. If the destination is a
// directory, the directory must already exist.
Destination string `mapstructure:"destination"`

// The name of the SBOM file stored in HCP Packer.
// If omitted, HCP Packer uses the build fingerprint as the file name.
// This value must be between three and 36 characters from the following set: `[A-Za-z0-9_-]`.
// You must specify a unique name for each build in an artifact version.
SbomName string `mapstructure:"sbom_name"`
ctx interpolate.Context
}

type Provisioner struct {
config Config
}

func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec {
return p.config.FlatMapstructure().HCL2Spec()

Check failure on line 57 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Darwin go tests

p.config.FlatMapstructure undefined (type Config has no field or method FlatMapstructure)

Check failure on line 57 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Windows go tests

p.config.FlatMapstructure undefined (type Config has no field or method FlatMapstructure)

Check failure on line 57 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Lint

p.config.FlatMapstructure undefined (type Config has no field or method FlatMapstructure)
}

var sbomFormatRegexp = regexp.MustCompile("^[0-9A-Za-z-]{3,36}$")

func (p *Provisioner) Prepare(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
PluginType: "hcp-sbom",
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}

var errs error

if p.config.Source == "" {
errs = packersdk.MultiErrorAppend(errs, errors.New("source must be specified"))
}

if p.config.SbomName != "" && !sbomFormatRegexp.MatchString(p.config.SbomName) {
// Ugly but a bit of a problem with interpolation since Provisioners
// are prepared twice in HCL2.
//
// If the information used for interpolating is populated in-between the
// first call to Prepare (at the start of the build), and when the
// Provisioner is actually called, the first call will fail, as
// the value won't contain the actual interpolated value, but a
// placeholder which doesn't match the regex.
//
// Since we don't have a way to discriminate between the calls
// in the context of the provisioner, we ignore them, and later the
// HCP Packer call will fail because of the broken regex.
if strings.Contains(p.config.SbomName, "<no value>") {
log.Printf("[WARN] interpolation incomplete for `sbom_name`, will possibly retry later with data populated into context, otherwise will fail when uploading to HCP Packer.")
} else {
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("`sbom_name` %q doesn't match the expected format, it must "+
"contain between 3 and 36 characters, all from the following set: [A-Za-z0-9_-]", p.config.SbomName))
}
}

return errs
}

// PackerSBOM is the type we write to the temporary JSON dump of the SBOM to
// be consumed by Packer core
type PackerSBOM struct {
// RawSBOM is the raw data from the SBOM downloaded from the guest
RawSBOM []byte `json:"raw_sbom"`
// Format is the format detected by the provisioner
//
// Supported values: `SPDX` or `CYCLONEDX`
Format hcpPackerModels.HashicorpCloudPacker20230101SbomFormat `json:"format"`

Check failure on line 113 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Darwin go tests

undefined: hcpPackerModels.HashicorpCloudPacker20230101SbomFormat

Check failure on line 113 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Windows go tests

undefined: hcpPackerModels.HashicorpCloudPacker20230101SbomFormat

Check failure on line 113 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: hcpPackerModels.HashicorpCloudPacker20230101SbomFormat
// Name is the name of the SBOM to be set on HCP Packer
//
// If unset, HCP Packer will generate one
Name string `json:"name,omitempty"`
}

func (p *Provisioner) Provision(
ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator,
generatedData map[string]interface{},
) error {
log.Println("Starting to provision with `hcp-sbom` provisioner")

if generatedData == nil {
generatedData = make(map[string]interface{})
}
p.config.ctx.Data = generatedData

src := p.config.Source

pkrDst := generatedData["dst"].(string)
if pkrDst == "" {
return fmt.Errorf("packer destination path missing from configs: this is an internal error, which should be reported to be fixed.")
}

var buf bytes.Buffer
if err := comm.Download(src, &buf); err != nil {
ui.Errorf("download failed for SBOM file: %s", err)
return err
}

format, err := validateSBOM(buf.Bytes())

Check failure on line 144 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Darwin go tests

undefined: validateSBOM

Check failure on line 144 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Windows go tests

undefined: validateSBOM

Check failure on line 144 in provisioner/hcp-sbom/provisioner.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: validateSBOM (typecheck)
if err != nil {
return fmt.Errorf("validation failed for SBOM file: %s", err)
}

outFile, err := os.Create(pkrDst)
if err != nil {
return fmt.Errorf("failed to open/create output file %q: %s", pkrDst, err)
}
defer outFile.Close()

err = json.NewEncoder(outFile).Encode(PackerSBOM{
RawSBOM: buf.Bytes(),
Format: format,
Name: p.config.SbomName,
})
if err != nil {
return fmt.Errorf("failed to write sbom file to %q: %s", pkrDst, err)
}

if p.config.Destination == "" {
return nil
}

// SBOM for User
usrDst, err := p.getUserDestination()
if err != nil {
return fmt.Errorf("failed to compute destination path %q: %s", p.config.Destination, err)
}
err = os.WriteFile(usrDst, buf.Bytes(), 0644)
if err != nil {
return fmt.Errorf("failed to write SBOM to destination %q: %s", usrDst, err)
}

return nil
}

// getUserDestination determines and returns the destination path for the user SBOM file.
func (p *Provisioner) getUserDestination() (string, error) {
dst := p.config.Destination

// Check if the destination exists and determine its type
info, err := os.Stat(dst)
if err == nil {
if info.IsDir() {
// If the destination is a directory, create a temporary file inside it
tmpFile, err := os.CreateTemp(dst, "packer-user-sbom-*.json")
if err != nil {
return "", fmt.Errorf("failed to create temporary file in user SBOM directory %s: %s", dst, err)
}
dst = tmpFile.Name()
tmpFile.Close()
}
return dst, nil
}

outDir := filepath.Dir(dst)
// In case the destination does not exist, we'll get the dirpath,
// and create it if it doesn't already exist
err = os.MkdirAll(outDir, 0755)
if err != nil {
return "", fmt.Errorf("failed to create destination directory for user SBOM: %s\n", err)
}

// Check if the destination is a directory after the previous step.
//
// This happens if the path specified ends with a `/`, in which case the
// destination is a directory, and we must create a temporary file in
// this destination directory.
destStat, statErr := os.Stat(dst)
if statErr == nil && destStat.IsDir() {
tmpFile, err := os.CreateTemp(outDir, "packer-user-sbom-*.json")
if err != nil {
return "", fmt.Errorf("failed to create temporary file in user SBOM directory %s: %s", dst, err)
}
dst = tmpFile.Name()
tmpFile.Close()
}

return dst, nil
}
2 changes: 1 addition & 1 deletion version/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.0-dev
1.11.0
1 change: 1 addition & 0 deletions website/content/community-plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ HashiCorp maintainers for advice on how to get started contributing.
## Provisioners

- File
- HCP SBOM
- InSpec
- PowerShell
- Shell
Expand Down
4 changes: 2 additions & 2 deletions website/content/docs/commands/fmt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ $ cat my-template.pkr.hcl | packer fmt -

- `-` - read formatting changes from stdin and write them to stdout.

- `recursive` Also process files in subdirectories. By default, only the
given directory (or current directory) is processed.
- `-recursive` Also process files in subdirectories. By default, only the
given directory (or current directory) is processed.
Loading
Loading