-
Notifications
You must be signed in to change notification settings - Fork 126
tree: add labels.json and security OCI labels for Clair scanning
#1919
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| IMAGE_FROM=registry.ci.openshift.org/coreos/rhel-coreos-base:10.2 | ||
| IMAGE_NAME=openshift/ose-rhel-coreos-10 | ||
| IMAGE_CPE=cpe:/a:redhat:openshift:4.22::el10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| IMAGE_FROM=registry.ci.openshift.org/coreos/rhel-coreos-base:9.8 | ||
| IMAGE_NAME=openshift/ose-rhel-coreos-9 | ||
| IMAGE_CPE=cpe:/a:redhat:openshift:4.22::el9 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| IMAGE_FROM=registry.ci.openshift.org/coreos/stream-coreos-base:10 | ||
| # SCOS/OKD: no labels.json or OCI labels for name/cpe |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/python3 -u | ||
|
|
||
| """ | ||
| This script generates /usr/share/buildinfo/labels.json, which provides embedded | ||
| metadata for security scanners that only have filesystem access (not OCI image | ||
| metadata). | ||
| """ | ||
|
|
||
| import datetime | ||
| import json | ||
| import os | ||
| import sys | ||
|
|
||
| LABELS_FILE = "/usr/share/buildinfo/labels.json" | ||
|
|
||
|
|
||
| def main(): | ||
| image_name = os.environ.get('IMAGE_NAME', '') | ||
| image_cpe = os.environ.get('IMAGE_CPE', '') | ||
| target_arch = os.environ.get('TARGETARCH', '') | ||
|
|
||
| if not all([image_name, image_cpe, target_arch]): | ||
| return | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean it will just silently fail? would we want it to silently fail?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess what we could do here is sanity-check whether we're in CentOS Stream or RHEL and only in the latter loudly fail. |
||
|
|
||
| # Ideally the creation date we set here is consistent with the creation date | ||
| # of the OCI image itself. We'll get that once we're hermetic and we hook | ||
| # up SOURCE_DATE_EPOCH. So prepare for that eventuality, but for now just | ||
| # use the current time (which will be a few seconds different from the OCI | ||
| # timestamp, which is still fine for our purposes). | ||
| source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH', '') | ||
| if source_date_epoch: | ||
| created = datetime.datetime.fromtimestamp( | ||
| int(source_date_epoch), tz=datetime.timezone.utc | ||
| ).strftime('%Y-%m-%dT%H:%M:%SZ') | ||
| else: | ||
| created = datetime.datetime.now( | ||
| tz=datetime.timezone.utc | ||
| ).strftime('%Y-%m-%dT%H:%M:%SZ') | ||
|
|
||
| # this schema is documented at: | ||
| # https://github.com/RedHatProductSecurity/security-data-guidelines/blob/main/schema/embedded_metadata.v1.schema.json | ||
| labels = { | ||
| 'architecture': target_arch, | ||
| 'cpe': image_cpe, | ||
| 'name': image_name, | ||
| 'org.opencontainers.image.created': created, | ||
| } | ||
|
|
||
| os.makedirs(os.path.dirname(LABELS_FILE), exist_ok=True) | ||
| with open(LABELS_FILE, encoding='utf-8', mode='w') as f: | ||
| json.dump(labels, f, sort_keys=True, indent=2) | ||
| f.write('\n') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main()) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make it explicit?