Skip to content

Commit d38dae8

Browse files
breadchrisfreeqazgithub-actions[bot]
authored
Fetch epss scores (#1087)
**STOP**: Is this a **security vulnerability**? If so, follow Responsible Disclosure and email us at [email protected] instead of opening a public PR. Co-authored-by: Free Wortley <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 89feac9 commit d38dae8

File tree

13 files changed

+434
-32
lines changed

13 files changed

+434
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ node_modules
1212
docker-compose.*.yaml
1313
.env.docker
1414
outputs/
15+
out/
1516
.log*
1617

1718
.yarn/*

lunatrace/bsl/hasura/metadata/databases/lunatrace/tables/tables.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- "!include vulnerability_affected.yaml"
4646
- "!include vulnerability_affected_range_event.yaml"
4747
- "!include vulnerability_affected_version.yaml"
48+
- "!include vulnerability_cisa_known_exploited.yaml"
4849
- "!include vulnerability_credit.yaml"
4950
- "!include vulnerability_cwe.yaml"
5051
- "!include vulnerability_equivalent.yaml"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
table:
2+
name: cisa_known_exploited
3+
schema: vulnerability
4+
computed_fields:
5+
- name: vulnerability
6+
definition:
7+
function:
8+
name: cisa_known_exploited_vulnerability
9+
schema: vulnerability
10+
table_argument: known_exploited
11+
comment: Vulnerability referenced by the known exploited vulnerability.

lunatrace/bsl/hasura/metadata/databases/lunatrace/tables/vulnerability_vulnerability.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ array_relationships:
7070
table:
7171
name: severity
7272
schema: vulnerability
73+
computed_fields:
74+
- name: cisa_known_exploited
75+
definition:
76+
function:
77+
name: vulnerability_cisa_known_exploited
78+
schema: vulnerability
79+
table_argument: vulnerability
7380
insert_permissions:
7481
- role: service
7582
permission:

lunatrace/bsl/hasura/metadata/remote_schemas.yaml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,60 @@
1616
scalar JSON
1717
scalar UUID
1818
type AuthenticatedRepoCloneUrlOutput {
19-
url: String
19+
url: String
2020
}
2121
type Mutation {
22-
presignManifestUpload(project_id: UUID!): PresignedUrlResponse
22+
presignManifestUpload(project_id: UUID!): PresignedUrlResponse
2323
}
2424
type PresignedUrlResponse {
25-
bucket: String!
26-
headers: JSON!
27-
key: String!
28-
url: String!
25+
bucket: String!
26+
headers: JSON!
27+
key: String!
28+
url: String!
2929
}
3030
type Query {
31-
authenticatedRepoCloneUrl(repoGithubId: Int!): AuthenticatedRepoCloneUrlOutput
32-
fakeQueryToHackHasuraBeingABuggyMess: String
33-
sbomUrl(buildId: UUID!): String
31+
authenticatedRepoCloneUrl(repoGithubId: Int!): AuthenticatedRepoCloneUrlOutput
32+
fakeQueryToHackHasuraBeingABuggyMess: String
33+
sbomUrl(buildId: UUID!): String
3434
}
3535
type SbomUploadUrlOutput {
36-
error: Boolean!
37-
uploadUrl: UploadUrl
36+
error: Boolean!
37+
uploadUrl: UploadUrl
3838
}
3939
type UploadUrl {
40-
headers: JSON!
41-
url: String!
40+
headers: JSON!
41+
url: String!
4242
}
4343
- role: service
4444
definition:
4545
schema: |
4646
scalar JSON
4747
scalar UUID
4848
type AuthenticatedRepoCloneUrlOutput {
49-
url: String
49+
url: String
5050
}
5151
type Mutation {
52-
presignManifestUpload(project_id: UUID!): PresignedUrlResponse
52+
presignManifestUpload(project_id: UUID!): PresignedUrlResponse
5353
}
5454
type PresignedUrlResponse {
55-
bucket: String!
56-
headers: JSON!
57-
key: String!
58-
url: String!
55+
bucket: String!
56+
headers: JSON!
57+
key: String!
58+
url: String!
5959
}
6060
type Query {
61-
authenticatedRepoCloneUrl(repoGithubId: Int!): AuthenticatedRepoCloneUrlOutput
62-
fakeQueryToHackHasuraBeingABuggyMess: String
63-
presignSbomUpload(orgId: UUID!, buildId: UUID!): SbomUploadUrlOutput
64-
sbomUrl(buildId: UUID!): String
61+
authenticatedRepoCloneUrl(repoGithubId: Int!): AuthenticatedRepoCloneUrlOutput
62+
fakeQueryToHackHasuraBeingABuggyMess: String
63+
presignSbomUpload(orgId: UUID!, buildId: UUID!): SbomUploadUrlOutput
64+
sbomUrl(buildId: UUID!): String
6565
}
6666
type SbomUploadUrlOutput {
67-
error: Boolean!
68-
uploadUrl: UploadUrl
67+
error: Boolean!
68+
uploadUrl: UploadUrl
6969
}
7070
type UploadUrl {
71-
headers: JSON!
72-
url: String!
71+
headers: JSON!
72+
url: String!
7373
}
7474
input SbomUploadUrlInput {
7575
orgId: UUID!
@@ -81,13 +81,13 @@
8181
scalar JSON
8282
scalar UUID
8383
type Query {
84-
presignSbomUpload(orgId: UUID!, buildId: UUID!): SbomUploadUrlOutput
84+
presignSbomUpload(orgId: UUID!, buildId: UUID!): SbomUploadUrlOutput
8585
}
8686
type SbomUploadUrlOutput {
87-
error: Boolean!
88-
uploadUrl: UploadUrl
87+
error: Boolean!
88+
uploadUrl: UploadUrl
8989
}
9090
type UploadUrl {
91-
headers: JSON!
92-
url: String!
91+
headers: JSON!
92+
url: String!
9393
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
DROP TABLE IF EXISTS vulnerability.cisa_known_exploited CASCADE;
3+
DROP INDEX IF EXISTS vulnerability_equivalent_b_idx;
4+
DROP FUNCTION vulnerability.cisa_known_exploited_vulnerability;
5+
DROP FUNCTION vulnerability.vulnerability_cisa_known_exploited;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- Indexes to speed up EPSS inserter
2+
CREATE INDEX IF NOT EXISTS vulnerability_equivalent_b_idx ON vulnerability.equivalent (b);
3+
4+
CREATE INDEX IF NOT EXISTS vulnerability_vulnerability_source_id_idx ON vulnerability.vulnerability (source_id);
5+
6+
-- Table to hold the CISA Known Exploited vulnerabilities
7+
CREATE TABLE IF NOT EXISTS vulnerability.cisa_known_exploited (
8+
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
9+
cve TEXT UNIQUE,
10+
vendor_project text NOT NULL,
11+
product text NOT NULL,
12+
vulnerability_name text NOT NULL,
13+
date_added date NOT NULL,
14+
short_description text NOT NULL,
15+
required_action text NOT NULL,
16+
due_date date NOT NULL,
17+
notes text NOT NULL,
18+
PRIMARY KEY ("id"),
19+
CHECK (cve LIKE 'CVE-%')
20+
);
21+
22+
CREATE OR REPLACE FUNCTION vulnerability.cisa_known_exploited_vulnerability(known_exploited vulnerability.cisa_known_exploited)
23+
RETURNS SETOF vulnerability.vulnerability AS $$
24+
SELECT *
25+
FROM vulnerability.vulnerability
26+
WHERE source_id = known_exploited.cve
27+
$$ LANGUAGE sql STABLE;
28+
29+
CREATE OR REPLACE FUNCTION vulnerability.vulnerability_cisa_known_exploited(vulnerability vulnerability.vulnerability)
30+
RETURNS SETOF vulnerability.cisa_known_exploited
31+
LANGUAGE sql
32+
STABLE
33+
AS $function$
34+
SELECT *
35+
FROM vulnerability.cisa_known_exploited
36+
WHERE cve = vulnerability.source_id
37+
$function$
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin/
22
.lunatrace.yaml
3+
build/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright by LunaSec (owned by Refinery Labs, Inc)
2+
//
3+
// Licensed under the Business Source License v1.1
4+
// (the "License"); you may not use this file except in compliance with the
5+
// License. You may obtain a copy of the License at
6+
//
7+
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
8+
//
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
package cisa
12+
13+
import (
14+
"github.com/ajvpot/clifx"
15+
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/cisa"
16+
"github.com/rs/zerolog/log"
17+
"github.com/urfave/cli/v2"
18+
"go.uber.org/fx"
19+
)
20+
21+
type Params struct {
22+
fx.In
23+
24+
Ingester cisa.CISAKnownVulnIngester
25+
}
26+
27+
func NewCommand(p Params) clifx.CommandResult {
28+
return clifx.CommandResult{
29+
Command: &cli.Command{
30+
Name: "cisa",
31+
Subcommands: []*cli.Command{
32+
{
33+
Name: "ingest",
34+
Usage: "[file or directory]",
35+
Flags: []cli.Flag{},
36+
Subcommands: []*cli.Command{},
37+
Action: func(ctx *cli.Context) error {
38+
log.Info().
39+
Msg("Updating CISA Known Vulnerabilities")
40+
err := p.Ingester.Ingest(ctx.Context)
41+
if err == nil {
42+
log.Info().
43+
Msg("Updated CISA Known Vulnerabilities")
44+
}
45+
return err
46+
},
47+
},
48+
},
49+
},
50+
}
51+
}

lunatrace/bsl/ingest-worker/cmd/ingestworker/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
package main
1212

1313
import (
14+
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/cisa"
1415
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/cwe"
1516
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/epss"
1617
packageCommand "github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/package"
1718
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/cmd/ingestworker/vulnerability"
19+
cisa2 "github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/cisa"
1820
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/config/ingestworker"
1921
cwe2 "github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/cwe"
2022
"github.com/lunasec-io/lunasec/lunatrace/bsl/ingest-worker/pkg/dbfx"
@@ -52,6 +54,7 @@ func main() {
5254
fx.Provide(
5355
cwe2.NewCWEIngester,
5456
epss2.NewEPSSIngester,
57+
cisa2.NewCISAKnownVulnIngester,
5558
),
5659

5760
// todo make a module
@@ -78,6 +81,7 @@ func main() {
7881
vulnerability.NewCommand,
7982
cwe.NewCommand,
8083
epss.NewCommand,
84+
cisa.NewCommand,
8185
),
8286
fx.Provide(
8387
packageCommand.NewCommand,

0 commit comments

Comments
 (0)