Skip to content

Commit

Permalink
In universal mode, safely ignore directories from container export (#…
Browse files Browse the repository at this point in the history
…1228)

* In universal mode, safely ignore directories from container export

Signed-off-by: Prabhu Subramanian <[email protected]>

* In universal mode, safely ignore directories from container export

Signed-off-by: Prabhu Subramanian <[email protected]>

* Improve types used in tests

Signed-off-by: Prabhu Subramanian <[email protected]>

---------

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Jul 9, 2024
1 parent 932f46e commit 370a4af
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dockertests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ jobs:
docker rmi ubuntu:latest
bin/cdxgen.js almalinux:9.4-minimal -t docker -o bomresults/bom-almalinux.json
docker rmi almalinux:9.4-minimal
bin/cdxgen.js centos:latest -t docker -o bomresults/bom-centos.json
bin/cdxgen.js centos:latest -t oci -o bomresults/bom-centos.json
docker rmi centos:latest
bin/cdxgen.js phpmyadmin@sha256:1092481630056189e43cc0fe66fd01defcc9334d78ab4611b22f65e9a39869bd -o bomresults/bom-phpmyadmin.json --validate
docker rmi phpmyadmin@sha256:1092481630056189e43cc0fe66fd01defcc9334d78ab4611b22f65e9a39869bd
bin/cdxgen.js shiftleft/scan-slim -o bomresults/bom-scanslim.json -t docker --validate
bin/cdxgen.js shiftleft/scan-slim -o bomresults/bom-scanslim.json -t container --validate
docker rmi shiftleft/scan-slim
bin/cdxgen.js redmine@sha256:a5c5f8a64a0d9a436a0a6941bc3fb156be0c89996add834fe33b66ebeed2439e -o bomresults/bom-redmine.json --validate
docker rmi redmine@sha256:a5c5f8a64a0d9a436a0a6941bc3fb156be0c89996add834fe33b66ebeed2439e
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/repotests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ jobs:
run: |
bin/cdxgen.js -p --no-recurse repotests/microservices-demo -o bomresults/bom-msd-1.json --validate
bin/cdxgen.js -p -r repotests/microservices-demo -o bomresults/bom-msd-2.json --validate
bin/cdxgen.js -p -r -t yaml-manifest repotests/microservices-demo -o bomresults/bom-yaml.json --validate
bin/cdxgen.js -p -r -t universal repotests/microservices-demo -o bomresults/bom-yaml.json
shell: bash
- name: repotests openpbs
run: |
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "10.8.0",
"version": "10.8.1",
"exports": "./index.js",
"compilerOptions": {
"allowJs": true,
Expand Down
10 changes: 9 additions & 1 deletion docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
homedir,
tmpdir,
} from "node:os";
import { basename, join } from "node:path";
import { basename, join, resolve } from "node:path";
import process from "node:process";
import stream from "node:stream/promises";
import { parse } from "node:url";
Expand Down Expand Up @@ -1003,6 +1003,14 @@ export const extractFromManifest = async (
* Returns the location of the layers with additional packages related metadata
*/
export const exportImage = async (fullImageName) => {
// Safely ignore local directories
if (
!fullImageName ||
fullImageName === "." ||
existsSync(resolve(fullImageName))
) {
return undefined;
}
// Try to get the data locally first
const localData = await getImage(fullImageName);
if (!localData) {
Expand Down
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6161,14 +6161,17 @@ export async function createBom(path, options) {
path.includes(":latest")
) {
exportData = await exportImage(path);
if (!exportData) {
console.log(
"BOM generation has failed due to problems with exporting the image",
);
options.failOnError && process.exit(1);
return {};
if (exportData) {
isContainerMode = true;
} else {
if (DEBUG_MODE) {
console.log(
path,
"doesn't appear to be a valid container image. Looking for application pacakges.",
);
}
return await createMultiXBom([path], options);
}
isContainerMode = true;
} else if (projectType === "oci-dir") {
isContainerMode = true;
exportData = {
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "10.8.0",
"version": "10.8.1",
"exports": "./index.js",
"include": ["*.js", "bin/**", "data/**", "types/**"],
"exclude": ["test/", "docs/", "contrib/", "ci/", "tools_config/"]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "10.8.0",
"version": "10.8.1",
"description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
"homepage": "http://github.com/cyclonedx/cdxgen",
"author": "Prabhu Subramanian <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion types/docker.d.ts.map

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

2 changes: 1 addition & 1 deletion types/index.d.ts.map

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

0 comments on commit 370a4af

Please sign in to comment.