Skip to content

Commit b49fe5c

Browse files
authored
libcnb-test: Use --trust-extra-buildpacks with pack build (#855)
To force the builder to be trusted after changes were made in Pack CLI v0.35.0 to improve security. The new flag to restore the old behaviour was only added in Pack v0.35.1, so using `libcnb-test` now requires that Pack version or newer. (Adding a version check would require calling out to Pack before every test execution, which is not worth it given that it only affects tests, and this will be a one-off transition.) Fixes #854. GUS-W-16600037.
1 parent b018a93 commit b49fe5c

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
- name: Rust Cache
6363
uses: Swatinem/[email protected]
6464
- name: Install Pack CLI
65-
uses: buildpacks/github-actions/[email protected].2
65+
uses: buildpacks/github-actions/[email protected].4
6666
- name: Run integration tests
6767
# Runs only tests annotated with the `ignore` attribute (which in this repo, are the integration tests).
6868
run: cargo test -- --ignored
@@ -93,4 +93,4 @@ jobs:
9393
# This image used the experimental image extensions feature which has to be explicitly enabled and doesn't
9494
# work with `--trust-builder`. To unblock CI, the builder has been changed to `heroku/builder:22`. As soon as
9595
# we can, we should use a non-libc builder again.
96-
run: pack build example-basics --force-color --builder heroku/builder:22 --trust-builder --buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_basics --path examples/
96+
run: pack build example-basics --force-color --builder heroku/builder:22 --trust-builder --trust-extra-buildpacks --buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_basics --path examples/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
### Changed
13+
14+
- `libcnb-test`:
15+
- `pack build` is now run with `--trust-extra-buildpacks` to force the builder to be trusted after upstream changes in Pack CLI. Pack CLI v0.35.1+ is now required to use `libcnb-test`. ([#855](https://github.com/heroku/libcnb.rs/pull/855))
1216

1317
## [0.22.0] - 2024-06-18
1418

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Successfully wrote buildpack directory: packaged/x86_64-unknown-linux-musl/debug
189189
💡 To test your buildpack locally with pack, run:
190190
pack build my-image-name \
191191
--buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack \
192+
--trust-extra-buildpacks \
192193
--path /path/to/application
193194

194195
/Users/example/src/my-buildpack/packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack
@@ -206,7 +207,7 @@ application code at all, we just create an empty directory and use that as our a
206207

207208
```console
208209
$ mkdir bogus-app
209-
$ pack build my-image --buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack --path bogus-app --builder heroku/builder:22
210+
$ pack build my-image --buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack --trust-extra-buildpacks --path bogus-app --builder heroku/builder:22
210211
...
211212
===> ANALYZING
212213
Image with name "my-image" not found

libcnb-cargo/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Successfully wrote buildpack directory: packaged/x86_64-unknown-linux-musl/debug
4646
💡 To test your buildpack locally with pack, run:
4747
pack build my-image-name \
4848
--buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack \
49+
--trust-extra-buildpacks \
4950
--path /path/to/application
5051

5152
/Users/example/src/my-buildpack/packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack

libcnb-cargo/src/package/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ fn eprint_pack_command_hint(
147147
.to_string_lossy()
148148
);
149149
}
150+
eprintln!(" --trust-extra-buildpacks \\");
150151
eprintln!(" --path /path/to/application");
151152
eprintln!();
152153
}

libcnb-test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The framework:
1515
Integration tests require the following to be available on the host:
1616

1717
- [Docker](https://docs.docker.com/engine/install/)
18-
- [Pack CLI](https://buildpacks.io/docs/install-pack/)
18+
- [Pack CLI](https://buildpacks.io/docs/install-pack/) v0.35.1+
1919
- [Cross-compilation prerequisites](https://docs.rs/libcnb/latest/libcnb/#cross-compilation-prerequisites) (however `libcnb-cargo` itself is not required)
2020

2121
Only local Docker daemons are fully supported. As such, if you are using Circle CI you must use the

libcnb-test/src/pack.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) struct PackBuildCommand {
1414
path: PathBuf,
1515
pull_policy: PullPolicy,
1616
trust_builder: bool,
17+
trust_extra_buildpacks: bool,
1718
}
1819

1920
#[derive(Clone, Debug)]
@@ -65,6 +66,7 @@ impl PackBuildCommand {
6566
// Prevent redundant image-pulling, which slows tests and risks hitting registry rate limits.
6667
pull_policy: PullPolicy::IfNotPresent,
6768
trust_builder: true,
69+
trust_extra_buildpacks: true,
6870
}
6971
}
7072

@@ -126,6 +128,10 @@ impl From<PackBuildCommand> for Command {
126128
command.arg("--trust-builder");
127129
}
128130

131+
if pack_build_command.trust_extra_buildpacks {
132+
command.arg("--trust-extra-buildpacks");
133+
}
134+
129135
command
130136
}
131137
}
@@ -188,6 +194,7 @@ mod tests {
188194
path: PathBuf::from("/tmp/foo/bar"),
189195
pull_policy: PullPolicy::IfNotPresent,
190196
trust_builder: true,
197+
trust_extra_buildpacks: true,
191198
};
192199

193200
let command: Command = input.clone().into();
@@ -218,6 +225,7 @@ mod tests {
218225
"--env",
219226
"ENV_FOO=FOO_VALUE",
220227
"--trust-builder",
228+
"--trust-extra-buildpacks",
221229
]
222230
);
223231

libcnb-test/tests/integration_test.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ pack command failed with exit code 1!
263263
264264
## stderr:
265265
266-
ERROR: failed to build: invalid builder 'invalid!'")]
266+
ERROR: forbidden image name: parsing builder image invalid!: could not parse reference: invalid!
267+
268+
## stdout:
269+
270+
271+
")]
267272
fn unexpected_pack_failure() {
268273
TestRunner::default().build(
269274
BuildConfig::new("invalid!", "tests/fixtures/empty").buildpacks(Vec::new()),
@@ -306,7 +311,7 @@ fn expected_pack_failure() {
306311
assert_empty!(context.pack_stdout);
307312
assert_contains!(
308313
context.pack_stderr,
309-
"ERROR: failed to build: invalid builder 'invalid!'"
314+
"ERROR: forbidden image name: parsing builder image invalid!"
310315
);
311316
},
312317
);

0 commit comments

Comments
 (0)