Skip to content

Conversation

@ggbecker
Copy link
Member

Description:

  • Add option to enable installation of individual ansible tasks per rule.

@ggbecker ggbecker added the Ansible Ansible remediation update. label May 24, 2021
@ggbecker ggbecker added this to the 0.1.57 milestone May 24, 2021
@openshift-ci
Copy link

openshift-ci bot commented May 24, 2021

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label May 24, 2021
CMakeLists.txt Outdated
option(SSG_SEPARATE_SCAP_FILES_ENABLED "If enabled, separate SCAP files (OVAL, XCCDF, CPE dict, ...) will be installed alongside the source data-streams" TRUE)
option(SSG_ANSIBLE_PLAYBOOKS_ENABLED "If enabled, Ansible Playbooks for each profile will be built and installed." TRUE)
option(SSG_BASH_SCRIPTS_ENABLED "If enabled, Bash remediation scripts for each profile will be built and installed." TRUE)
option(SSG_ANSIBLE_TASKS_ENABLED "If enabled, Ansible Tasks for each rule will be installed." FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about guarding the call of the ssg_build_ansible_playbooks macro by this option?

Copy link
Member Author

Choose a reason for hiding this comment

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

it makes sense

Copy link
Member Author

@ggbecker ggbecker May 25, 2021

Choose a reason for hiding this comment

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

can you please check if this is what you had in mind? 1ec2353

CMakeLists.txt Outdated
option(SSG_SEPARATE_SCAP_FILES_ENABLED "If enabled, separate SCAP files (OVAL, XCCDF, CPE dict, ...) will be installed alongside the source data-streams" TRUE)
option(SSG_ANSIBLE_PLAYBOOKS_ENABLED "If enabled, Ansible Playbooks for each profile will be built and installed." TRUE)
option(SSG_BASH_SCRIPTS_ENABLED "If enabled, Bash remediation scripts for each profile will be built and installed." TRUE)
option(SSG_ANSIBLE_TASKS_ENABLED "If enabled, Ansible Tasks for each rule will be installed." FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, these files are Ansible Playbooks, so using the term "tasks" is misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand that... but how should I call them since SSG_ANSIBLE_PLAYBOOKS_ENABLED is already being used?

maybe SSG_ANSIBLE_INDIVIDUAL_PLAYBOOKS_ENABLED or SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed to SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED, see: 81f9051#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR51

if(SSG_ANSIBLE_TASKS_ENABLED)
install(
CODE "
file(GLOB ROLE_FILES \"${CMAKE_BINARY_DIR}/${PRODUCT}/playbooks/*.yml\") \n
Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, these files are Ansible Playbooks and you also have used the misleading word "tasks" for it before so I think using the term "role" for them increases confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

that's correct... it was a copy paste problem

Copy link
Member Author

@ggbecker ggbecker May 25, 2021

Choose a reason for hiding this comment

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

I have also changed the folder's name that holds all the ansible playbooks from tasks to playbooks. So files will be installed to ansible/playbooks/

@jan-cerny jan-cerny changed the title Add option to enable installation of individual ansible tasks per rule. Add option to enable installation of individual ansible tasks per rule May 25, 2021
@ggbecker ggbecker force-pushed the individual-ansible-tasks branch 2 times, most recently from fadda7a to 035fe7a Compare May 25, 2021 15:43
@ggbecker ggbecker marked this pull request as ready for review May 25, 2021 15:48
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label May 25, 2021
@ggbecker ggbecker force-pushed the individual-ansible-tasks branch from 035fe7a to b033813 Compare May 25, 2021 15:49
@JAORMX
Copy link
Contributor

JAORMX commented May 26, 2021

/retest

CODE "
file(GLOB PLAYBOOK_PER_RULE_FILES \"${CMAKE_BINARY_DIR}/${PRODUCT}/playbooks/*\") \n
if(NOT IS_ABSOLUTE ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/playbooks)
file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${SSG_ANSIBLE_ROLE_INSTALL_DIR}/playbooks/${PRODUCT}\"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sorry, I had a comment but I apparently didn't submit it or I misclicked. My comment was that the ${SSG_ANSIBLE_ROLE_INSTALL_DIR} is already used to install profile playbooks. But the downstream Linux distributions will want to place the rule playbooks to a different subpackage than the profile playbooks. Therefore I think it might be better to put the rule playbooks to a different directory than ${SSG_ANSIBLE_ROLE_INSTALL_DIR}. What is your opinion on that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand your concern, but it would feel really strange to have ansible playbooks on a different folder than {SSG_ANSIBLE_ROLE_INSTALL_DIR} (which is usually scap-security-guide/ansible). That's why a created a subfolder called playbooks where this files would be installed. I guess the fact that downstream Linux distributions will use these files on a different subpackage doesn't necessarily mean we have to install these files on a different top-level directory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

but it would feel really strange to have ansible playbooks on a different folder than {SSG_ANSIBLE_ROLE_INSTALL_DIR}

It depends, something like /usr/share/scap-security-guide/rule_ansible_playbooks/ could work.

I guess the fact that downstream Linux distributions will use these files on a different subpackage doesn't necessarily mean we have to install these files on a different top-level directory.

That's correct, it's certainly possible to pick the right items for the (sub)packages in spec file.

I mean I think it's fine in the current form, I was curious if we could come up with something possibly better or not.

Copy link
Member

Choose a reason for hiding this comment

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

As the profile playbooks installed in ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/ are actually playbooks (not roles), how about installing the rule playbooks in ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/rule_playbooks/${PRODUCT}?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that the naming is a bit confusing here. I guess it's better to have explicit than some hidden meaning. I'll update it accordingly. Thanks

@ggbecker ggbecker force-pushed the individual-ansible-tasks branch from b033813 to a705438 Compare May 27, 2021 10:58
@jan-cerny
Copy link
Collaborator

/retest

Copy link
Member

@yuumasato yuumasato left a comment

Choose a reason for hiding this comment

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

Just running cmake I get the following warning for each product:

CMake Warning (dev) at cmake/SSGCommon.cmake:804 (add_dependencies):          
  Policy CMP0046 is not set: Error on non-existent dependency in                                                                                             
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.    
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "generate-chromium-ansible-playbooks" of target
  "chromium-content" does not exist.
Call Stack (most recent call first):
  chromium/CMakeLists.txt:6 (ssg_build_product)
This warning is for project developers.  Use -Wno-dev to suppress it.

The problem is that SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED being false by default, disables ssg_build_ansible_playbooks(${PRODUCT}) which would add the custom_target generate-${PRODUCT}-ansible-playbooks.

@ggbecker
Copy link
Member Author

Just running cmake I get the following warning for each product:

CMake Warning (dev) at cmake/SSGCommon.cmake:804 (add_dependencies):          
  Policy CMP0046 is not set: Error on non-existent dependency in                                                                                             
  add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.    
  Use the cmake_policy command to set the policy and suppress this warning.

  The dependency target "generate-chromium-ansible-playbooks" of target
  "chromium-content" does not exist.
Call Stack (most recent call first):
  chromium/CMakeLists.txt:6 (ssg_build_product)
This warning is for project developers.  Use -Wno-dev to suppress it.

The problem is that SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED being false by default, disables ssg_build_ansible_playbooks(${PRODUCT}) which would add the custom_target generate-${PRODUCT}-ansible-playbooks.

That's why I had initially an OR logic expression in the condition for ssg_build_ansible_playbooks call... I guess I'll have to reevaluate some things. Thanks for noticing that.

@yuumasato
Copy link
Member

That's why I had initially an OR logic expression in the condition for ssg_build_ansible_playbooks call... I guess I'll have to reevaluate some things. Thanks for noticing that.

I think the AND makes sense. A solution could be to declare the custom target directly in the ssg_build_product macro, like in:

add_custom_target(${PRODUCT}-content)

@ggbecker
Copy link
Member Author

That's why I had initially an OR logic expression in the condition for ssg_build_ansible_playbooks call... I guess I'll have to reevaluate some things. Thanks for noticing that.

I think the AND makes sense. A solution could be to declare the custom target directly in the ssg_build_product macro, like in:

add_custom_target(${PRODUCT}-content)

hopefully that's what you had in mind :) f7bb68f

Copy link
Member

@yuumasato yuumasato left a comment

Choose a reason for hiding this comment

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

hopefully that's what you had in mind :) f7bb68f

Almost there, see my comments.

@ggbecker ggbecker force-pushed the individual-ansible-tasks branch from f7bb68f to 141dce8 Compare May 27, 2021 14:28
@ggbecker
Copy link
Member Author

hopefully that's what you had in mind :) f7bb68f

Almost there, see my comments.

Okay, done in 141dce8 (amended commit)

@yuumasato
Copy link
Member

hopefully that's what you had in mind :) f7bb68f

Almost there, see my comments.

Okay, done in 141dce8 (amended commit)

Now I get warnings when doing this, :(
cmake -DSSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED:BOOLEAN=ON ../

@ggbecker I apologize, my suggestion doesn't work as expected. add_dependencies() only works on targets, not files.

I think you'll need to have a better look on why this dependency is added here:

add_dependencies(
${PRODUCT}-content
generate-${PRODUCT}-ansible-playbooks
)

To me it looks like it should be moved closer to where it is defined.

@ggbecker ggbecker changed the title Add option to enable installation of individual ansible tasks per rule Add option to enable installation of individual ansible playbooks per rule May 31, 2021
@ggbecker
Copy link
Member Author

hopefully that's what you had in mind :) f7bb68f

Almost there, see my comments.

Okay, done in 141dce8 (amended commit)

Now I get warnings when doing this, :(
cmake -DSSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED:BOOLEAN=ON ../

@ggbecker I apologize, my suggestion doesn't work as expected. add_dependencies() only works on targets, not files.

I think you'll need to have a better look on why this dependency is added here:

add_dependencies(
${PRODUCT}-content
generate-${PRODUCT}-ansible-playbooks
)

To me it looks like it should be moved closer to where it is defined.

I brought the dependency definition closer to the target definition. That might fix the issue, although I'm not entirely sure if this would cause any undesired side effect. See: 02df119

@yuumasato
Copy link
Member

@ggbecker The rule playbooks were not being built with 02df119.
I made a PR to your branch.
It would also be good to squash the last few commits to clean up a bit this back and forth with the target and dependencies.

@ggbecker
Copy link
Member Author

@ggbecker The rule playbooks were not being built with 02df119.
I made a PR to your branch.

Thank you very much.

It would also be good to squash the last few commits to clean up a bit this back and forth with the target and dependencies.

I definitely will :D

@ggbecker ggbecker force-pushed the individual-ansible-tasks branch from 605f4a3 to f637c88 Compare May 31, 2021 16:09
Copy link
Member

@yuumasato yuumasato left a comment

Choose a reason for hiding this comment

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

LGTM, I just have one comment about the install path of rule playbooks.

CODE "
file(GLOB PLAYBOOK_PER_RULE_FILES \"${CMAKE_BINARY_DIR}/${PRODUCT}/playbooks/*\") \n
if(NOT IS_ABSOLUTE ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/playbooks)
file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${SSG_ANSIBLE_ROLE_INSTALL_DIR}/playbooks/${PRODUCT}\"
Copy link
Member

Choose a reason for hiding this comment

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

As the profile playbooks installed in ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/ are actually playbooks (not roles), how about installing the rule playbooks in ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/rule_playbooks/${PRODUCT}?

ggbecker and others added 2 commits June 1, 2021 14:49
A dependency on rule playbooks target was being added from a
conditional branch related to profile playbooks.
It caused issues when building profile playbooks but not rule playbooks,
the rule playbooks target would not exist, but still be added as
dependency.

Co-authored-by: Watson Sato <[email protected]>
@ggbecker ggbecker force-pushed the individual-ansible-tasks branch from f637c88 to 8b99c9c Compare June 1, 2021 12:50
@ggbecker
Copy link
Member Author

ggbecker commented Jun 1, 2021

LGTM, I just have one comment about the install path of rule playbooks.

I have updated the installing directory.

@yuumasato
Copy link
Member

@JAORMX Hey man, I see a a lot of "didn't match expected results" in the rhcos e2e, are these somehow expected?
I don't see how changes in this PR would cause it.
The expected result for the audit_rules_etc_group_open rule didn't match. Expected 'PASS', Got 'FAIL'

@yuumasato
Copy link
Member

/retest

@yuumasato
Copy link
Member

Test results look good now, :)

@yuumasato yuumasato merged commit 04055c6 into ComplianceAsCode:master Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ansible Ansible remediation update.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants