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

Fix STIG IDs reference processing #4725

Merged
merged 3 commits into from
Aug 22, 2019

Conversation

jan-cerny
Copy link
Collaborator

@jan-cerny jan-cerny commented Aug 14, 2019

Description:

This PR allows to assign a rule multiple STIG IDs using a comma-separated list which is the same way we use for the other references. prevents people from assigning a rule multiple STIG IDs using a comma-separated list because a rule can have only 1 STIG ID.

There were 2 basic problems:

  1. Python code converting YAML to shorthand was not splitting the string at comma.
  2. XSLT template that converts shorhand to XCCDF had a special treatment for STIG IDs which always copies the whole attribute value instead of each identifier which lead to duplicate reference elements.

Note: there was some stigid-concat which I can't find anywhere and it seems to be evaluated as empty string which means result of concatenating it with any string is that string.

Rationale:

In #4706 we encountered that using a comma separated list for RHEL7 STIG ID doesn't work.

@matejak
Copy link
Member

matejak commented Aug 14, 2019

The tests/unit/ssg-module/test_build_yaml.py unit test needs to be updated, as we now don't have STIG IDs where the ID has the product-prefix s.a. RHEL-07-27445-6 on the input (i.e. in rule.yml files).

@matejak matejak self-assigned this Aug 14, 2019
@matejak matejak added the Python label Aug 14, 2019
@matejak matejak added this to the 0.1.46 milestone Aug 14, 2019
@redhatrises
Copy link
Contributor

redhatrises commented Aug 14, 2019

Yes. This is very intentional and should not be changed as it breaks downstream users functionality.

@matejak
Copy link
Member

matejak commented Aug 15, 2019

@redhatrises Could you please explain in greater detail? This PR allows rules to have multiple STIG IDs, and it doesn't change anything for rules that have one or zero STIG IDs. The product-prefix I was referring to is related to input, i.e. to yaml files, the STIG ID appearance in the datastream won't change.

@redhatrises
Copy link
Contributor

@redhatrises Could you please explain in greater detail? This PR allows rules to have multiple STIG IDs, and it doesn't change anything for rules that have one or zero STIG IDs. The product-prefix I was referring to is related to input, i.e. to yaml files, the STIG ID appearance in the datastream won't change.

There can only be 1 STIGID to a rule not multiple. Enabling multiple STIG IDs to a rule is introducing a bug.

@jan-cerny
Copy link
Collaborator Author

@redhatrises Aha, OK, I didn't know that. Then this patch isn't needed.

But, because this limitation is not obvious, I suggest adding a check to the Python code to verify that there is a single ID and its format is correct.

We also still can merge the unit test change from in 2ba63a9 and then we could remove the code that handled inconsistent usage of RHEL-06- prefixes, because we already changed all rule.ymls to not use prefixes for both RHEL6 and RHEL7 STIG IDs. (The prefixes are added automatically during the build.)

@matejak
Copy link
Member

matejak commented Aug 16, 2019

I think that there is nothing wrong with this PR - it gets some things right, and as a side-effect, it opens door to multiple STIG IDs in the content.

If @jan-cerny adds some assert to build_yaml.py that will make sure that at most one STIG ID is allowed, we are good.

@redhatrises Could you please provide a reference that we could use to document the test, so it is easy to determine why two and more STIG IDs are a no-go? I was unable to find this claim on my own.

@shawndwells
Copy link
Member

@redhatrises Could you please provide a reference that we could use to document the test, so it is easy to determine why two and more STIG IDs are a no-go? I was unable to find this claim on my own.

Not sure what is meant -- reference to document the test?

Each configuration rule must attest a single configuration action, and receive a single CCE.

Each configuration rule should have a single DISA reference as well. Sometimes DISA's rules accidentally evaluate two configuration settings in a single rule; in those cases we alert them to the mistake and they're separated out.

@matejak
Copy link
Member

matejak commented Aug 19, 2019

@shawndwells Why have you closed that PR? Right now, there is nothing that could stop content authors to define multiple STIG IDs to one rule. This PR can fix this easily.
By reference I meant an answer to a question that an uninformed content creator may have in the future - "why it is not possible for one rule to have multiple STIG IDs - is it an artificial limitation, or is there a real reason for it"?

@jan-cerny jan-cerny reopened this Aug 19, 2019
@jan-cerny
Copy link
Collaborator Author

@matejak I have changed the code to raise an exception when somebody tries to have multiple STIG IDs in a rule.

@redhatrises
Copy link
Contributor

I believe that these changes are good to go. I will create a PR to talk about reference handling in the documentation... I thought I did already did that to reduce confusion for authors, but I must have dreamt it!

We have stopped using the prefixed format RHEL-06- in
5897bac
After that we don't need the functionality anymore
therefore we don't need to test it.
This PR allows to assign a rule multiple STIG IDs using a
comma-separated list which is the same way we use for the other
references. There were 2 basic problems: 1. Python code converting YAML
to shorthand was not splitting the string at comma. 2. XSLT template
that converts shorhand to XCCDF had a special treatment for STIG IDs
which always copies the whole attribute value instead of each identifier
which lead to duplicate `reference` elements.
The code will raise an exception when rule author tries to define
multiple STIG IDs in a single rule using a comma-separated list.
The patch also extends unit tests to cover this case.
@jan-cerny
Copy link
Collaborator Author

@matejak rebased on the top of master

@matejak
Copy link
Member

matejak commented Aug 22, 2019

Great, thank you for the effort and everybody for remarks!

@matejak matejak merged commit 3054f4f into ComplianceAsCode:master Aug 22, 2019
This pull request was closed.
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.

4 participants