-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding state and execution modules for compliance workflows. (#404)
* Add salt state and execution modules for compliance check PoC. (#396) * Add salt state and execution modules for compliance check use cases. * Add vcenter state module * rename module names. * incorporate new config module changes. --------- Co-authored-by: ramurugesan <[email protected]> * Compliance control state and execution module refactoring (#397) * VCFSC-42: Add salt state and execution modules for jpmc compliance check use cases. * Add vcenter state module * rename module names. * incorporate new config module changes. * refactoring modules. --------- Co-authored-by: ramurugesan <[email protected]> * change version to dev * Multi product auth support. * fix error message. * Compliance check changes to handle exceptions (#399) * Compliance check changes to handle exceptions * Fix pre-commit issue * Minor fix for compliance check response * Fix unit test cases. --------- Co-authored-by: ramurugesan <[email protected]> * Minor fix to read config from pillar information and then grain (#400) * Incrementing version * Fix priority of importing credentials from pillar first * Adding support for NSX product (#401) * Incrementing version * Fix priority of importing credentials from pillar first * Adding support for product NSX * Add more product support * ESXi Context changes and response format changes. * set results to True for dry-run. * Incorporated config module framework changes. * hostname from grains ('fqdn') if available and then fallback to pillars. * Retrieve hostname from grains and fallback to pillar * Reading ssl verification flag from pillar * Adding product filtering * Optional ssl_thumbprint for esxi context * Fix skipped remediation status for compliance controls * Add controller metadata module (#403) Add controller metadata module --------- Co-authored-by: Russell Jew <[email protected]> * Cleanup code and adding unit test cases * Adding config-module dependency and resolving comment * Ignoring linkcheck for broken links due to migration * Remove docs for invalid modules * Updating tests to run on 3006.9 and python version to 3.10 * Removing python < 3.10 from tests; remove cython dependency from windows; update pytest-salt-factories dependency version * Upgrading salt requires * Test pipeline with previous changes --------- Co-authored-by: Raja Murugesan <[email protected]> Co-authored-by: ramurugesan <[email protected]> Co-authored-by: rjew-bc <[email protected]>
- Loading branch information
1 parent
2a5b0f7
commit 1fa6a84
Showing
21 changed files
with
933 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
docs/ref/modules/saltext.vmware.modules.compliance_control.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
saltext.vmware.modules.compliance_control | ||
========================================= | ||
|
||
.. automodule:: saltext.vmware.modules.compliance_control | ||
:members: |
6 changes: 6 additions & 0 deletions
6
docs/ref/modules/saltext.vmware.modules.controller_metadata.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
saltext.vmware.modules.controller_metadata | ||
========================================== | ||
|
||
.. automodule:: saltext.vmware.modules.controller_metadata | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
saltext.vmware.states.compliance_control | ||
======================================== | ||
|
||
.. automodule:: saltext.vmware.states.compliance_control | ||
:members: |
6 changes: 6 additions & 0 deletions
6
docs/ref/states/saltext.vmware.states.controller_metadata.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
saltext.vmware.states.controller_metadata | ||
========================================= | ||
|
||
.. automodule:: saltext.vmware.states.controller_metadata | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# SPDX-License: Apache-2.0 | ||
import logging | ||
|
||
import salt.exceptions | ||
import saltext.vmware.utils.compliance_control as compliance_control_util | ||
from config_modules_vmware.interfaces.controller_interface import ControllerInterface | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
__virtualname__ = "vmware_compliance_control" | ||
|
||
|
||
def __virtual__(): | ||
return __virtualname__ | ||
|
||
|
||
def control_config_compliance_check(control_config, product, auth_context=None): | ||
""" | ||
Checks compliance of control config. Control config can be ntp, dns, syslog, etc. | ||
Returns control compliance response object. | ||
control_config | ||
control config dict object. | ||
product | ||
appliance name - vcenter, sddc-manager, etc. | ||
auth_context | ||
optional auth context to access product. | ||
""" | ||
|
||
log.info("Checking compliance %s", control_config) | ||
if not auth_context: | ||
config = __opts__ | ||
auth_context = compliance_control_util.create_auth_context(config=config, product=product) | ||
|
||
try: | ||
controller_interface_obj = ControllerInterface(auth_context) | ||
response_check_compliance = controller_interface_obj.check_compliance( | ||
desired_state_spec=control_config | ||
) | ||
log.debug("Response for compliance check %s", response_check_compliance) | ||
return response_check_compliance | ||
except Exception as exc: | ||
log.error("Compliance check encountered an error: %s", str(exc)) | ||
raise salt.exceptions.VMwareRuntimeError(str(exc)) | ||
|
||
|
||
def control_config_remediate(control_config, product, auth_context=None): | ||
""" | ||
Remediate given compliance control config. Control config can be ntp, dns, syslog, etc. | ||
Returns remediation response object. | ||
control_config | ||
control config dict object. | ||
product | ||
appliance name. vcenter, sddc-manager, etc. | ||
auth_context | ||
Optional auth context to access product. | ||
""" | ||
|
||
log.info("Remediation : %s", control_config) | ||
|
||
if not auth_context: | ||
config = __opts__ | ||
auth_context = compliance_control_util.create_auth_context(config=config, product=product) | ||
|
||
try: | ||
controller_interface_obj = ControllerInterface(auth_context) | ||
response_remediate = controller_interface_obj.remediate_with_desired_state( | ||
desired_state_spec=control_config | ||
) | ||
log.debug("Remediation response %s", response_remediate) | ||
return response_remediate | ||
|
||
except Exception as exc: | ||
# Handle exceptions by setting status as false and including exception details | ||
log.error("Remediation encountered an error: %s", str(exc)) | ||
raise salt.exceptions.VMwareRuntimeError(str(exc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# SPDX-License: Apache-2.0 | ||
import logging | ||
|
||
import salt.exceptions | ||
from config_modules_vmware.interfaces.metadata_interface import ControllerMetadataInterface | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
__virtualname__ = "vmware_controller_metadata" | ||
|
||
|
||
def __virtual__(): | ||
return __virtualname__ | ||
|
||
|
||
def validate(controller_metadata): | ||
""" | ||
Validates that the controller custom metadata is valid - has correct product/controls, format, and types. | ||
controller_metadata | ||
controller metadata dict to validate | ||
""" | ||
|
||
log.info("Validating controller metadata: %s", controller_metadata) | ||
|
||
try: | ||
ControllerMetadataInterface.validate_custom_metadata(controller_metadata) | ||
except Exception as exc: | ||
log.error("Error when validating controller metadata: %s", str(exc)) | ||
raise salt.exceptions.VMwareRuntimeError(str(exc)) |
Oops, something went wrong.