diff --git a/utils/autotailor b/utils/autotailor index 3c3e994eaa..a71f44ed3f 100755 --- a/utils/autotailor +++ b/utils/autotailor @@ -300,6 +300,7 @@ class Tailoring: self.id = "xccdf_auto_tailoring_default" self.version = 1 self.original_ds_filename = "" + self.use_relative_path = False self.profiles = [] @@ -319,8 +320,19 @@ class Tailoring: root.set("id", self.id) benchmark = ET.SubElement(root, "{%s}benchmark" % NS) - datastream_uri = pathlib.Path( - self.original_ds_filename).absolute().as_uri() + if self.use_relative_path: + # Preserve relative paths as-is, convert absolute paths to basename + ds_path = pathlib.Path(self.original_ds_filename) + if ds_path.is_absolute(): + # Convert absolute path to basename for compatibility with layered products + datastream_uri = ds_path.name + else: + # Keep relative paths as provided by the user + datastream_uri = self.original_ds_filename + else: + # Use absolute URI (default behavior for backward compatibility) + datastream_uri = pathlib.Path( + self.original_ds_filename).absolute().as_uri() benchmark.set("href", datastream_uri) version = ET.SubElement(root, "{%s}version" % NS) @@ -433,6 +445,10 @@ def get_parser(): "-o", "--output", default="-", help="Where to save the tailoring file. If not supplied, write to " "standard output.") + parser.add_argument( + "--relative-path", action="store_true", + help="Use relative path (basename only) for the benchmark href instead of " + "absolute file:// URI.") return parser @@ -447,6 +463,7 @@ if __name__ == "__main__": t = Tailoring() t.original_ds_filename = args.datastream t.reverse_dns = args.id_namespace + t.use_relative_path = args.relative_path if args.json_tailoring: t.import_json_tailoring(args.json_tailoring)