Skip to content

Commit f2da712

Browse files
committed
feat: Add ability to mount secrets
1 parent 22ef839 commit f2da712

File tree

27 files changed

+463
-69
lines changed

27 files changed

+463
-69
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tempfile = "3"
3333
tokio = { version = "1", features = ["rt", "rt-multi-thread"] }
3434
users = "0.11"
3535
uuid = { version = "1", features = ["v4"] }
36+
zeroize = { version = "1", features = ["aarch64", "derive", "std", "serde"] }
3637

3738
[workspace.lints.rust]
3839
unsafe_code = "forbid"

integration-tests/Earthfile

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,11 @@ PROJECT blue-build/cli
44
IMPORT github.com/earthly/lib/utils/dind AS dind
55

66
all:
7-
BUILD +test-image
8-
# BUILD +test-legacy-image
97
BUILD +build
108
BUILD +switch
119
BUILD +validate
12-
13-
test-image:
14-
FROM +build-template --src=template-containerfile
15-
WORKDIR /tmp/test
16-
COPY ./test-scripts/*.sh ./
17-
18-
DO +RUN_TESTS
19-
20-
test-legacy-image:
21-
FROM +build-template --src=template-legacy-containerfile
22-
WORKDIR /tmp/test
23-
COPY ./test-scripts/*.sh ./
24-
25-
DO +RUN_TESTS
26-
27-
build-template:
28-
ARG --required src
29-
FROM DOCKERFILE \
30-
-f +$src/test/Containerfile \
31-
+$src/test/*
10+
BUILD +template-containerfile
11+
BUILD +template-legacy-containerfile
3212

3313
template-containerfile:
3414
FROM +test-base
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/Containerfile
22
/Containerfile.*
3+
/secrets

integration-tests/test-repo/recipes/common.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,41 @@ modules:
7777
from: fedora-test
7878
src: /test.txt
7979
dest: /
80+
81+
# Testing secrets
82+
- type: script
83+
secrets:
84+
- type: env
85+
name: TEST_SECRET
86+
snippets:
87+
- '[ "$TEST_SECRET" == "test123" ]'
88+
- type: script
89+
secrets:
90+
- type: file
91+
source: ./secrets/test-secret
92+
destination: /tmp/test-secret
93+
snippets:
94+
- '[ "$(cat /tmp/test-secret)" == "321tset" ]'
95+
- type: script
96+
secrets:
97+
- type: exec
98+
command: cat
99+
args:
100+
- ./test_secret_file.txt
101+
output:
102+
type: env
103+
name: TEST_SECRET
104+
snippets:
105+
- '[ "$TEST_SECRET" == "TEST_PASS" ]'
106+
- type: script
107+
secrets:
108+
- type: exec
109+
command: cat
110+
args:
111+
- ./test_secret_file.txt
112+
output:
113+
type: file
114+
destination: /tmp/test-secret
115+
snippets:
116+
- '[ "$(cat /tmp/test-secret)" == "TEST_PASS" ]'
117+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST_PASS

justfile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export RUST_BACKTRACE := "1"
22
export BB_CACHE_LAYERS := "true"
3+
export TEST_SECRET := "test123"
4+
# export BB_SKIP_VALIDATION := "true"
35

46
set dotenv-load := true
57
set positional-arguments := true
@@ -133,11 +135,15 @@ cargo_bin := if env('CARGO_HOME', '') != '' {
133135
x"$HOME/.cargo/bin"
134136
}
135137

138+
generate-test-secret:
139+
mkdir -p integration-tests/test-repo/secrets
140+
echo "321tset" > integration-tests/test-repo/secrets/test-secret
141+
136142
# Run all integration tests
137-
integration-tests: test-docker-build test-empty-files-build test-arm64-build test-podman-build test-buildah-build test-generate-iso-image test-generate-iso-recipe
143+
integration-tests: generate-test-secret test-docker-build test-empty-files-build test-arm64-build test-podman-build test-buildah-build test-generate-iso-image test-generate-iso-recipe
138144

139145
# Run docker driver integration test
140-
test-docker-build: install-debug-all-features
146+
test-docker-build: generate-test-secret install-debug-all-features
141147
cd integration-tests/test-repo \
142148
&& bluebuild build \
143149
--retry-push \
@@ -148,7 +154,7 @@ test-docker-build: install-debug-all-features
148154
-vv \
149155
recipes/recipe.yml recipes/recipe-gts.yml
150156

151-
test-empty-files-build: install-debug-all-features
157+
test-empty-files-build: generate-test-secret install-debug-all-features
152158
cd integration-tests/empty-files-repo \
153159
&& bluebuild build \
154160
--retry-push \
@@ -158,15 +164,15 @@ test-empty-files-build: install-debug-all-features
158164
{{ should_push }} \
159165
-vv
160166

161-
test-rechunk-build: install-debug-all-features
167+
test-rechunk-build: generate-test-secret install-debug-all-features
162168
cd integration-tests/test-repo \
163169
&& bluebuild build \
164170
{{ should_push }} \
165171
-vv \
166172
--rechunk \
167173
recipes/recipe-rechunk.yml
168174

169-
test-fresh-rechunk-build: install-debug-all-features
175+
test-fresh-rechunk-build: generate-test-secret install-debug-all-features
170176
cd integration-tests/test-repo \
171177
&& bluebuild build \
172178
{{ should_push }} \
@@ -176,7 +182,7 @@ test-fresh-rechunk-build: install-debug-all-features
176182
recipes/recipe-rechunk.yml
177183

178184
# Run arm integration test
179-
test-arm64-build: install-debug-all-features
185+
test-arm64-build: generate-test-secret install-debug-all-features
180186
cd integration-tests/test-repo \
181187
&& bluebuild build \
182188
--retry-push \
@@ -186,7 +192,7 @@ test-arm64-build: install-debug-all-features
186192
recipes/recipe-arm64.yml
187193

188194
# Run docker driver external login integration test
189-
test-docker-build-external-login: install-debug-all-features
195+
test-docker-build-external-login: generate-test-secret install-debug-all-features
190196
cd integration-tests/test-repo \
191197
&& bluebuild build \
192198
--retry-push \
@@ -196,7 +202,7 @@ test-docker-build-external-login: install-debug-all-features
196202
recipes/recipe-docker-external.yml
197203

198204
# Run podman driver integration test
199-
test-podman-build: install-debug-all-features
205+
test-podman-build: generate-test-secret install-debug-all-features
200206
cd integration-tests/test-repo \
201207
&& bluebuild build \
202208
--retry-push \
@@ -208,7 +214,7 @@ test-podman-build: install-debug-all-features
208214
recipes/recipe-podman.yml
209215

210216
# Run buildah driver integration test
211-
test-buildah-build: install-debug-all-features
217+
test-buildah-build: generate-test-secret install-debug-all-features
212218
cd integration-tests/test-repo \
213219
&& bluebuild build \
214220
--retry-push \
@@ -220,14 +226,14 @@ test-buildah-build: install-debug-all-features
220226
recipes/recipe-buildah.yml
221227

222228
# Run ISO generator for images
223-
test-generate-iso-image: install-debug-all-features
229+
test-generate-iso-image: generate-test-secret install-debug-all-features
224230
#!/usr/bin/env bash
225231
set -eu
226232
ISO_OUT=$(mktemp -d)
227233
bluebuild generate-iso -vv --output-dir "$ISO_OUT" image ghcr.io/blue-build/cli/test:40
228234

229235
# Run ISO generator for images
230-
test-generate-iso-recipe: install-debug-all-features
236+
test-generate-iso-recipe: generate-test-secret install-debug-all-features
231237
#!/usr/bin/env bash
232238
set -eu
233239
ISO_OUT=$(mktemp -d)

process/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ os_pipe = { version = "1", features = ["io_safety"] }
2020
rand = "0.9"
2121
signal-hook = { version = "0.3", features = ["extended-siginfo"] }
2222
sigstore = { version = "0.11", features = ["full-rustls-tls", "cached-client", "sigstore-trust-root", "sign"], default-features = false }
23-
zeroize = { version = "1", features = ["aarch64", "derive", "serde"] }
2423

2524
cached.workspace = true
2625
chrono.workspace = true
@@ -42,6 +41,7 @@ tokio.workspace = true
4241
bon.workspace = true
4342
users.workspace = true
4443
uuid.workspace = true
44+
zeroize.workspace = true
4545

4646
[dev-dependencies]
4747
rstest.workspace = true

process/drivers.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
time::Duration,
1515
};
1616

17-
use blue_build_utils::semver::Version;
17+
use blue_build_utils::{BUILD_ID, semver::Version};
1818
use bon::{Builder, bon};
1919
use cached::proc_macro::cached;
2020
use clap::Args;
@@ -69,9 +69,6 @@ static SELECTED_SIGNING_DRIVER: std::sync::LazyLock<RwLock<Option<SigningDriverT
6969
static SELECTED_CI_DRIVER: std::sync::LazyLock<RwLock<Option<CiDriverType>>> =
7070
std::sync::LazyLock::new(|| RwLock::new(None));
7171

72-
/// UUID used to mark the current builds
73-
static BUILD_ID: std::sync::LazyLock<Uuid> = std::sync::LazyLock::new(Uuid::new_v4);
74-
7572
/// Args for selecting the various drivers to use for runtime.
7673
///
7774
/// If the args are left uninitialized, the program will determine

process/drivers/buildah_driver.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::{io::Write, process::Stdio};
22

3-
use blue_build_utils::{credentials::Credentials, semver::Version};
3+
use blue_build_utils::{credentials::Credentials, secret::SecretArgs, semver::Version};
44
use colored::Colorize;
55
use comlexr::cmd;
66
use log::{debug, error, info, trace};
7-
use miette::{IntoDiagnostic, Result, bail, miette};
7+
use miette::{Context, IntoDiagnostic, Result, bail, miette};
88
use serde::Deserialize;
9+
use tempfile::TempDir;
910

1011
use crate::{drivers::types::Platform, logging::CommandLogging};
1112

@@ -50,9 +51,14 @@ impl BuildDriver for BuildahDriver {
5051
fn build(opts: &BuildOpts) -> Result<()> {
5152
trace!("BuildahDriver::build({opts:#?})");
5253

54+
let temp_dir = TempDir::new()
55+
.into_diagnostic()
56+
.wrap_err("Failed to create temporary directory for secrets")?;
57+
5358
let command = cmd!(
5459
"buildah",
5560
"build",
61+
for opts.secrets.args(&temp_dir)?,
5662
if !matches!(opts.platform, Platform::Native) => [
5763
"--platform",
5864
opts.platform.to_string(),

0 commit comments

Comments
 (0)