Skip to content

Commit

Permalink
metadata: Enable built time override in metadata
Browse files Browse the repository at this point in the history
With the built time being part of an EIF's metadata we are not able to
reproducibly build a byte-for-byte identical image file from the same
sources.

Allow to optionally provide a build time override as DateTime<Utc>.
Without providing a build time override the current time is taken as has
always been the case.

Signed-off-by: Leonard Foerster <foersleo@amazon.de>
  • Loading branch information
Leonard Foerster authored and foersleo committed Jun 24, 2024
1 parent 5a69099 commit 1d3ba8c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/utils/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::defs::EifBuildInfo;
use chrono::offset::Utc;
use chrono::DateTime;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
Expand All @@ -17,8 +18,12 @@ pub fn generate_build_info(
build_tool: &str,
build_tool_version: &str,
img_config_path: &str,
build_time_override: Option<DateTime<Utc>>,
) -> Result<EifBuildInfo, String> {
let now = Utc::now();
let now = match build_time_override {
Some(val) => val,
None => Utc::now(),
};

let config_file = File::open(img_config_path)
.map_err(|e| format!("Failed to open kernel image config file: {}", e))?;
Expand Down Expand Up @@ -50,6 +55,15 @@ macro_rules! generate_build_info {
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
$kernel_config_path,
None,
)
};
($kernel_config_path:expr, $time_override:expr) => {
$crate::utils::identity::generate_build_info(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
$kernel_config_path,
$time_override,
)
};
}
Expand Down

0 comments on commit 1d3ba8c

Please sign in to comment.