Skip to content

Commit 7bdf304

Browse files
author
Harri Klingsten
committed
Addes option to resolve license when creating SBOM file with CdxGen.
1 parent 80ce592 commit 7bdf304

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Returns EPSS score for provided CVE, the value is percent where 0 is minimum an
1515

1616

1717
# Prerequisites
18+
I know the setup of this is a bit corky, just be aware of that, look at troubleshot if you have problems.
19+
1820
If this is the first time you use a Power Commands implementation a encryption setup will be done at the first startup. The encryption key is setup for all Power Commands projects and is unique for every machine. Encryption is used by this Power Commands project to secure your **Dependency Track** API key.
1921

2022
This application is intended to use **CycloneDX** and **Dependency Track** software running as container, therefore you need to have Docker Desktop installed, this way you do not need to install software on your machine besides this Power Commands console application. Setup Docker Desktop is however not described in this documentation.
@@ -79,13 +81,24 @@ If you add the --upload option, the sbom will also be uploaded to Dependency Tra
7981

8082
```sbom --path https://github.com/PowerCommands/PowerCommands2022.git --NAME <my-sbom-name> --upload```
8183

84+
### Resolve licenses
85+
By default resolving licenses is turned off because it is a very time consuming process. If you need this you need to configure this in the ```PowerCommandsConfiguration.yaml``` configuration file.
86+
```
87+
cdxgen:
88+
resolveLicenses: true
89+
```
90+
This has to be done before the container has been started so if it is already running you need to stop the container first and restart it with the ```start``` command. There will be some warning about the Dependency Track container already running but that is nothing to worry about.
8291
___
8392

8493
## Trouble shoot
8594
If you having trouble to start Dependency Track or login from Dependency Track, open Docker Desktop and make sure that the containers is running.
8695

8796
<img src="containers_running.png" alt="Docker Containers running" width="800">
8897

98+
Also check the ```PowerCommandsConfiguration.yaml``` configuration file that the path to the directory where SBOM is stored is correct and exists.
99+
100+
```sdxGenServerVolumeMount: C:\Temp\Cdxgen_server```
101+
89102
## Power Commands
90103

91104
Read more about Power Commands: https://github.com/PowerCommands/PowerCommands2022

src/SecTools/SecToolsCommands/Commands/SetupCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ public override RunResult Run()
2323
DockerDesktopManager.Pull(Configuration.DependencyTracker.FrontendImage);
2424

2525
WriteSuccessLine("\nDependency track setup done!");
26+
return Ok();
2627
}
2728
else if (HasOption("dt-key"))
2829
{
2930
var secretCommand = new SecretCommand("secret", Configuration);
3031
secretCommand.InitializeAndValidateInput("secret --create \"DT_PowerCommand\"".Interpret());
3132
secretCommand.Run();
33+
return Ok();
3234
}
35+
WriteWarning("No option was provided, you need to provide either --docker to setup the docker images or --dt_key to setup the Dependency Track access token. (create a Team in DT Administration/Access management/Teams)");
3336
return Ok();
3437
}
3538
}

src/SecTools/SecToolsCommands/Commands/StartCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public override RunResult Run()
1515
DockerDesktopManager.StartDockerDesktop(fullFileName, Configuration.DockerDesktop.StartupTime);
1616

1717
var xCfg = Configuration.Cdxgen;
18-
CycloneDxManager.Start(xCfg.HostMount, xCfg.ContainerMount, xCfg.HostPort, xCfg.ContainerPort, xCfg.SdxGenServerVolumeMount, xCfg.ImageUrl, xCfg.ServerHost);
18+
CycloneDxManager.Start(xCfg.HostMount, xCfg.ContainerMount, xCfg.HostPort, xCfg.ContainerPort, xCfg.SdxGenServerVolumeMount, xCfg.ImageUrl, xCfg.ServerHost, xCfg.ResolveLicenses);
1919

2020
var dCfg = Configuration.DependencyTracker;
2121
DependencyTrackManager.Start(dCfg.ApiUrl, dCfg.ApiServerImage, dCfg.ApiServerContainer, dCfg.ApiPorts, dCfg.FrontendImage, dCfg.FrontendContainer, dCfg.FrontendPorts, dCfg.AdminUrl, dCfg.StartupTime);

src/SecTools/SecToolsCommands/Configuration/CdxgenConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public class CdxgenConfiguration
1010
public string ContainerMount { get; set; } = "/tmp";
1111
public string ServerHost { get; set; } = "0.0.0.0";
1212
public string SbomApiUrl { get; set; } = "http://127.0.0.1:9090/sbom";
13+
public bool ResolveLicenses { get; set; }
1314
}

src/SecTools/SecToolsCommands/Managers/CycloneDxManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
namespace SecToolsCommands.Managers;
22
public static class CycloneDxManager
33
{
4-
public static void Start(string hostMount, string containerMount, string hostPort, string containerPort, string sdxGenServerVolumeMount, string imageUrl, string serverHost)
4+
public static void Start(string hostMount, string containerMount, string hostPort, string containerPort, string sdxGenServerVolumeMount, string imageUrl, string serverHost, bool resolveLicenses = false)
55
{
6-
var arguments = $"run --rm -v {hostMount}:{containerMount} -p {hostPort}:{containerPort} -v {sdxGenServerVolumeMount}:/app:rw -t {imageUrl} -r /app --server --server-host {serverHost} --restart unless-stopped";
6+
var resolveLicenseEnvironmentVariable = resolveLicenses ? "--env FETCH_LICENSE=true" : "";
7+
var arguments = $"run --rm -v {hostMount}:{containerMount} {resolveLicenseEnvironmentVariable} -p {hostPort}:{containerPort} -v {sdxGenServerVolumeMount}:/app:rw -t {imageUrl} -r /app --server --server-host {serverHost} --restart unless-stopped";
78
ShellService.Service.Execute("docker", arguments, "");
89
ConsoleService.Service.WriteSuccessLine(nameof(CycloneDxManager), "CycloneDX Generator server ready!");
910
}

src/SecTools/SecToolsCommands/PowerCommandsConfiguration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ configuration:
1717
containerMount: /tmp
1818
serverHost: "0.0.0.0"
1919
sbomApiUrl: http://127.0.0.1:9090/sbom
20+
resolveLicenses: true
2021
dependencyTracker:
2122
urlToDockerComposeFile: https://dependencytrack.org/docker-compose.yml
2223
adminUrl: http://localhost:8080

0 commit comments

Comments
 (0)