Skip to content

Conversation

@henrysachs
Copy link
Contributor

@henrysachs henrysachs commented Aug 17, 2025

Add support for arbitrary key-value pairs in SBOMs through new --sbom-property CLI flags. This enables users to add custom metadata to SBOMs for better organization and compliance tracking.

Closes: #3734

Description

This will allow users to define so called "tags" to their sbom. I already implemented SPDX and CycloneDX JSON Support. But as @kzantow also has stated I'm unsure about adding these values to the comment section of SPDX v2. As I'm not that deep into the standards I don't know when we can assume v3 to be released and would take the comment key as the best we can currently do. On the other hand i read that you can add "custom" values to the JSON as long as you prefix them. So we could add custom syft prefixed keys to the SPDX Document.

Also to be open about it: I'm not that good in Software Testing so I used AI to help me write those Tests.

example command:

syft scan alpine:latest --sbom-property team=dev --sbom-property environment=test -o syft-json

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (please discuss with the team first; Syft is 1.0 software and we won't accept breaking changes without going to 2.0)
  • Documentation (updates the documentation)
  • Chore (improve the developer experience, fix a test flake, etc, without changing the visible behavior of Syft)
  • Performance (make Syft run faster or use less memory, without changing visible behavior much)

Checklist:

  • I have added unit tests that cover changed behavior
  • I have tested my code in common scenarios and confirmed there are no regressions
  • I have added comments to my code, particularly in hard-to-understand sections

Add support for arbitrary key-value pairs in SBOMs through new --sbom-property CLI flags.
This enables users to add custom metadata to SBOMs for better organization and compliance tracking.

Closes: anchore#3734
Signed-off-by: Henry Sachs <[email protected]>
@github-actions github-actions bot added the json-schema Changes the json schema label Aug 17, 2025
Signed-off-by: Henry Sachs <[email protected]>
@henrysachs
Copy link
Contributor Author

@spiffcs @kzantow maybe you could talk about that PR in the livestream today?

@github-actions

This comment has been minimized.

@henrysachs
Copy link
Contributor Author

I rebased the branch to match the latest syft changes and regenerated the schema

Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @henrysachs overall this looks great. My main feedback is about being consistent with naming; properties makes more sense to me than tags

Enrich []string `yaml:"enrich" json:"enrich" mapstructure:"enrich"`

// custom SBOM properties
SBOMProperties []string `yaml:"sbom-properties" json:"sbom-properties" mapstructure:"sbom-properties"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should is be a map[string]string? I think this is properly supported with all the configuration tooling, but we'd need a different field for the CLI flags of the type []string, probably

for k := range tags {
keys = append(keys, k)
}
slices.Sort(keys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just use slices.Sorted(maps.Keys(theMap))

var parts []string
parts = append(parts, "SBOM Properties:")
for _, key := range keys {
parts = append(parts, fmt.Sprintf(" %s: %s", key, tags[key]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for whitespace here? I think newlines shouldn't cause a problem, but maybe it's safer to use a different separator? Have you tried this in Tag-Value format? maybe we just output this like <key>=<value>;<key>=<value>, I think the = at least, is more consistent with the configuration here?

Distro LinuxRelease `json:"distro"` // Distro represents the Linux distribution that was detected from the source
Descriptor Descriptor `json:"descriptor"` // Descriptor is a block containing self-describing information about syft
Schema Schema `json:"schema"` // Schema is a block reserved for defining the version for the shape of this JSON document and where to find the schema document to validate the shape
Tags map[string]string `json:"tags"` // Tags contains custom properties added to the SBOM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags seems like it might be misleading, confused with image tags maybe? Is there another term we could use here to be more clear what this is used for? CDX Properties seems a bit better, to me, maybe we adopt Properties?

if tags == nil {
return make(map[string]string)
}
// Create a copy to avoid modifying the original map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be modified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

json-schema Changes the json schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add arbitrary name-value pairs to SBOM

2 participants