Creating and persisting a custom XCCDF Profile from scratch via libopenscap's C API #2395
|
Hello everyone, I'm working with libopenscap's C API directly (not the I already wrote my own function to traverse a Benchmark and collect all its Rule items, since I couldn't find a built-in getter that returns the full rule list directly — happy to know if I missed one. What I'm trying to figure out is the correct API-level workflow to:
So my questions are:
For context: I'm using the SCAP Security Guide content as my SCAP source, and my end goal is to let users pick freely from all rules of a benchmark (not just those already in one specific named profile), then save the resulting custom profile for reuse and auditing. Thanks in advance! |
Replies: 1 comment 1 reply
|
Yes, the C API has the pieces for this. The workflow I would use is to persist a Tailoring document, not to write only a detached The relevant public API names are in
A minimal shape is roughly: struct xccdf_tailoring *tailoring = xccdf_tailoring_new();
xccdf_tailoring_set_id(tailoring, "xccdf_org.example_tailoring_custom");
xccdf_tailoring_set_benchmark_ref(tailoring, benchmark_href_or_id);
struct xccdf_profile *profile = xccdf_profile_new();
xccdf_profile_set_id(profile, "xccdf_org.example_profile_custom");
xccdf_profile_set_tailoring(profile, true);
for (each selected_rule_id) {
struct xccdf_select *sel = xccdf_select_new();
xccdf_select_set_item(sel, selected_rule_id);
xccdf_select_set_selected(sel, true);
xccdf_profile_add_select(profile, sel);
}
xccdf_tailoring_add_profile(tailoring, profile);
xccdf_tailoring_export(
tailoring,
"custom-tailoring.xml",
xccdf_benchmark_get_schema_version(benchmark)
);You do not need the custom profile to For rule enumeration, I do not think there is a single "return all rules recursively" getter. The public API exposes tree traversal primitives: start with For persistence/reload, keep the tailoring file next to the original content and evaluate with the original benchmark plus the tailoring file/profile. That matches OpenSCAP’s own tailoring tests: the tailoring XML carries the customized profile, while the rule definitions remain in the benchmark/data stream. If this matches your use case, please mark it as answered so other libopenscap users can find the profile/select/tailoring API path. |
Yes, the C API has the pieces for this. The workflow I would use is to persist a Tailoring document, not to write only a detached
<Profile>fragment. That keeps the custom profile auditable while still referencing the original Benchmark/DataStream.The relevant public API names are in
src/XCCDF/public/xccdf_benchmark.h:xccdf_profile_new()/xccdf_profile_set_id()to create the profilexccdf_select_new()/xccdf_select_set_item()/xccdf_select_set_selected()to create each rule selectionxccdf_profile_add_select()to attach selections to the profilexccdf_tailoring_new()/xccdf_tailoring_set_id()/xccdf_tailoring_set_benchmark_ref()/xccdf_tailoring_add_profile()xccdf_tailoring_expo…