Repository navigation
feat(exporters): read the CCI mapping file a style names - #56
Merged
Merged
Conversation
Since the first release the DISA style named ident.cci_lookup.mapping_file and CCILookupService could load any mapping file, but the engine always took one shared service built with no file, so a style could not use a CIS-to-CCI mapping of its own. The mapping file a style's ident mapping names is now the one its CCI lookup reads. A relative path is resolved against the folder of the style file that writes it, when that file loads and before it is merged (as extends is; compose-go resolves relative paths per file the same way); an absolute path is used as written. cci_service_for keeps one lookup per resolved path (functools.cache); get_cci_service is the bundled file's. A mapping file that cannot be read, or is not a list of safeguard entries, stops the load with an error naming the style and the file. The shipped styles name no mapping file: disa.yaml's line pointed at the bundled file through a path that only worked because it was never read. Exports are unchanged. Signed-off-by: Aaron Lippold <lippold@gmail.com>
…s entries The shape check covered only the outer list: an OFFICIAL entry whose primary_cci was text passed it and raised AttributeError, with neither the style nor the mapping file named. The entries are now described once (_MappingEntry, _MappedCci, strict, extra keys such as reasoning kept) and validated with pydantic; its ValidationError is a ValueError, so the engine names the style and the mapping file. The reader of OFFICIAL entries reads the models; what it gives is unchanged. Signed-off-by: Aaron Lippold <lippold@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the first release, the DISA style has named a CIS-to-CCI mapping file (
ident.cci_lookup.mapping_file), the docs have shown it, andCCILookupServicewas built to load any mapping file. But the engine always used one shared service built with no file, so a style's mapping file was never read. This PR builds what was intended: the mapping file a style names is the one its CCI lookup reads. A style can now use its own mapping, for example one keyed by another CIS Controls version, or an organization's own.Behaviour
identmapping incci_lookup.mapping_filegives the CCIs. A style that names none reads the bundledsrc/cis_bench/data/cis-cci-mapping.json.extendsis. compose-go resolves relative paths per file the same way. An absolute path is used as written.cci_service_for(path)keeps one lookup per resolved path (functools.cache);get_cci_service()is the bundled file's.reasoningkept. A file that doesn't exist, isn't JSON, or has entries of the wrong shape stops the load with an error naming the style and the mapping file.disa.yaml'smapping_file: "data/cis-cci-mapping.json"only seemed to work because it was never read; resolved against the styles folder, it points at a file that doesn't exist.Docs
mapping-engine-guide.md,yaml-config-reference.mdandxccdf-styles.mddescribemapping_file, how a relative path resolves, and the default.Verification
pytest tests/: 2715 passed.pytest tests/scripts: 53 passed. mypy,ruff check,ruff format --checkandmkdocs build --strictare clean.cis-bench validatepasses on all 28.CCI-999999, carriesCCI-999999on all 43 Rules citing 4.8, and validates.