-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Linux Kernel cataloger #1694
Conversation
1520164
to
8127d42
Compare
Some sample output from a directory with a kernel file: {
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "/home/ubuntu/eve/rootfs/boot/",
"documentNamespace": "https://anchore.com/syft/dir/home/ubuntu/eve/rootfs/boot-b6c3a42e-a58e-4d40-baf6-0629dfea8599", "creationInfo": {
"licenseListVersion": "3.20",
"creators": [
"Organization: Anchore, Inc",
"Tool: syft-[not provided]"
], "created": "2023-03-24T07:50:58Z"
},
"packages": [
{
"name": "linux-kernel",
"SPDXID": "SPDXRef-Package-linux-kernel-linux-kernel-cbf2ab66dde87d2d",
"versionInfo": "5.10.121-linuxkit (root@buildkitsandbox) #1 SMP Fri Dec 2 10:35:42 UTC 2022",
"downloadLocation": "NOASSERTION",
"sourceInfo": "acquired package info from the following paths: ",
"licenseConcluded": "NONE",
"licenseDeclared": "NONE",
"copyrightText": "NOASSERTION",
"externalRefs": [
{
"referenceCategory": "SECURITY",
"referenceType": "cpe23Type",
"referenceLocator": "cpe:2.3:a:linux-kernel:linux-kernel:5.10.121-linuxkit_\\(root\\@buildkitsandbox\\)_\\#1_SMP_Fri_Dec_2_10\\:35\\:42_UTC_2022:*:*:*:*:*:
*:*"
},
{
"referenceCategory": "SECURITY",
"referenceType": "cpe23Type",
"referenceLocator": "cpe:2.3:a:linux-kernel:linux_kernel:5.10.121-linuxkit_\\(root\\@buildkitsandbox\\)_\\#1_SMP_Fri_Dec_2_10\\:35\\:42_UTC_2022:*:*:*:*:*:
*:*"
},
{
"referenceCategory": "SECURITY",
"referenceType": "cpe23Type",
"referenceLocator": "cpe:2.3:a:linux_kernel:linux-kernel:5.10.121-linuxkit_\\(root\\@buildkitsandbox\\)_\\#1_SMP_Fri_Dec_2_10\\:35\\:42_UTC_2022:*:*:*:*:*:
*:*"
},
{
"referenceCategory": "SECURITY",
"referenceType": "cpe23Type",
"referenceLocator": "cpe:2.3:a:linux_kernel:linux_kernel:5.10.121-linuxkit_\\(root\\@buildkitsandbox\\)_\\#1_SMP_Fri_Dec_2_10\\:35\\:42_UTC_2022:*:*:*:*:*:
*:*"
},
{
"referenceCategory": "SECURITY",
"referenceType": "cpe23Type",
"referenceLocator": "cpe:2.3:a:linux:linux-kernel:5.10.121-linuxkit_\\(root\\@buildkitsandbox\\)_\\#1_SMP_Fri_Dec_2_10\\:35\\:42_UTC_2022:*:*:*:*:*:*:*"
},
{
"referenceCategory": "SECURITY",
"referenceType": "cpe23Type",
"referenceLocator": "cpe:2.3:a:linux:linux_kernel:5.10.121-linuxkit_\\(root\\@buildkitsandbox\\)_\\#1_SMP_Fri_Dec_2_10\\:35\\:42_UTC_2022:*:*:*:*:*:*:*"
},
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceType": "purl",
"referenceLocator": "pkg:linux-kernel/[email protected]"
}
]
}
],
"relationships": [
{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-DOCUMENT",
"relationshipType": "DESCRIBES"
}
]
} |
Nice! One comment on the version value:
These are generated downstream of package creation today (this may change in the future, but for the meantime it's here https://github.com/anchore/syft/blob/v0.75.0/syft/pkg/cataloger/catalog.go#L79 ... running after the catalog creates the package). Also regarding the pURL: as far as I can tell there isn't a "kernel" (or "kernel"-like) pURL to use. This feels like it should be a |
as long as the syft/syft/artifact/relationship.go Line 8 in 81b87dd
|
I'm not certain I 100% follow yet, but if you are looking to have "owned files" as part of the concept of the kernel package then all you would need to do is to have the package metadata implement the FileOwner interface (https://github.com/anchore/syft/blob/main/syft/pkg/file_owner.go) and this should be automagically handled downstream in syft (example: https://github.com/anchore/syft/blob/main/syft/pkg/rpm_metadata.go#L50-L60). |
I changed it to just use the "base" version.
I changed it to
It has nothing to capture the additional meta information other than the usual known qualifiers, listed here, which basically are So where else should we capture it? In the kernel itself, the whole thing is a single string. To use my example above, When you run |
5200c78
to
1e96889
Compare
I updated this to be able to scan kernel modules as well. It is successfully finding them, parsing them, getting module information out of them. But then it needs to add them to a package, including per-module metadata. I assumed that would be the same as the kernel package, but if I do anything different (e.g. So how do I:
|
1e96889
to
bcfff4e
Compare
Also, in doing the purl for the kernel as |
eaae5c2
to
bb6f69c
Compare
Signed-off-by: Avi Deitcher <[email protected]>
bb6f69c
to
c9637b8
Compare
Signed-off-by: Alex Goodman <[email protected]>
The short answer to some of your questions is that the cataloger your writing needs to use the ...
{
"id": "ffe5a39e57372695",
"name": "linux-kernel",
"version": "6.2.8-060208-generic",
"type": "generic/linux-kernel",
"foundBy": "linux-kernel-cataloger",
"locations": [
{
"path": "vmlinuz-6.2.8-060208-generic"
}
{
"path": "mods/crc32c-intel.ko"
},
],
"licenses": [],
"language": "",
"cpes": [
"cpe:2.3:a:linux-kernel:linux-kernel:6.2.8-060208-generic:*:*:*:*:*:*:*",
"cpe:2.3:a:linux-kernel:linux_kernel:6.2.8-060208-generic:*:*:*:*:*:*:*",
"cpe:2.3:a:linux_kernel:linux-kernel:6.2.8-060208-generic:*:*:*:*:*:*:*",
"cpe:2.3:a:linux_kernel:linux_kernel:6.2.8-060208-generic:*:*:*:*:*:*:*",
"cpe:2.3:a:linux:linux-kernel:6.2.8-060208-generic:*:*:*:*:*:*:*",
"cpe:2.3:a:linux:linux_kernel:6.2.8-060208-generic:*:*:*:*:*:*:*"
],
"purl": "pkg:generic/[email protected]",
"metadataType": "KernelPackageMetadata",
"metadata": {
"architecture": "x86",
"version": "6.2.8-060208-generic",
"extendedVersion": "6.2.8-060208-generic (kernel@sita) #202303220943 SMP PREEMPT_DYNAMIC Wed Mar 22 13:50:04 UTC 2023",
"format": "bzImage",
"videoMode": "Video mode 65535",
"modules": [
{
"kernelVersion": "4.18.0-448.el8.x86_64",
"versionMagic": "4.18.0-448.el8.x86_64 SMP mod_unload modversions ",
"sourceVersion": "1E7D107C937AAE2A22F9942",
"author": "Austin Zhang <[email protected]>, Kent Liu <[email protected]>",
"license": "GPL",
"name": "crc32c_intel",
"description": "CRC32c (Castagnoli) optimization using Intel Hardware.",
"path": "mods/crc32c-intel.ko"
}
]
}
}
... I generated something like this that uses your kernel cataloger but instead of adding another cataloger for the modules, have the kernel Cataloger continue to search for modules once a kernel is found. This gives you the most flexibility for the kind of capabilities you're looking for I think. I just pushed some code, but consider it to be more of a "draft", as there are still some problems to solve. The biggest one is to make certain that the modules found really do correspond to the kernel that it's being paired with. (also just to be clear, feel free to throw away any code I'm pushing to your) |
To answer more explicitly:
By having one cataloger parser function deal with looking up more supporting files to catalog (instead of adding another cataloger and depending on package merging, which will be more difficult to deal with in the code base as time moves forward).
By adding the module information as a child of the kernel metadata.
This has to be done explicitly within the cataloger as new module locations are found.
Just as mentioned in answering 2, this is much easier if the module metadatas are children of the parent kernel metadata. Side note: most catalogers aren't like this, but some are. The DPKG cataloger comes to mind... where the package DB file is cataloged first and additional file paths are cataloged as supporting evidence of the discovered package on the fly. |
Thanks, I will look at your push and see if I can update it. |
I see what you did, that makes sense. A new cataloger is only for a new package entry. Once you hit a cataloger, it should find all of its children. I don't like having all of those hundreds of files in The part I don't get is about I get additional files. You wrote:
I don't see a standard for it. The definition of |
30183dd
to
7f942f1
Compare
Cleaned up the How I actually add the files, though, still is beyond me. EDIT: OK, now I see it, the The only thing I am missing, then, is the metadata on those files. Is there any way to report on them? We extract them and make them part of the |
Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: Avi Deitcher <[email protected]>
7f942f1
to
c33e142
Compare
Currently syft-json and CycloneDX formats support showing these attributes. For syft-json there is nothing left to do, it will be shown automatically. For CyloneDX you will need to map the specific parameters that are worth capturing with the
I don't think I entirely understand your comment about checksums. The file digest cataloger can capture checksums for files and can be enabled with the Capturing structured data in the comments field is something that we try to avoid when possible. We have very few exceptions to this. Capturing arbitrary metadata into SPDX is a current limitation of the format. |
Also, regarding the license check failure:
Mind adding a license in your repo? |
Definitely agreed. I am happy to steer clear of there.
Oh is that it? It just reports these empty checksums for the files. I don't care, as long as that is correct.
Last I ran, it did not. I will run it again.
Will do.
Sure. I thought I did, but I guess I just rushed it through. |
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
…taloger Signed-off-by: <>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Json schema diff for reviewers # ❯ diff schema/json/schema-7.1.2.json schema/json/schema-7.1.3.json
749a750,843
> "LinuxKernelMetadata": {
> "properties": {
> "name": {
> "type": "string"
> },
> "architecture": {
> "type": "string"
> },
> "version": {
> "type": "string"
> },
> "extendedVersion": {
> "type": "string"
> },
> "buildTime": {
> "type": "string"
> },
> "author": {
> "type": "string"
> },
> "format": {
> "type": "string"
> },
> "rwRootFS": {
> "type": "boolean"
> },
> "swapDevice": {
> "type": "integer"
> },
> "rootDevice": {
> "type": "integer"
> },
> "videoMode": {
> "type": "string"
> }
> },
> "type": "object",
> "required": [
> "name",
> "architecture",
> "version"
> ]
> },
> "LinuxKernelModuleMetadata": {
> "properties": {
> "name": {
> "type": "string"
> },
> "version": {
> "type": "string"
> },
> "sourceVersion": {
> "type": "string"
> },
> "path": {
> "type": "string"
> },
> "description": {
> "type": "string"
> },
> "author": {
> "type": "string"
> },
> "license": {
> "type": "string"
> },
> "kernelVersion": {
> "type": "string"
> },
> "versionMagic": {
> "type": "string"
> },
> "parameters": {
> "patternProperties": {
> ".*": {
> "$ref": "#/$defs/LinuxKernelModuleParameter"
> }
> },
> "type": "object"
> }
> },
> "type": "object"
> },
> "LinuxKernelModuleParameter": {
> "properties": {
> "type": {
> "type": "string"
> },
> "description": {
> "type": "string"
> }
> },
> "type": "object"
> },
1027a1122,1127
> },
> {
> "$ref": "#/$defs/LinuxKernelMetadata"
> },
> {
> "$ref": "#/$defs/LinuxKernelModuleMetadata"
|
🥳 |
Thanks for helping walk me through this @wagoodman @kzantow ! |
* main: (35 commits) Fix kernel cataloger test fixtures (#1742) feat: Support scanning license files in golang packages over the network (#1630) Add package-to-file location evidence relationships (#1698) Add Linux Kernel cataloger (#1694) Add annotations for evidence on package locations (#1723) add format make target (#1733) Update tests to not fail on Mac M1's. (#1730) chore(deps): update bootstrap tools to latest versions (#1728) Add support for nar files. (#1727) add highlevel details about catalogers (#1726) chore(deps): bump golang.org/x/net from 0.8.0 to 0.9.0 (#1722) chore(deps): update stereoscope to e95d60a265e384df29b7a139f5c5402d6ad72e06 (#1721) feat: gradle lockfile support (#1719) chore(deps): bump github.com/docker/docker (#1715) chore(deps): bump golang.org/x/mod from 0.9.0 to 0.10.0 (#1713) chore(deps): bump golang.org/x/term from 0.6.0 to 0.7.0 (#1714) chore(deps): bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#1716) chore(deps): bump peter-evans/create-pull-request from 4 to 5 (#1712) chore: update tools-golang to v0.5.0 (#1717) Add Nix cataloger (#1696) ... Signed-off-by: Christopher Phillips <[email protected]>
* add kernel handler Signed-off-by: Avi Deitcher <[email protected]> * [wip] combine kernel and kernel module cataloging Signed-off-by: Alex Goodman <[email protected]> * [wip] combine kernel and kernel module cataloging Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: Avi Deitcher <[email protected]> * rename Kernel package to LinuxKernel package Signed-off-by: Alex Goodman <[email protected]> * split kernel and module packages within cataloger Signed-off-by: Alex Goodman <[email protected]> * wire up application configuration with kernel cataloger options Signed-off-by: Alex Goodman <[email protected]> * dont use references for packages on relationships Signed-off-by: Alex Goodman <[email protected]> * fix linting and tests Signed-off-by: Alex Goodman <[email protected]> * kernel cataloger should be resistent to partial failure Signed-off-by: Alex Goodman <[email protected]> * log upon kernel module metadata missing Signed-off-by: Alex Goodman <[email protected]> * add tests for linux kernel cataloger Signed-off-by: Alex Goodman <[email protected]> * update integration tests Signed-off-by: Alex Goodman <[email protected]> * update cli package test counts Signed-off-by: Alex Goodman <[email protected]> * add evidence annotations for kernel packages Signed-off-by: Alex Goodman <[email protected]> * reduce noise in cli test output Signed-off-by: Alex Goodman <[email protected]> * missed cli test to reduce noise for Signed-off-by: Alex Goodman <[email protected]> * fix package counts Signed-off-by: Alex Goodman <[email protected]> * update docs with linux kernel cataloging refs Signed-off-by: Alex Goodman <[email protected]> * bump json schema with new metadata fields Signed-off-by: Alex Goodman <[email protected]> --------- Signed-off-by: Avi Deitcher <[email protected]> Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: <> Co-authored-by: Alex Goodman <[email protected]>
This adds a cataloger for kernel files. It looks for files in a particular set of filenames, then uses libmagic (well, a library in go that reproduces part of it, with more to come) to parse metadata.
Includes options to append additional file globs to parse.
TODO:
Closes #1378