Skip to content
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 ruletype OSPS-LE- 04 #296

Merged
merged 9 commits into from
Jan 31, 2025
Merged

Add ruletype OSPS-LE- 04 #296

merged 9 commits into from
Jan 31, 2025

Conversation

teodor-yanev
Copy link
Contributor

Closes https://github.com/stacklok/minder-stories/issues/199

This PR should be merged only after the external license processor is up and running. The URL in the POST used here should then be updated.
For visibility, this is the lib that will do the processing: https://github.com/CycloneDX/license-scanner

@teodor-yanev teodor-yanev self-assigned this Jan 28, 2025
Comment on lines 52 to 55
violations[{"msg": msg}] {
not license_file
msg := "No license file found in release assets"
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine for there to be no explicit license in the assets; in that case, we'd expect the source code license to apply. (This is the common case.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, in that case, I've added a line to exit gracefully if no such is found.

Comment on lines 47 to 50
license_file := asset {
some asset in input.ingested
is_license_file(asset.name)
}
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't need to worry about the not license_file case, it seems like we could simplify to put this into the violations[{"msg":msg}] block.

"Accept": "application/json",
"Content-Type": "application/octet-stream"
},
"raw_body": license_resp
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this need to be the .body or some other attribute of the http response?

Copy link
Contributor Author

@teodor-yanev teodor-yanev Jan 29, 2025

Choose a reason for hiding this comment

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

For when we have "HTTP message body to include in request. The value WILL NOT be serialized. Use this for non-JSON messages.", "raw_body": https://www.openpolicyagent.org/docs/latest/policy-reference/#http

Copy link
Member

Choose a reason for hiding this comment

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

I meant that license_resp is an object, not a string. I think you want:

Suggested change
"raw_body": license_resp
"raw_body": license_resp.raw_body

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Done, thanks.

security-baseline/rule-types/github/osps-le-04.yaml Outdated Show resolved Hide resolved
@teodor-yanev teodor-yanev marked this pull request as ready for review January 29, 2025 13:24
@teodor-yanev teodor-yanev requested a review from a team as a code owner January 29, 2025 13:24
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

I'm assuming you've tested this in staging?

Comment on lines 66 to 67
# We have this servcice processing on the other side:
# https://github.com/CycloneDX/license-scanner
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# We have this servcice processing on the other side:
# https://github.com/CycloneDX/license-scanner
# We have a service for this detection:
# https://github.com/evankanderson/spdx-detector

evankanderson
evankanderson previously approved these changes Jan 30, 2025
Comment on lines 55 to 56
# Exit without violation if no license file found
license_file != {}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need this; since license_file is some entry in input.ingested which has a name property which passes is_license_file, you know it's not an empty object (it must contain a name property).

Comment on lines 44 to 53
license_pattern := "^license(\\..*)?$"
is_license_file(name) if {
regex.match(license_pattern, lower(name))
}

violations[{"msg": msg}] {
license_file := asset {
some asset in input.ingested
is_license_file(asset.name)
}
Copy link
Member

Choose a reason for hiding this comment

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

This seems simpler as:

Suggested change
license_pattern := "^license(\\..*)?$"
is_license_file(name) if {
regex.match(license_pattern, lower(name))
}
violations[{"msg": msg}] {
license_file := asset {
some asset in input.ingested
is_license_file(asset.name)
}
violations[{"msg": msg}] {
license_file := asset {
some asset in input.ingested
startswith(lower(name), "license")
}

@teodor-yanev
Copy link
Contributor Author

Testing:

./bin/minder profile status list -n my-test-profile --detailed
WARNING: Running against a test environment (staging.stacklok.dev) and may not be stable
+--------------------------------------+-----------------+---------+----------------------+
|                  ID                  |      NAME       | STATUS  |     LAST UPDATED     |
+--------------------------------------+-----------------+---------+----------------------+
| ecdf0b42-74be-46b8-b238-d56b3f12312d | my-test-profile | Failure | 2025-01-31T22:10:20Z |
+--------------------------------------+-----------------+---------+----------------------+
+--------------+----------------------------------+---------+-------------+--------------------------------------+
|  RULE NAME   |              ENTITY              | STATUS  | REMEDIATION |             ENTITY INFO              |
+--------------+----------------------------------+---------+-------------+--------------------------------------+
| osps-le-04   | teodor-yanev/demo-repo-go/v1.0.0 | Success | Skipped     | entity_id:                           |
| [osps-le-04] | [release]                        |         |             | 10110bd7-b0a7-452f-aca6-862837a8eab1 |
|              |                                  |         |             | entity_type: release name:           |
|              |                                  |         |             | teodor-yanev/demo-repo-go/v1.0.0     |
|              |                                  |         |             | provider: github                     |
+              +----------------------------------+---------+-------------+--------------------------------------+
|              | teodor-yanev/demo-repo-go/v1.0.1 | Failure | Skipped     | entity_id:                           |
|              | [release]                        |         |             | d452f035-07e7-4849-b08e-11d0d06f6324 |
|              |                                  |         |             | entity_type: release name:           |
|              |                                  |         |             | teodor-yanev/demo-repo-go/v1.0.1     |
|              |                                  |         |             | provider: github                     |
+              +----------------------------------+---------+-------------+--------------------------------------+
|              | teodor-yanev/demo-repo-go/v1.0.2 | Failure | Skipped     | entity_id:                           |
|              | [release]                        |         |             | 6c26e2b7-6354-44fb-b08f-b9853f16d5dc |
|              |                                  |         |             | entity_type: release name:           |
|              |                                  |         |             | teodor-yanev/demo-repo-go/v1.0.2     |
|              |                                  |         |             | provider: github                     |
+              +----------------------------------+---------+-------------+--------------------------------------+
|              | teodor-yanev/demo-repo-go/v1.0.3 | Failure | Skipped     | entity_id:                           |
|              | [release]                        |         |             | 3d874a79-0be4-41d1-8d79-fe9695ebb066 |
|              |                                  |         |             | entity_type: release name:           |
|              |                                  |         |             | teodor-yanev/demo-repo-go/v1.0.3     |
|              |                                  |         |             | provider: github                     |
+              +----------------------------------+---------+-------------+--------------------------------------+
|              | teodor-yanev/demo-repo-go/v1.0.4 | Success | Skipped     | entity_id:                           |
|              | [release]                        |         |             | 15e9cdc6-5982-4afb-b238-c83d8e608730 |
|              |                                  |         |             | entity_type: release name:           |
|              |                                  |         |             | teodor-yanev/demo-repo-go/v1.0.4     |
|              |                                  |         |             | provider: github                     |
+--------------+----------------------------------+---------+-------------+--------------------------------------+

"Accept": "application/octet-stream"
},
"enable_redirect": true,
"raise_error": true
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but it's also the default for http.send.

@teodor-yanev teodor-yanev merged commit 614ec51 into main Jan 31, 2025
6 checks passed
@teodor-yanev teodor-yanev deleted the add-ruletype-osps-le-04 branch January 31, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants