Skip to content

Commit

Permalink
Include source of invalid base64 data in error messages
Browse files Browse the repository at this point in the history
The user data content could be sensitive.
  • Loading branch information
tjkirch committed Apr 8, 2021
1 parent 1fcb96c commit 11e5ca2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
10 changes: 8 additions & 2 deletions sources/api/bootstrap-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ where
// If user data was specified, decode it and write it out
if let Some(user_data) = &container_details.user_data {
debug!("Decoding user data for container '{}'", name);
let decoded_bytes = base64::decode(user_data.as_bytes()).context(error::Base64Decode)?;
let decoded_bytes =
base64::decode(user_data.as_bytes()).context(error::Base64Decode { name })?;

let path = dir.join("user-data");
debug!("Storing user data in {}", path.display());
Expand Down Expand Up @@ -606,8 +607,13 @@ mod error {
source: apiclient::Error,
},

#[snafu(display("Unable to base64 decode user-data: '{}'", source))]
#[snafu(display(
"Unable to decode base64 in user data of bootstrap container '{}': '{}'",
name,
source
))]
Base64Decode {
name: String,
source: base64::DecodeError,
},

Expand Down
6 changes: 3 additions & 3 deletions sources/api/early-boot-config/src/provider/vmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl VmwareDataProvider {

// Base64 decode the &str
let decoded_bytes = base64::decode(&base64_str).context(error::Base64Decode {
base64_string: base64_str.to_string(),
what: "OVF user data",
})?;

// Decompress the data if it's compressed
Expand Down Expand Up @@ -312,9 +312,9 @@ mod error {
source: vmw_backdoor::VmwError,
},

#[snafu(display("Unable to base64 decode string '{}': '{}'", base64_string, source))]
#[snafu(display("Unable to decode base64 in {}: '{}'", what, source))]
Base64Decode {
base64_string: String,
what: String,
source: base64::DecodeError,
},

Expand Down
8 changes: 3 additions & 5 deletions sources/api/host-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ mod error {
#[snafu(display("Logger setup error: {}", source))]
Logger { source: log::SetLoggerError },

#[snafu(display("Unable to base64 decode user-data '{}': '{}'", base64_string, source))]
#[snafu(display("Unable to base64 decode user-data for container '{}': '{}'", name, source))]
Base64Decode {
base64_string: String,
name: String,
source: base64::DecodeError,
},

Expand Down Expand Up @@ -383,9 +383,7 @@ where

// If user data was specified, unencode it and write it out before we start the container.
if let Some(user_data) = &image_details.user_data {
let decoded_bytes = base64::decode(user_data.as_bytes()).context(error::Base64Decode {
base64_string: user_data.as_ref(),
})?;
let decoded_bytes = base64::decode(user_data.as_bytes()).context(error::Base64Decode { name })?;

let path = dir.join("user-data");
fs::write(path, decoded_bytes).context(error::UserDataWrite { name })?;
Expand Down
9 changes: 1 addition & 8 deletions sources/api/schnauzer/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,8 @@ mod error {
))]
MissingTemplateData { template: String },

#[snafu(display(
"Unable to base64 decode string '{}' in template '{}': '{}'",
base64_string,
template,
source
))]
#[snafu(display("Unable to decode base64 in template '{}': '{}'", template, source))]
Base64Decode {
base64_string: String,
template: String,
source: base64::DecodeError,
},
Expand Down Expand Up @@ -239,7 +233,6 @@ pub fn base64_decode(

// Base64 decode the &str
let decoded_bytes = base64::decode(&base64_str).context(error::Base64Decode {
base64_string: base64_str.to_string(),
template: template_name.to_owned(),
})?;

Expand Down
9 changes: 4 additions & 5 deletions sources/api/static-pods/src/static_pods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ where
field: "manifest",
})?;

let manifest = base64::decode(manifest.as_bytes()).context(error::Base64Decode {
base64_string: manifest.as_ref(),
})?;
let manifest = base64::decode(manifest.as_bytes()).context(error::Base64Decode { name })?;

info!("Writing static pod '{}' to '{}'", name, STATIC_POD_DIR);

Expand Down Expand Up @@ -271,9 +269,10 @@ mod error {
#[snafu(display("Logger setup error: {}", source))]
Logger { source: log::SetLoggerError },

#[snafu(display("Unable to base64 decode manifest '{}': '{}'", base64_string, source))]
#[snafu(display(
"Unable to decode base64 in static pod '{}' manifest: {}", name, source))]
Base64Decode {
base64_string: String,
name: String,
source: base64::DecodeError,
},

Expand Down

0 comments on commit 11e5ca2

Please sign in to comment.