summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnst Sjöstrand <ernstp@gmail.com>2022-05-24 13:50:21 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-04 12:16:59 +0100
commitcc3cefdb43dadb9108bc1929b3a7589f4c97b11e (patch)
tree91ece031e2346fbe9819e21003323a8030de3a77
parentb0cff6d434a2f590aa916704560a71fa3ea0dee0 (diff)
downloadpoky-cc3cefdb43dadb9108bc1929b3a7589f4c97b11e.tar.gz
cve-check: Only include installed packages for rootfs manifest
Before this the rootfs manifest and the summary were identical. We should separate the summary and rootfs manifest more clearly, now the summary is for all CVEs and the rootfs manifest is only for things in that image. This is even more useful if you build multiple images. (From OE-Core rev: 2bacd7cc67b2f624885ce9c9c9e48950b359387d) Signed-off-by: Ernst Sjöstrand <ernstp@gmail.com> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 3b8cc6fc45f0ea5677729ee2b1819bdc7a441ab1) Signed-off-by: Steve Sakoman <steve@sakoman.com> (cherry picked from commit 65498411d73e8008d5550c2d0a1148f990717587) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/cve-check.bbclass69
1 files changed, 54 insertions, 15 deletions
diff --git a/meta/classes/cve-check.bbclass b/meta/classes/cve-check.bbclass
index 3cae0e8eb2..29b276e491 100644
--- a/meta/classes/cve-check.bbclass
+++ b/meta/classes/cve-check.bbclass
@@ -171,6 +171,8 @@ python cve_check_write_rootfs_manifest () {
171 """ 171 """
172 172
173 import shutil 173 import shutil
174 import json
175 from oe.rootfs import image_list_installed_packages
174 from oe.cve_check import cve_check_merge_jsons 176 from oe.cve_check import cve_check_merge_jsons
175 177
176 if d.getVar("CVE_CHECK_COPY_FILES") == "1": 178 if d.getVar("CVE_CHECK_COPY_FILES") == "1":
@@ -181,26 +183,63 @@ python cve_check_write_rootfs_manifest () {
181 if os.path.exists(deploy_file_json): 183 if os.path.exists(deploy_file_json):
182 bb.utils.remove(deploy_file_json) 184 bb.utils.remove(deploy_file_json)
183 185
184 if os.path.exists(d.getVar("CVE_CHECK_TMP_FILE")): 186 # Create a list of relevant recipies
185 bb.note("Writing rootfs CVE manifest") 187 recipies = set()
186 deploy_dir = d.getVar("DEPLOY_DIR_IMAGE") 188 for pkg in list(image_list_installed_packages(d)):
187 link_name = d.getVar("IMAGE_LINK_NAME") 189 pkg_info = os.path.join(d.getVar('PKGDATA_DIR'),
190 'runtime-reverse', pkg)
191 pkg_data = oe.packagedata.read_pkgdatafile(pkg_info)
192 recipies.add(pkg_data["PN"])
193
194 bb.note("Writing rootfs CVE manifest")
195 deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
196 link_name = d.getVar("IMAGE_LINK_NAME")
197
198 json_data = {"version":"1", "package": []}
199 text_data = ""
200 enable_json = d.getVar("CVE_CHECK_FORMAT_JSON") == "1"
201 enable_text = d.getVar("CVE_CHECK_FORMAT_TEXT") == "1"
202
203 save_pn = d.getVar("PN")
204
205 for pkg in recipies:
206 # To be able to use the CVE_CHECK_RECIPE_FILE variable we have to evaluate
207 # it with the different PN names set each time.
208 d.setVar("PN", pkg)
209 if enable_text:
210 pkgfilepath = d.getVar("CVE_CHECK_RECIPE_FILE")
211 if os.path.exists(pkgfilepath):
212 with open(pkgfilepath) as pfile:
213 text_data += pfile.read()
214
215 if enable_json:
216 pkgfilepath = d.getVar("CVE_CHECK_RECIPE_FILE_JSON")
217 if os.path.exists(pkgfilepath):
218 with open(pkgfilepath) as j:
219 data = json.load(j)
220 cve_check_merge_jsons(json_data, data)
221
222 d.setVar("PN", save_pn)
223
224 if enable_text:
225 link_path = os.path.join(deploy_dir, "%s.cve" % link_name)
188 manifest_name = d.getVar("CVE_CHECK_MANIFEST") 226 manifest_name = d.getVar("CVE_CHECK_MANIFEST")
189 cve_tmp_file = d.getVar("CVE_CHECK_TMP_FILE")
190 227
191 bb.utils.mkdirhier(os.path.dirname(manifest_name)) 228 with open(manifest_name, "w") as f:
192 shutil.copyfile(cve_tmp_file, manifest_name) 229 f.write(text_data)
193 230
194 manifest_link = os.path.join(deploy_dir, "%s.cve" % link_name) 231 update_symlinks(manifest_name, link_path)
195 update_symlinks(manifest_name, manifest_link)
196 bb.plain("Image CVE report stored in: %s" % manifest_name) 232 bb.plain("Image CVE report stored in: %s" % manifest_name)
197 233
198 if d.getVar("CVE_CHECK_FORMAT_JSON") == "1": 234 if enable_json:
199 link_path = os.path.join(deploy_dir, "%s.json" % link_name) 235 link_path = os.path.join(deploy_dir, "%s.json" % link_name)
200 manifest_path = d.getVar("CVE_CHECK_MANIFEST_JSON") 236 manifest_name = d.getVar("CVE_CHECK_MANIFEST_JSON")
201 bb.note("Generating JSON CVE manifest") 237
202 generate_json_report(d, manifest_path, link_path) 238 with open(manifest_name, "w") as f:
203 bb.plain("Image CVE JSON report stored in: %s" % link_path) 239 json.dump(json_data, f, indent=2)
240
241 update_symlinks(manifest_name, link_path)
242 bb.plain("Image CVE JSON report stored in: %s" % manifest_name)
204} 243}
205 244
206ROOTFS_POSTPROCESS_COMMAND_prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}" 245ROOTFS_POSTPROCESS_COMMAND_prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"