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

xccdf to hdf results in empty code_desc #1163

Closed
candrews opened this issue Mar 3, 2023 · 8 comments
Closed

xccdf to hdf results in empty code_desc #1163

candrews opened this issue Mar 3, 2023 · 8 comments

Comments

@candrews
Copy link
Contributor

candrews commented Mar 3, 2023

  1. Download the Ubuntu 18.04 STIG from DISA at https://dl.dod.cyber.mil/wp-content/uploads/stigs/zip/U_CAN_Ubuntu_18-04_V2R8_STIG_SCAP_1-2_Benchmark.zip
  2. Use openscap to generate an xccdf report: oscap-podman ubuntu:18.04 xccdf eval --fetch-remote-resources --profile MAC-3_Public --report report.html --results results.xml U_CAN_Ubuntu_18-04_V2R8_STIG_SCAP_1-2_Benchmark.xml For convenience, here's the resulting results.xml
  3. Use this project to convert the the xccdf results to hdf: npx @mitre/saf convert xccdf_results2hdf -i results.xml -o results.hdf For convenience, here's the resulting results.hdf.json

Actual:
Every instance of code_desc has a value of empty string, for example:

"results": [
  {
    "status": "failed",
    "code_desc": "",
    "start_time": "2023-03-02T09:53:07-05:00"
  }

Expected:
code_desc should have value. Per the hdf documentation at https://github.com/mitre/saf/wiki/HDF-Mapper-and-Converter-Creation-Guide-(for-SAF-CLI-&-Heimdall2)#hdf-schema-breakdown- it should contain "Test expectations as defined by control"

@aaronlippold
Copy link
Member

So you are trying to convert an oscap xccdf-results file to HDF-Results JSON. I would guess this is likely a bug with the nesting of the XML given the results may be pulling that code_desc from a key that may being missed by the mapper.

We would be happy to chat with you about this to see if we can dig into what is causing the mapping issue and get a PR started.

@candrews
Copy link
Contributor Author

candrews commented Mar 3, 2023

We would be happy to chat with you about this to see if we can dig into what is causing the mapping issue and get a PR started.

Sounds great! Is there more information I can provide?

@aaronlippold
Copy link
Member

So I think what we are looking for here is that the XCCDF-Results file actually has the rendered SCAP - vs just a reference to an SCAP XML File - in the final object that we are looping over to create the HDF-Results JSON. If we are - for some reason - missing the step that populates the 'SCAP code' that would be the expected 'code of the test' we expect to be put there. I think we just have to dig in a bit with the debugger.

Does this describe what you are expecting so we are clear on the expected path.

@candrews
Copy link
Contributor Author

candrews commented Mar 3, 2023

I admit that I don't understand all of those details. Basically, I'm looking for the steps I provided in this issue's description to produce an HDF file that has code_desc populated. I'm not knowledgeable enough (yet?) to know exactly how that should be done or why it's not being done today.

@candrews
Copy link
Contributor Author

candrews commented Mar 7, 2023

@aaronlippold is there anything I can do to help this effort?

@candrews
Copy link
Contributor Author

It appears this bug is in @mitre/hdf-converters, and I found the source for that package at https://github.com/mitre/heimdall2/tree/master/libs/hdf-converters

candrews added a commit to candrews/heimdall2 that referenced this issue Apr 13, 2023
* Support XCCDF generated using ComplianceAsCode:
  https://github.com/ComplianceAsCode/content/
* Support nested XCCDF groups
* Set `code_desc` to an appropriate value (not empty string)
* Refactor to remove global variables

Bug: mitre/saf#1163
Fixes: mitre#4194
mergify bot pushed a commit to mitre/heimdall2 that referenced this issue Jul 13, 2023
…ults (#4255)

* Improve xccdf_results_mapper when converting XCCDF->HDF

* Support XCCDF generated using ComplianceAsCode:
  https://github.com/ComplianceAsCode/content/
* Support nested XCCDF groups
* Set `code_desc` to an appropriate value (not empty string)
* Refactor to remove global variables

Bug: mitre/saf#1163
Fixes: #4194

* Minor changes requested by code review

* Use the "RegExp.exec()" method instead

Address sonar finding typescript:S6594

* Set impact to 0 for 'notapplicable' and 'informational' results

* Don't handle every array item within each array item

In handleArray, the array v is looped over. For each item, the entire
array is looped over again, resulting in an array v of length n
resulting in an output array of length n^2, making handleArray's
complexity O(n^2).

However, that n^2 looping is unnecessary. Removing it brings the
complexity of handleArray down to O(n), drastically reducing execution
time.

* "version" should use "version.text" (not just "version")

* For version, prefer version over id

* For version, remove unnecessary comment

* Remove unnecessary String conversion

* Add tsdoc to getRulesInGroup

* removed 'id' as a potential path for 'version'.  the complianceascode sample doesn't contain that attribute at all -> we should not have a tag for it.  also updated samples but these samples updates also include changes from the baseconverter updates so warrant inspection esp for the complianceascode sample output

Signed-off-by: Amndeep Singh Mann <[email protected]>

* linting

Signed-off-by: Amndeep Singh Mann <[email protected]>

* Use triple equals for string comparson

* Various fixes

* Correct "refs" to comply with schema

* Only include description if it has a label

* make the nist family part of the regexes only match against valid nist control families

Signed-off-by: Amndeep Singh Mann <[email protected]>

* Use `as unknown as ControlDescription` instead of `as any`

* Run lint on src/nist.ts

Fixes linting issues introduced in 587282d

* Regenerate samples

Updates samples after 587282d

* Use concise character class syntax '\d' instead of '[0-9]'.

Addresses sonar finding typescript:S6353

* the treemap expects a canonized form of the nist controls that are not zero-padded.  also changed default behaviors so there's no need to supply a parameter to the canonize function at all.

Signed-off-by: Amndeep Singh Mann <[email protected]>

* get rid of dupe nist tags - even if there were dupes in the original file, it makes no sense to have that replicated here anymore really - there are some particularly egregious cases too where a control is replicated at least 3 times in the array

Signed-off-by: Amndeep Singh Mann <[email protected]>

* could simplify the default_partial_config implementation and also ran the linter

Signed-off-by: Amndeep Singh Mann <[email protected]>

* sonarqube

Signed-off-by: Amndeep Singh Mann <[email protected]>

---------

Signed-off-by: Amndeep Singh Mann <[email protected]>
Co-authored-by: Aaron Lippold <[email protected]>
Co-authored-by: Amndeep Singh Mann <[email protected]>
@candrews
Copy link
Contributor Author

candrews commented Jul 14, 2023

Since mitre/heimdall2#4255 has now been merged, the remaining task is to upgrade to @mitre/hdf-converters version 2.6.58 once it is released.

@Amndeep7
Copy link
Contributor

A release has gone out so I'm going to close this issue @candrews. Ping me if you want it to remain open for some reason.

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

No branches or pull requests

3 participants