Commit Graph
101 Commits
Author SHA1 Message Date
Tanmay Jain 014f8d1bbe FEAT(provenance): Add SLSA provenance attestation and verification (#13667)
* feat(provenance): add SLSA provenance and attestation signing libraries

Add internal/provenance for deriving in-toto subjects from Packer
artifacts, building SLSA Provenance v1 predicates, wrapping in-toto
statements, and best-effort git/CI source detection.

Add internal/attestation for DSSE envelope handling and a pluggable
Signer/Verifier backend supporting key (local PEM), kms (aws/gcp/
azure/hashivault), and keyless (Sigstore Fulcio) modes, plus Sigstore
bundle handling and DSSE/policy verification.

Add the supporting module dependencies in go.mod/go.sum.

* feat(provenance): add provenance post-processor

Add the opt-in "provenance" post-processor that runs after a build,
derives subjects from the artifact, emits DSSE-wrapped SLSA provenance
(and optional SBOM) attestations, signs them via the configured
signing backend, and writes sidecar files (including *.sigstore.json
bundles in keyless mode). Register it in the core post-processor set.

The provenance enable flag is a tri-state so an unset value stays
enabled through HCL2 decoding instead of being silently disabled.

* feat(provenance): add verify-attestation command

Add "packer verify-attestation" to verify signed DSSE attestations
against key, KMS, and keyless policy inputs, including optional
Sigstore bundle checks for Rekor and timestamp evidence. Register the
command in the CLI.

* docs(provenance): add reference CI workflows and changelog

Add reference GitHub Actions workflows under examples/ci for SLSA L2
keyless signing and L3-compatible delegated signing

* fix: lint and tests

* Added docs for Provenance PostProcessor
2026-07-21 13:40:42 +05:30
Hari 5ed27a3490 fix: update build constraints to support arm architecture on FreeBSD (#13650) 2026-06-03 16:52:34 +05:30
Hari 5c431e0e44 Removes Syft binary download/handling from the HCP SBOM provisioner (#13636) 2026-06-03 15:23:57 +05:30
hashicorp-copywrite[bot] abc4bfffce Merge pull request #13632 from hashicorp/compliance/add-headers
[COMPLIANCE] Add/Update Copyright Headers
2026-06-03 14:37:46 +05:30
Tanmay Jain 072dfdee9e Skips bucket update when metadata matches current state
Prevents unnecessary update operations by checking if the
bucket's description and labels already match the requested
values before issuing an update.

Improves efficiency and avoids redundant API calls.
2026-04-27 14:07:59 +05:30
HariandHari Om eee3805c06 Feature/enforced provisioner (#13591)
* added the parser for the enforced block

* Enhance enforced provisioner parsing to support HCL and JSON formats

- Updated ParseProvisionerBlocks to handle both HCL and JSON syntax, including legacy JSON format.

- Added comprehensive test cases for JSON provisioner parsing.

- Improved ExtractBuildProvisionerHCL to merge inline commands from shell provisioners.

- Enhanced logging for enforced block operations in HCP Packer.

* Remove PublishEnforcedBlocks function from Bucket struct

* Remove ExtractBuildProvisionerHCL function and unused imports

* Reverted the version upgrade

* Added the internal-sdk for the enforcedProvsioner api changes

* Enhance enforced provisioner handling and error reporting

- Update error handling in FetchEnforcedBlocks to return detailed errors instead of warnings.
- Modify GetCoreBuildProvisionerFromBlock to accept build name for overrides.
- Add tests for FetchEnforcedBlocks to ensure correct behavior and error handling.
- Implement diagnostics for unsupported legacy JSON templates.

* Implement enforced provisioner parsing and handling

- Introduced a new package `enforcedparser` to handle parsing of enforced provisioner blocks from HCL and JSON formats.

- Refactored existing code to utilize the new `ParseProvisionerBlocks` function from the `enforcedparser` package.

- Updated `GetCoreBuildProvisionerFromEnforcedBlock` method to convert enforced provisioner blocks into core build provisioners.

- Enhanced error handling and logging during the parsing process.

- Added tests for the new parsing functionality and ensured existing tests were updated to reflect changes.

- Modified `InjectEnforcedProvisioners` method in JSON registry to utilize the new parsing logic.

* Add test case for -skip-enforcement flag in BuildArgs

* Refactor sensitive variable handling in provisioners and add related tests

* Refactor enforced provisioner handling: remove internal parser, update tests, and streamline API interactions

* Enhance provisioner block parsing: add error handling for invalid combinations and expand test coverage

* Remove internal SDK replacement for enforced block types in go.mod

* Update dependencies in go.mod and go.sum: bump hcp-sdk-go and packer-plugin-sdk versions, adjust syft version, and update OpenTelemetry packages

* Update hcp-sdk-go dependency to v0.172.0 in go.mod and go.sum

* Fix formatting in TestBuildCommand_ParseArgs and add newline at end of json_enforced_test.go

* Refactor testJSONRegistryWithBuilds: remove environment variable setup and streamline registry initialization

* Rename injected variable for clarity in InjectEnforcedProvisioners function

---------

Co-authored-by: Hari Om <[email protected]>
2026-04-17 14:17:28 +05:30
Tanmay Jain 46b216b203 Merge pull request #13545 from hashicorp/compliance/update-headers-batch-2
[IND-4226] [COMPLIANCE] Update Copyright Headers (Batch 2 of 5)
2025-12-22 15:35:05 +05:30
Tanmay Jain 00c9a6d7f7 Merge pull request #13540 from hashicorp/compliance/update-headers
[IND-4226] [COMPLIANCE] Update Copyright Headers
2025-12-22 15:34:39 +05:30
Devashish 651ea426be Verbiage change 2025-12-12 13:20:11 -05:00
hashicorp-copywrite[bot] 219421c08c [COMPLIANCE] Update Copyright and License Headers (Batch 2 of 5) 2025-12-11 07:02:15 +00:00
Tanmay Jain aa2b628319 Adding ui object support in Bucket for Logs 2025-12-08 16:08:49 +05:30
hashicorp-copywrite[bot] 6af0b29558 [COMPLIANCE] Update Copyright and License Headers 2025-11-30 18:32:15 +00:00
Tanmay Jain 52448da979 Added Test Cases for Channel Assignment 2025-11-21 14:35:51 +05:30
Tanmay Jain 0e354e503b FEAT: Adds support for updating HCP Packer registry channels
Enables specifying channels in the build configuration to automatically update existing HCP Packer registry channels to point to the new build version upon completion. Improves workflow automation and reduces manual channel management for users.
2025-11-21 12:43:46 +05:30
Anurag Sharma 543123ac17 bump golang.org/x/crypto to 0.43.0 (#13518)
* bump golang.org/x/crypto to 0.43.0
CVE-2025-47913 GO-2025-4116

* fixed go.sum

* fixed multiple warnings that prevented test runs

* make generate

* fix lint errors, update linter version

* fix go vet issues
2025-11-18 15:49:03 +05:30
Tanmay Jain daa421e5ca FEAT: Added Jenkins CICD Metadata Support for HCP 2025-11-04 11:40:47 +05:30
Anurag Sharma 3f9b1e358c add bitbucket pipelines metadata (#13513) 2025-11-04 09:53:04 +05:30
Jenna Goldstrich 40bea58c92 Fix incorrect Credential file default path in docs (#13447)
should be ~/.config/hcp/cred_file.json
2025-08-13 15:26:45 +05:30
Jenna Goldstrich 8a376a8845 HCP Certificate Authentication Support (#13435)
* Add support for using a certificate file instead of HCP Client Credentials to authenticate to HashiCorp Cloud Platform

* Docs

* Change certificate auth warnings to print to stdio

* rough draft docs

* Update comments

* Parse home directory correctly, default directory certs don't work before this

* cred-file => cred_file, and add unit test

* Fix invalid log, and use full path in log messages and error messages

* Fix original file not being reset in unit test

* Move test statements around to validate Windows behavior

* Use a 'windows friendly' path

* The issue here was the path error'd on mac and linux, but not Windows, when I swapped to the different path then nothing error'd causing everything to fail, I think this should fix it on 3 platforms

* 1.14.1 => 1.14.2
2025-08-12 10:40:55 +05:30
Martin Grogan b1417b7f5c hcp: use GetHCPPackerRegistryBlock in the hcl module 2025-03-11 14:49:59 -04:00
Martin Grogan cc610bc006 hcp: give a proper error when using conflicting build name
It was possible to put the same source 2 times in the build and when
using HCP, it would error eventually since they are considered the same
build from HCP side
2025-03-03 15:44:29 -05:00
Lucas Bajolet 62befd70bf hcp: replace packersdk.Build by *CoreBuild
As the rest of the build process was updated to remove references to the
Build interface exposed by the SDK, we change the usage of such types in
the hcp internal package, so they are typed with *CoreBuild too.
2025-02-13 16:06:02 -05:00
Jenna Goldstrich 8dcd9fe1a5 Ensure org ID is set and move UploadSbom to api package 2025-01-21 16:57:50 -05:00
Jenna Goldstrich 347c57306c hcp: use enum for HCP SBOM upload
Since the protos for uploading an SBOM for a build have been changed to
use an enumeration instead of a plain string with the latest revisions
to the HCP Packer SBOM support feature, we update how we reference those
values for the SBOM format to use that enum instead.
2025-01-21 16:57:50 -05:00
Lucas Bajolet 9b3f29faf9 hcp: wrap completeBuild to mark as failed on error
When a build cannot be completed without errors, the build state was
left as running, unless the build explicitly failed, which meant that
HCP Packer would be responsible for changing the status after the
heartbeats for the build stopped being sent for two 5m periods.

This commit changes this behaviour, by explicitly marking the build as
failed if something did not work while trying to complete a build on HCP
Packer, even if the local Packer core build succeeded before that.
2025-01-21 16:57:50 -05:00
Jenna Goldstrich 362c547211 hcp: integrate SBOM upload to HCP code
Since packer now supports keeping track of SBOMs produced during a
build, we add the code to integrate those changes into the internal/hcp
package, so we do upload them on build completion.
2025-01-21 16:57:50 -05:00
Jenna Goldstrich cf6a82fae8 Make error less brittle to fix upcoming error with HCP SDK Go changing how we return 404 error 2025-01-21 11:33:32 -08:00
Lucas Bajolet 9076c7b24a internal/dag: remove unused code
Since the DAG package was lifted from Terraform, its contents are more
than what we need for now, so this commit cleans-up the package to keep
only the currently needed parts of code.
If we need to support more in the future, we can revert this commit, or
pickup the changes again from Terraform.
2024-10-29 16:10:29 -04:00
Lucas Bajolet 09774aaeb8 internal/dag: adapt Validate to not check for Root
The implementation of the DAG as extracted from Terraform relied on a
Root vertex being injected into the graph as the last node to visit.

This is used as a sanity check for Terraform, but doesn't apply to our
use-case for now, as we are always executing everything and have no need
for this root node.

Instead, we change how Validate operates so it does not error in case
there is no valid root node for the graph, but enables us calling it to
check for self-referencing edges, and circular dependencies.
2024-10-29 16:10:29 -04:00
Lucas Bajolet 673c13ebe7 internal: add dag package
The dag package is a port over from Terraform to Packer, changing what
little there was to fit our current dependency ecosystem.
Most of the changes are on the type of diagnostics returned, as
Terraform has its own type for them, while we rely on hcl's Diagnostics.

Other than that, the functionality is essentially equivalent, and the
code was barely touched.
2024-10-29 16:10:29 -04:00
Lucas Bajolet 69ec781ee2 hcp: don't continue if HEAD doesn't exist
In HCP's metadata package, especially the VCS/git parts, we keep the
current HEAD for a repository, along with the state it is in, in order
to report it to HCP Packer when the build completes.

However, when a build is run on a template from an empty Git repository,
and HCP Packer is enabled, the code would crash when trying to get the
information on the current HEAD, as it doesn't exist.

The git library we use returns an error in such a case, but this was
ignored, leading to a crash when attempting to get the hash to this
reference later on.

This commit fixes the problem by NOT ignoring the error to get the head,
and immediately stop processing the git data as it doesn't yet exist.
2024-09-13 10:46:25 -04:00
Devashish 265dfe105a Remove suffix from CICD platform type (#13121) 2024-07-25 18:15:56 +05:30
Devashish aa6c5f8405 feat: Phase 2 Extension of Build Metadata (#13092) 2024-07-22 23:08:14 +05:30
Jenna Goldstrich 078ad45860 HCP Packer Buckets: Change UpsertBucket to call GetBucket (#13059)
* Update UpsertBucket to first call GetBucket, this will allow bucket level role based authentication, as CreateBucket uses project level auth

* Fix one incorrect test failure message
2024-06-21 08:28:09 -07:00
Devashish f19b9b7369 Remove GetMetadata from StartBuild and add to CompleteBuild for HCL (#12926) 2024-04-15 17:13:09 -04:00
Devashish 70d2efec4d Report metadata only when the build completes (#12923) 2024-04-15 15:02:10 -04:00
Devashish edc8a4dc0d Use latest version of hcp-sdk-go
Remove loggers and move AddMetadataToBuild method to Version
2024-04-11 12:55:04 -04:00
Devashish 8e92027546 HPR-1537: Packer Core sends metadata to HCP Packer in UpdateBuild API (#12891) 2024-04-11 12:55:04 -04:00
Devashish 595b45e67c Packer tracks Version and Plugins Metadata (#12860) 2024-04-11 12:55:04 -04:00
Lucas Bajolet 32f89015fe hcp: fix hcp artifact extraction method
With Packer 1.10.1 we started warning when a build failed to complete
because of a potential incompatibility with the builder being used.

This led to cases in which the build failed for other reasons, and
Packer would still warn of potential incompatibilities, even if the
builder was in effect HCP compatible.

We attempted to fix this issue by introducing a new error type, and
checks when we read the artifacts linked to a build, however this loop
would fail when any one of the artifacts is not compatible with HCP
Packer, leading to false failures.

To avoid this problem, we log incompatibilities to the verbose logger,
and only signal the problem if all the artifacts could not be used to
upload data to HCP Packer, in which case it's almost certain that if the
build succeeded and no artifacts are registered to the build, that all
the components used are not compatible with HCP, and should be reported
as such to users.
2024-02-27 11:39:21 -05:00
Lucas Bajolet 548893bbee build: don't suggest lack of HCP support on fail
When running a build with HCP Packer enabled, Packer attempts to push
the build status to HCP.
If the build fails, we update the status to BUILD_FAILED, and that's the
end of it.
If however the build succeeds, Packer attempts to get the HCP artifact
from the builder, which will only succeed if the builder supports it.
Otherwise, we'll get either nil, or an artifact type that is not
compatible with what is expected for HCP support.

When either of those happens, we warn that the builder may not support
HCP Packer at all, so users are aware of the problem.

However, when the error was introduced, it only looked at the fact that
an error was produced, independently of the type of error. This caused
legitimate errors while building to be reported as potential
incompatibility between the builder and HCP, which was confusing to
users.

This commit changes this by introducing a new error type, only produced
when the artifact either is nil, or failed to be deserialised into a HCP
artifact, which lets us produce the incompatibility warning with more
accuracy.
2024-02-13 14:47:06 -05:00
Devashish 91ce35f439 Expose versionFingerprint instead of versionId from packer template 2024-01-26 14:31:04 -05:00
Wilken RiveraandLucas Bajolet 12b8c885a3 Update error messaging for HCP incompatible plugin builds (#12800)
* Update error messaging for HCP incompatible plugin builds

* Update command/build.go

Co-authored-by: Lucas Bajolet <[email protected]>

---------

Co-authored-by: Lucas Bajolet <[email protected]>
2024-01-25 11:32:18 -05:00
3fa637c608 Migrate HCP Packer to API V2 and new nomenclature changes (#12794)
* add hcp packer new nomenclature updates

* Update docs with nomenclature changes

* Update navigation bar links

* Bump github.com/hashicorp/hcp-sdk-go from 0.81.0 to 0.82.0

* fix acceptance test template

---------

Co-authored-by: sylviamoss <[email protected]>
Co-authored-by: Wilken Rivera <[email protected]>
2024-01-24 13:17:35 -05:00
Wilken Rivera c245b1fb7c deps: Bump github.com/hashicorp/hcp-sdk-go to v0.73.0
* Updates cloud-resource-management API to use sable
* Removes duplicate imports of the same SDK packages
2023-11-15 10:27:51 -05:00
hashicorp-copywrite[bot] 19055df3ec [COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00
Wilken Rivera 60c66fdf9f Add additional validation for manually set project ids
When setting a project id via the HCP_PROJECT_ID env the client will try to validate the project
by checking that it has an associated registry. If the project is invalid or not a valid UUID an error
will be displayed to the user

* Add comment to clarify usage of SDK loaded env. variables
2023-07-25 11:31:39 -04:00
Wilken Rivera 38101a64c9 hcp: Add support for project level service principals
HCP supports two types of service principals: Organization-level and project-level.
When a user tries to publish to an active HCP Packer registry using a plsp the client
fails when configuring the client due to a API permission error; namely plsp do not have
the permissions to query an org for a list of projects. Setting the HCP_PROJECT_ID does
not resolve the issue because the call to ListProjects is still executed.

This changes updates the client configuration params to obtain both the HCP Organization and
Project IDs that will be used for connecting to the HCP Packer registry. With this change
if a user provides a project Id via the HCP_PROJECT_ID environment variable no call to ListProjects will
be made. Instead the value will be take as is and used to create the connection. A user connecting with
a project level service principals must provide a valid HCP_PROJECT_ID in order to connect.
2023-07-25 11:31:39 -04:00
hashicorp-copywrite[bot] d563a3c623 [COMPLIANCE] Add Copyright and License Headers 2023-06-05 13:39:28 -04:00
Lucas Bajolet 925cb5e541 hcp: support HCP_PROJECT_ID environment variable
With HCP supporting multi-projects now, Packer needs to take it into
account when picking a project from an organisation.

This commit adds two cases:

1. multiple projects are defined, none is supplied through
   HCP_PROJECT_ID: in this case we will default to the oldest project
   defined for the organisation.

2. we supply HCP_PROJECT_ID: in this case, we pick the project with the
   corresponding ID, and use it for publishing metadata.
2023-06-01 14:39:09 -04:00