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

Enable autotailor to process multi-profile JSON Tailorings #2146

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

evgenyz
Copy link
Contributor

@evgenyz evgenyz commented Aug 6, 2024

The script will now accept multiple profiles in JSON Tailorings and also will use command-line options to update existing profiles or will create a new profile in the XCCDF tailoring.

Also, I've added a synonym option --tailoring-profile-id for the existing rather confusing option --new-profile-id.

I've tried to keep backward-compatibility both in logic and in the CLI API.

@evgenyz evgenyz requested a review from jan-cerny August 6, 2024 12:05
@evgenyz evgenyz added this to the 1.4 milestone Aug 6, 2024
@jan-cerny jan-cerny self-assigned this Aug 6, 2024
utils/autotailor Outdated Show resolved Hide resolved
utils/autotailor Outdated Show resolved Hide resolved
\fB--json-tailoring JSON_TAILORING_FILE\fR
.RS
Import tailoring from a JSON file (https://github.com/ComplianceAsCode/schemas/tree/main/tailoring). This option makes BASE_PROFILE_ID positional argument optional.
However, data passed in the command line options takes precedence over JSON contents, including the BASE_PROFILE_ID argument.
When a JSON tailoring is accompanied with additional adjustments from the command-line options either a new profile would be added to the resulting XCCDF tailoring file or the profile with TAILORED_PROFILE_ID identifier, if present, will be updated accordingly.
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem to work the way it's documented here. For example:

utils/autotailor --id-namespace "com.example.www" --json-tailoring tests/utils/custom.json \
 --select R999 tests/utils/data_stream.xml.


Updating an existing profile with `--tailored-profile-id JSON_P1` seems to work.

should create a new profile but it doesn't create a new profile, the output is the same as if run without the --select R999 option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, okay, the thing is that if you actually want a new profile you absolutely must provide base profile id. I can't make it a required parameter if --json-tailoring is present since it is ambiguous what the user actually wants (and depends on the content of the JSON file). I don't want to ruin backward compatibility, so that's what I came up with. If you have any suggestions on how to work around this, I'm all ears.

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is to rephrase the doc text and help text. It needs to be clear that if the --json-tailoring option is set and other options are set at the same time, then the user needs to add --tailored-profile-id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not about --tailored-profile-id (it could be auto-generated) but about BASE_PROFILE positional argument. Which we can't deduce.

Copy link
Member

Choose a reason for hiding this comment

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

but --tailored-profile-id works for me as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reworded the help message a bit.

self.value_changes = set()
self.rules_to_select = set()
self.rules_to_unselect = set()
self.groups_to_select = set()
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't the lists be better to ensure deterministic output? With this change, the generated profiles are ordered randomly. The order or elements shouldn't matter for the functionality but could be unpleasant for users running diffs or our tests. I suggest using lists or keep sets but sort the items at serializing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sets are now converted to sorted lists before being rendered as XML.

utils/autotailor Outdated
@@ -339,7 +367,9 @@ def get_parser():
parser.add_argument(
"-j", "--json-tailoring", metavar="JSON_TAILORING_FILENAME", default="",
help="JSON Tailoring (https://github.com/ComplianceAsCode/schemas/blob/main/tailoring/schema.json) "
"filename.")
"filename. When a JSON tailoring is accompanied with additional adjustments from the command-line"
Copy link
Member

Choose a reason for hiding this comment

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

I suggest improving the help text to clarify that the JSON is an input file that needs to be created and supplied by the user ie. it isn't an output file generated by autotailor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Text has been improved.

utils/autotailor Outdated Show resolved Hide resolved
@evgenyz evgenyz force-pushed the add-multiprofile-tailoring branch 2 times, most recently from c2f1c5d to 32af898 Compare August 7, 2024 19:17
The script will now accept multiple profiles in JSON Tailorings
and also will use command-line options to update existing
profiles or will create a new profile in the XCCDF tailoring.
Copy link
Member

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

I have tried various other options together with the --json-tailoring option. I think that the autotailor tool now behaves according to the proposed documentation change.

@jan-cerny jan-cerny merged commit 572c9b3 into OpenSCAP:main Aug 8, 2024
17 checks passed
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.

2 participants