Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance walkers to create some kind of report #1289

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

bxf12315
Copy link
Collaborator

No description provided.

Copy link
Contributor

@dejanb dejanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few remarks on the first look. I still didn't try to run it

common/walker/Cargo.toml Show resolved Hide resolved
deploy/compose/compose-walkers.yaml Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
@bxf12315 bxf12315 force-pushed the TC-910 branch 3 times, most recently from d36147b to 30ce891 Compare April 19, 2024 03:50
@trust-git-bot
Copy link

trust-git-bot commented Apr 19, 2024

🚀 Deployed Preview: https://trustification-spog-pr-1289-preview.surge.sh

@bxf12315
Copy link
Collaborator Author

retest it

Copy link
Contributor

@dejanb dejanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't run the compose successfully, the walkers panic with

invalid character 's' looking for beginning of value

Did you see this as well? If not, can you provide some basic instructions on how to test it?

common/walker/Cargo.toml Show resolved Hide resolved
deploy/compose/compose.yaml Outdated Show resolved Hide resolved
deploy/compose/compose.yaml Outdated Show resolved Hide resolved
@bxf12315
Copy link
Collaborator Author

I couldn't run the compose successfully, the walkers panic with

invalid character 's' looking for beginning of value

Did you see this as well? If not, can you provide some basic instructions on how to test it?

I can run TRUST_IMAGE=trust TRUST_VERSION=latest docker-compose -f compose.yaml -f compose-guac.yaml -f compose-trustification.yaml -f compose-collectors.yaml -f compose-walkers.yaml up --force-recreate.

Copy link
Contributor

@dejanb dejanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the walker manually for now ingesting dataset1

REPORT_TYPE=SBOM REPORT_PATH=/tmp/share/reports/sbom RUST_LOG=info cargo run -p trust bombastic walker --sink http://localhost:8082 --devmode --source file:./data/ds1/sbom

Here are some comments

common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
deploy/compose/.env Outdated Show resolved Hide resolved
deploy/compose/.env Outdated Show resolved Hide resolved
Copy link
Contributor

@dejanb dejanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. I think things are going in the right direction. Here are some more comments for minor improvements.

common/walker/src/report.rs Outdated Show resolved Hide resolved
deploy/k8s/8.log Outdated Show resolved Hide resolved
deploy/k8s/charts/trustification/values.yaml Outdated Show resolved Hide resolved
deploy/k8s/charts/trustification/values.yaml Outdated Show resolved Hide resolved
Copy link
Contributor

@dejanb dejanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Just a few more minor comments

common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ctron ctron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just took a look at the Rust part. I don't feel having enough understanding of the deployment part.

common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
@bxf12315 bxf12315 force-pushed the TC-910 branch 3 times, most recently from 02ea0fc to 015638d Compare May 16, 2024 14:23
common/walker/src/report.rs Outdated Show resolved Hide resolved
common/walker/src/report.rs Outdated Show resolved Hide resolved
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Walker Report</title>
<link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly/patternfly.css">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for overlooking this before. However, relying on CDNs like this, for a product, will cause some issues.

Assuming this is run in an air-gapped environment, this won't work. I am also not sure if this is compliant with privacy policies like GDPR.

A possible solution would be to provide an env-var (via clap) to customize this base URL. We could then add this as a static asset and configure it's location from the Helm charts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any fix for this. I see that there as an additional ConfigMap replacing this file, injecting this value via Helm. This seems overly complex to me and duplicates the while file.

I think having a way to replace the file is good. However, as we already have a template engine in place, and to replace elements in this file, we should simply re-use that same functionality for replacing the value as well. This would allow us to get rid of all the extra code below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My method is too complicated. I will change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it looks like there's still the link unpkg.

bombastic/walker/src/lib.rs Outdated Show resolved Hide resolved
@bxf12315 bxf12315 force-pushed the TC-910 branch 3 times, most recently from eca6bf8 to 7435cbf Compare May 19, 2024 09:58
log::info!("This report contains no error messages and does not require the generation of an error report");
return Ok(());
}
let template_file_path = env::var_os("TEMPLATE_FILE");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't handled as a clap argument? Including adding the env attribute.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still using env::var_os somewhere inside the code. Why can't this be handled in the place we have the other options, using clap, using the long and env option?


/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/report")]
pub report_path: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason the env attribute is missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sill seems to be unresolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1289 (comment)
so I do not add it in env.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how this aligns with that comment.

  1. There's a default value, having the type of the value Option<T> doesn't seem to make sense
  2. It can be overridden by --report-path (which also seems to be used), for other args we allow overriding by env. I don't see any reason why we shouldn't do this in this case too.
  3. The same seems true for the vexination walker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok , I am not sure my understander is correct, I updated the PR, please check agian.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can keep the default value. Add the env marker and make it String.

common/walker/src/report.rs Outdated Show resolved Hide resolved
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Walker Report</title>
<link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly/patternfly.css">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any fix for this. I see that there as an additional ConfigMap replacing this file, injecting this value via Helm. This seems overly complex to me and duplicates the while file.

I think having a way to replace the file is good. However, as we already have a template engine in place, and to replace elements in this file, we should simply re-use that same functionality for replacing the value as well. This would allow us to get rid of all the extra code below.

deploy/compose/.env Outdated Show resolved Hide resolved
{{- $mod := dict "root" . "name" "report-server" "component" "report" "module" .Values.modules.report -}}


{{/*---*/}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

report:
enabled: true
ingress: {}
infrastructure: {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The infrastructure got removed. Please remove this as well.

ingress: {}
infrastructure: {}
image: {}
patternflyUrl: "https://unpkg.com/@patternfly/patternfly/patternfly.css"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said before, this isn't a viable option for many reasons. I think we should provide a suitable option by default and save us some trouble during productization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define several CSS options by adding a new configuration file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we decided on moving away from this approach and add some static CSS?

pub report_enable: bool,

/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/reports")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the other comment (bombastic) on this option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this issue being resolved.

@bxf12315
Copy link
Collaborator Author

@ctron @dejanb There is a new issue, patternfly.css and patternfly.min.css's sizes are both more than 1m. but configmap's size is 1m. so I can not input CSS file into configmap. So I customized some CSS styles.[1] please check it.
The PR also deploys on [2].

[1] https://github.com/trustification/trustification/pull/1289/files#diff-c94245949b61109bee8690aaba8bddf73b52617107b05fe30621394692139ef7R7
[2] https://report-xiabai-test.apps.scale.scale.trustification.cloud/

deploy/k8s/charts/trustification/values.yaml Outdated Show resolved Hide resolved

/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/report")]
pub report_path: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sill seems to be unresolved.

bombastic/walker/src/lib.rs Outdated Show resolved Hide resolved
pub report_enable: bool,

/// Define report output path
#[arg(long, default_value = "/tmp/share/report")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to have this Option<T> with a default value.

common/walker/src/report.rs Outdated Show resolved Hide resolved
command: [ "/usr/sbin/nginx" ]
args: [ "-g", "daemon off;" ]
ports:
- containerPort: 8018
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the port 8080 in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see port 8080 here, but there's no explanation why this is required.

pub report_enable: bool,

/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/reports")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this issue being resolved.

@bxf12315 bxf12315 force-pushed the TC-910 branch 3 times, most recently from 499ab23 to 5d6ecaf Compare May 30, 2024 10:41
ingress: {}
infrastructure: {}
image: {}
patternflyUrl: "https://unpkg.com/@patternfly/patternfly/patternfly.css"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we decided on moving away from this approach and add some static CSS?

pub report_enable: bool,

/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/report")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[arg(long, default_value = "/tmp/share/report")]
#[arg(long, env, default_value = "/tmp/share/report")]


/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/report")]
pub report_path: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub report_path: Option<String>,
pub report_path: String,

@@ -162,7 +170,9 @@ impl Run {
scanner.run(interval.into()).await?;
} else {
let (report, result) = scanner.run_once().await.split()?;
handle_report(report).await?;
if self.report_enable {
handle_report(report, self.report_path, "Sbom".to_string()).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
handle_report(report, self.report_path, "Sbom".to_string()).await?;
handle_report(report, self.report_path, "SBOM".to_string()).await?;

log::info!("This report contains no error messages and does not require the generation of an error report");
return Ok(());
}
let template_file_path = env::var_os("TEMPLATE_FILE");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still using env::var_os somewhere inside the code. Why can't this be handled in the place we have the other options, using clap, using the long and env option?

let mut tera = Tera::default();
if let Some(file) = template_file_path {
let template_file_path = file.to_str().unwrap_or(DEFAULT_TEMPLATE_FILIE).to_string();
let _ = tera.add_template_files(vec![(template_file_path, Some("report.html"))]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this error should silently be ignored.

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Walker Report</title>
<link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly/patternfly.css">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it looks like there's still the link unpkg.

pub report_enable: bool,

/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/reports")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[arg(long, default_value = "/tmp/share/reports")]
#[arg(long, env, default_value = "/tmp/share/reports")]


/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/reports")]
pub report_path: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub report_path: Option<String>,
pub report_path: String,

Copy link
Contributor

@ctron ctron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the previous review went to an older version of the PR. Not sure what happened, sorry.


/// Path of the HTML output file
#[arg(long, default_value = "/tmp/share/report")]
pub report_path: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can keep the default value. Add the env marker and make it String.

command: [ "/usr/sbin/nginx" ]
args: [ "-g", "daemon off;" ]
ports:
- containerPort: 8018
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see port 8080 here, but there's no explanation why this is required.

vexination/walker/src/lib.rs Outdated Show resolved Hide resolved
vexination/walker/src/lib.rs Outdated Show resolved Hide resolved
@bxf12315
Copy link
Collaborator Author

bxf12315 commented Jun 6, 2024

@dejanb @ctron I add basic auth on report server, please check it. Thanks

@@ -0,0 +1 @@
admin:$apr1$XFCFfzu4$vtfox1qeBPqcZv814kltL1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next step is to make this configurable for the person deploying the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants