Skip to content

Commit

Permalink
Support for fail-on-error for container sbom generation. Env variable…
Browse files Browse the repository at this point in the history
… to force non-strict tar extraction.

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Dec 26, 2024
1 parent e1dcfc2 commit 56fc686
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
30 changes: 12 additions & 18 deletions lib/managers/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,6 @@ export const getImage = async (fullImageName) => {
* @param entry {tar.ReadEntry} ReadEntry object from node-tar
*/
function handleAbsolutePath(entry) {
// Don't waste time with gibberish path
if (
!entry ||
!entry.path ||
entry.path.startsWith("{") ||
entry.path.includes("\n")
) {
return;
}
if (entry.path === "/" || win32.isAbsolute(entry.path)) {
entry.path = stripAbsolutePath(entry.path);
}
Expand All @@ -817,13 +808,12 @@ export const extractTar = async (fullImageName, dir, options) => {
filter: (path, entry) => {
// Some files are known to cause issues with extract
return !(
path.startsWith("{") ||
path.includes("\n") ||
path.includes("etc/machine-id") ||
path.includes("etc/gshadow") ||
path.includes("etc/shadow") ||
path.endsWith("etc/passwd") ||
path.endsWith("etc/ssl/certs") ||
path.includes("etc/passwd") ||
path.includes("etc/ssl/certs") ||
path.includes("etc/pki/ca-trust") ||
path.includes("usr/lib/systemd/") ||
path.includes("usr/lib64/libdevmapper.so") ||
path.includes("usr/sbin/") ||
Expand Down Expand Up @@ -878,8 +868,6 @@ export const extractTar = async (fullImageName, dir, options) => {
} else if (err.code === "TAR_BAD_ARCHIVE") {
if (DEBUG_MODE) {
console.log(`Archive ${fullImageName} is empty. Skipping.`);
// Empty tar images need not lead to failure.
return false;
}
} else if (["EACCES"].includes(err.code)) {
console.log(err);
Expand All @@ -892,8 +880,13 @@ export const extractTar = async (fullImageName, dir, options) => {
DEBUG_MODE &&
["TAR_ENTRY_INFO", "TAR_ENTRY_INVALID"].includes(err.code)
) {
if (
err?.header?.path?.includes("{") ||
err?.message?.includes("linkpath required")
) {
return false;
}
console.log(err);
return false;
} else if (DEBUG_MODE) {
console.log(err.code, "is not handled yet in extractTar method.");
}
Expand Down Expand Up @@ -959,6 +952,7 @@ export const exportArchive = async (fullImageName, options = {}) => {
options.failOnError && process.exit(1);
} catch (err) {
// ignore
options.failOnError && process.exit(1);
}
return undefined;
};
Expand Down Expand Up @@ -1028,8 +1022,8 @@ export const extractFromManifest = async (
}
} else {
console.log(err);
options.failOnError && process.exit(1);
}
options.failOnError && process.exit(1);
}
}
if (manifest.Config) {
Expand All @@ -1052,7 +1046,7 @@ export const extractFromManifest = async (
? join(allLayersExplodedDir, lastLayerConfig.config.WorkingDir)
: "";
} catch (err) {
// ignore
options.failOnError && process.exit(1);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion types/lib/managers/docker.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56fc686

Please sign in to comment.