Skip to content

Commit 14cdc42

Browse files
radu-mateirajatjindalendocrimesmichelleN
committed
fix(oci/config): ensure unique OCI image config
This commit ensures that applications pushed to OCI have unique image config fields for unique Spin application content and metadata by adding a label in the OCI image config to the content digest (SHA256) of the Spin locked application file. This is to address the issue of the Containerd Spin shim serving outdated content, because all images of Spin apps on a node would have the same image ID (the content digest of the OCI config object, which was identical for all Spin apps). ref spinframework/spin-operator#40 Signed-off-by: Radu Matei <[email protected]> Co-authored-by: Rajat Jindal <[email protected]> Co-authored-by: Danielle Lancashire <[email protected]> Co-authored-by: Michelle Dhanani <[email protected]>
1 parent 5b3aa0a commit 14cdc42

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/oci/src/client.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Spin's client for distributing applications via OCI registries
22
3+
use std::collections::HashMap;
34
use std::path::{Path, PathBuf};
45

56
use anyhow::{bail, Context, Result};
@@ -174,15 +175,31 @@ impl Client {
174175
SPIN_APPLICATION_MEDIA_TYPE.to_string(),
175176
None,
176177
);
178+
let config_layer_digest = locked_config_layer.sha256_digest().clone();
177179
layers.push(locked_config_layer);
178180

181+
let mut labels = HashMap::new();
182+
labels.insert(
183+
"com.fermyon.spin.lockedAppDigest".to_string(),
184+
config_layer_digest,
185+
);
186+
let cfg = oci_distribution::config::Config {
187+
labels: Some(labels),
188+
..Default::default()
189+
};
190+
179191
// Construct empty/default OCI config file. Data may be parsed according to
180192
// the expected config structure per the image spec, so we want to ensure it conforms.
181193
// (See https://github.com/opencontainers/image-spec/blob/main/config.md)
182194
// TODO: Explore adding data applicable to the Spin app being published.
183195
let oci_config_file = ConfigFile {
184196
architecture: oci_distribution::config::Architecture::Wasm,
185197
os: oci_distribution::config::Os::Wasip1,
198+
// We need to ensure that the image config for different content is updated.
199+
// Without referencing the digest of the locked application in the OCI image config,
200+
// all Spin applications would get the same image config digest, resulting in the same
201+
// image ID in container runtimes.
202+
config: Some(cfg),
186203
..Default::default()
187204
};
188205
let oci_config =

0 commit comments

Comments
 (0)