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

Improve Kickstart remediations #2147

Merged
merged 1 commit into from
Aug 13, 2024
Merged

Conversation

evgenyz
Copy link
Contributor

@evgenyz evgenyz commented Aug 6, 2024

Add header-less variant via --raw switch.

The purpose of the raw mode is to be tools, integrations and customization-friendly. It is not meant to be directly consumable by a user.

For now the behavior is implemented only for Kickstart remediation type. We'll derefine the raw shape of others later.

@evgenyz evgenyz requested a review from jan-cerny August 6, 2024 20:54
@evgenyz evgenyz added this to the 1.4 milestone Aug 6, 2024
@evgenyz evgenyz force-pushed the add-generate-raw-fix branch 2 times, most recently from d1ec3ed to 40d5fa6 Compare August 7, 2024 19:29
@jan-cerny
Copy link
Member

@evgenyz Nice idea! I think that we can go this way. Please be aware that for some remediation types (Ansible, Kickstart) the "header" also contains essential parts of the output that shouldn't be removed. On the other hand, in some remediation types (Bash, Kickstart) additional comments are added also in a lower part of the generated output and these are not essential so we can remove these in the --raw mode.

@jan-cerny jan-cerny self-assigned this Aug 9, 2024
@evgenyz
Copy link
Contributor Author

evgenyz commented Aug 9, 2024

Come to think about it, if we are going to backport it we'd better not break the API in this change. Hmm.

@evgenyz
Copy link
Contributor Author

evgenyz commented Aug 9, 2024

OTOH, we already broke it in the initial PR with the Kickstart remediation.

@evgenyz evgenyz force-pushed the add-generate-raw-fix branch 2 times, most recently from 3685163 to 23f655a Compare August 12, 2024 06:19
@evgenyz evgenyz marked this pull request as ready for review August 12, 2024 06:21
if (raw == 0) {
char *password = oscap_generate_random_string(24, NULL);
char *common = oscap_sprintf(common_template, password);
_write_text_to_fd(output_fd, common);
Copy link
Member

Choose a reason for hiding this comment

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

But without the items from the common_template, the generated kickstart won't be sufficient for automated installation of the operating system, in other words the installation will require user interaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The raw form is not meant to be easy-consumable, its purpose is to be convenient for parsing and customization using automation tools. It is going to be tools-friendly, not user-friendly.

@@ -0,0 +1,56 @@
# Create partition layout scheme (required for security compliance)
Copy link
Member

Choose a reason for hiding this comment

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

Why are these headers kept in the raw output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After another round of discussion with Satellite , I've changed the way we format sections in raw mode. It does not have comment headers now, but for partitioning scheme it has pseudo-sections # %partitions, # %logvols closed with # %end to make it easier for them to parse.

return 1;
}
if (raw == 0)
if (_write_script_header_to_fd(policy, result, sys, input_file_name, tailoring_file_name, output_fd) != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

When generating Ansible Playbooks the output is invalid because this part contains essential part of the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -520,7 +520,7 @@ OSCAP_API bool xccdf_policy_resolve(struct xccdf_policy * policy);
* @param output_fd write prescription to this file descriptor
* @returns zero on success, non-zero indicate partial (incomplete) output.
*/
OSCAP_API int xccdf_policy_generate_fix(struct xccdf_policy *policy, struct xccdf_result *result, const char *sys, const char *input_file_name, struct oscap_source *tailoring, int output_fd);
OSCAP_API int xccdf_policy_generate_fix(struct xccdf_policy *policy, struct xccdf_result *result, const char *sys, const char *input_file_name, struct oscap_source *tailoring, int output_fd, int raw);
Copy link
Member

Choose a reason for hiding this comment

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

missing Doxygen text for the new raw parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

The option would allow the user to generate fix scripts
without headers and boilerplate. Currently implemented
for Kickstart remediation type.
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.

For current upstream scap-secutiy-guide I have generated various remediations (Ansible, Bash, Kickstart, Blueprint) both with and without the --raw option for multiple profiles and checked them.

@jan-cerny jan-cerny merged commit 868a973 into OpenSCAP:main Aug 13, 2024
17 checks passed
@evgenyz evgenyz deleted the add-generate-raw-fix branch August 13, 2024 12:30
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