Skip to content

Commit

Permalink
Merge pull request #1078 from lunasec-io/environmental-cvss-backend
Browse files Browse the repository at this point in the history
Environmental cvss backend
  • Loading branch information
factoidforrest authored Jan 25, 2023
2 parents eb417c5 + 7ac5f12 commit b1682e0
Show file tree
Hide file tree
Showing 49 changed files with 1,249 additions and 18,386 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/lunatrace-deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: LunaTrace Deploy Production

on:
workflow_dispatch:
inputs:
migrate:
type: choice
description: Run migrations as part of the job? (keep an eye on it if you do)
options:
- no
- yes
default: no

concurrency: production

Expand Down Expand Up @@ -31,6 +39,10 @@ jobs:
env:
IS_LUNASEC_CI: true
run: yarn install --immutable --inline-builds
- name: migrate
if: inputs.migrate == 'yes'
working-directory: lunatrace/bsl/hasura
run: HASURA_GRAPHQL_ENDPOINT=https://lunatrace.lunasec.io/api/hasura HASURA_GRAPHQL_ADMIN_SECRET="$(aws secretsmanager get-secret-value --secret-id lunatrace-HasuraAdminSecret | jq -r .SecretString)" hasura migrate apply
- name: deploy
run: |-
set -euox pipefail
Expand Down
32 changes: 32 additions & 0 deletions .idea/jsonSchemas.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lunatrace/bsl/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"concurrently": "^7.0.0",
"config": "^3.3.6",
"cors": "^2.8.5",
"cvss": "~1.0.5",
"deepmerge": "^4.2.2",
"dotenv": "^10.0.0",
"eventsource": "^2.0.0",
Expand All @@ -82,6 +83,7 @@
"jwks-rsa": "^2.0.5",
"jwt-decode": "^3.1.2",
"markdown-table": "2.0.0",
"minimatch": "~5.1.2",
"murmurhash-native": "^3.5.0",
"node-fetch": "2",
"nodemon": "^2.0.15",
Expand All @@ -99,6 +101,7 @@
"tslog": "^3.3.3",
"uuid": "^8.3.2",
"validator": "^13.7.0",
"vuln-vects": "~1.1.0",
"zod": "~3.20.2"
},
"devDependencies": {
Expand All @@ -113,6 +116,7 @@
"@types/axios": "^0.14.0",
"@types/config": "^0.0.41",
"@types/cors": "^2.8.12",
"@types/cvss": "~1.0.0",
"@types/deepmerge": "^2.2.0",
"@types/eventsource": "^1.1.8",
"@types/express": "^4.17.13",
Expand All @@ -122,6 +126,7 @@
"@types/jsonwebtoken": "~8.5.8",
"@types/jwk-to-pem": "~2.0.1",
"@types/markdown-table": "2.0.0",
"@types/minimatch": "~5.1.2",
"@types/node": "^14.0.0",
"@types/semver": "^7.3.9",
"@types/tar": "~6.1.3",
Expand Down
4 changes: 2 additions & 2 deletions lunatrace/bsl/backend/src/config/load-environment-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ function checkEnvVar<E extends EnvVar<z.Schema>>(varConf: E): z.infer<E['castTo'

type VarName = keyof typeof commonEnvVarKeys;
type EnvVars = {
[name in VarName]: z.infer<typeof commonEnvVarKeys[name]['castTo']>;
[name in VarName]: z.infer<(typeof commonEnvVarKeys)[name]['castTo']>;
};

// Build the env vars and store them in the require cache as an export of this file
const partialEnvironmentVars: Partial<EnvVars> = {};

Object.keys(commonEnvVarKeys).forEach((keyName) => {
const varName = keyName as VarName;
const varConf: EnvVar<typeof commonEnvVarKeys[typeof varName]['castTo']> = commonEnvVarKeys[varName];
const varConf: EnvVar<(typeof commonEnvVarKeys)[typeof varName]['castTo']> = commonEnvVarKeys[varName];
// I can't figure out why this ignore is needed, but so be it
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
26 changes: 23 additions & 3 deletions lunatrace/bsl/backend/src/graphql-yoga/generated-resolver-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { GraphQLYogaError } from '@graphql-yoga/node';
import { SeverityNamesOsv, severityOrderOsv } from '@lunatrace/lunatrace-common';

import { vulnerabilityTreeFromHasura } from '../../models/vulnerability-dependency-tree/vulnerability-tree-from-hasura';
import { loadTree } from '../../models/vulnerability-dependency-tree/load-tree';
import { log } from '../../utils/log';
import { QueryResolvers } from '../generated-resolver-types';
import { checkBuildsAreAuthorized, throwIfUnauthenticated } from '../helpers/auth-helpers';
Expand All @@ -38,9 +38,7 @@ export const vulnerableReleasesFromBuildResolver: BuildVulnerabilitiesResolver =
);
}

const previewChains = args.previewChains !== null ? args.previewChains : false;

const depTree = await vulnerabilityTreeFromHasura(logger, buildId, minimumSeverity);
const depTree = await loadTree(logger, buildId, minimumSeverity);
if (depTree.error) {
logger.error('unable to build dependency tree', {
error: depTree.msg,
Expand All @@ -50,7 +48,7 @@ export const vulnerableReleasesFromBuildResolver: BuildVulnerabilitiesResolver =

logger.info('building vulnerable releases');

const vulnerableReleases = depTree.res.getVulnerableReleases(previewChains);
const vulnerableReleases = depTree.res.getVulnerableReleases();

logger.info('finished processing tree');
return vulnerableReleases;
Expand Down
13 changes: 11 additions & 2 deletions lunatrace/bsl/backend/src/graphql-yoga/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Query {
): AuthenticatedRepoCloneUrlOutput
fakeQueryToHackHasuraBeingABuggyMess: String
availableOrgsWithRepos: [OrgWithRepos!]
vulnerableReleasesFromBuild(buildId: uuid!, minimumSeverity: String, previewChains: Boolean): [BuildData_VulnerableRelease!]
vulnerableReleasesFromBuild(buildId: uuid!, minimumSeverity: String): [BuildData_VulnerableRelease!]
}

type Mutation {
Expand Down Expand Up @@ -95,11 +95,19 @@ type BuildData_VulnerableRelease {
guides: [BuildData_Guide!]!
fix_versions: [String!]!
paths: [String!]!
adjustment: BuildData_Adjustment #optional
}

type BuildData_Adjustment {
adjusted_from_cvss_score: Float
adjusted_from_severity_name: String
path_matched: String!
adjustments_applied: [String!]!
}


type BuildData_IgnoredVulnerability {
note: String!
locations: [String!]!
}

type BuildData_AffectedByVulnerability {
Expand All @@ -111,6 +119,7 @@ type BuildData_AffectedByVulnerability {
trivially_updatable_to: String
fix_versions: [String!]!
path: String!
adjustment: BuildData_Adjustment #optional
}

type BuildData_Location {
Expand Down
Loading

0 comments on commit b1682e0

Please sign in to comment.