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

Create mini datalake database #110

Merged
merged 13 commits into from
Mar 21, 2024
14 changes: 14 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Run syncmdl
run: aws lambda invoke --function-name crossfeed-staging-syncmdl --region us-east-1 /dev/stdout

Check failure on line 193 in .github/workflows/backend.yml

View workflow job for this annotation

GitHub Actions / lint

193:89 [line-length] line too long (103 > 88 characters)

Check failure on line 193 in .github/workflows/backend.yml

View workflow job for this annotation

GitHub Actions / lint

193:89 [line-length] line too long (103 > 88 characters)
working-directory: backend
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

deploy_prod:
needs: [build_worker, lint, test, test_python]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -238,3 +245,10 @@
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Run syncmdl
run: aws lambda invoke --function-name crossfeed-prod-syncmdl --region us-east-1 /dev/stdout

Check failure on line 250 in .github/workflows/backend.yml

View workflow job for this annotation

GitHub Actions / lint

250:89 [line-length] line too long (100 > 88 characters)

Check failure on line 250 in .github/workflows/backend.yml

View workflow job for this annotation

GitHub Actions / lint

250:89 [line-length] line too long (100 > 88 characters)
working-directory: backend
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"deploy-worker-prod": "./tools/deploy-worker.sh crossfeed-prod-worker",
"syncdb": "docker-compose exec -T backend npx ts-node src/tools/run-syncdb.ts",
"pesyncdb": "docker-compose exec -T backend npx ts-node src/tools/run-pesyncdb.ts",
"syncmdl": "docker-compose exec -T backend npx ts-node src/tools/run-syncmdl.ts",
"control-queue": "docker-compose exec -T backend npx ts-node src/tools/consumeControlQueue.ts"
},
"author": "",
Expand Down
87 changes: 86 additions & 1 deletion backend/src/models/connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createConnection, Connection } from 'typeorm';
import {
// Models for the Crossfeed database
Domain,
Service,
Vulnerability,
Expand All @@ -13,11 +14,95 @@
SavedSearch,
OrganizationTag,
Cpe,
Cve
Cve,

// Models for the Mini Data Lake database
CertScan,
Cidr,
Contact,
DL_Cpe,
DL_Cve,
DL_Domain,
HostScan,
Host,
Ip,
Kev,
Location,
DL_Organization,
cduhn17 marked this conversation as resolved.
Show resolved Hide resolved
PortScan,
PrecertScan,
Report,
Request,
Sector,
Snapshot,
SslyzeScan,
Tag,
Tally,
TicketEvent,
Ticket,
TrustymailScan,
VulnScan

Check failure on line 45 in backend/src/models/connection.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
} from '.';

let connection: Connection | null = null;

let dl_connection: Connection | null = null;

const connectDl = async (logging?:boolean) => {

Check failure on line 52 in backend/src/models/connection.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
const dl_connection = createConnection({
type: 'postgres',
host: process.env.MDL_HOST,
port: parseInt(process.env.MDL_PORT ?? ''),
username: process.env.MDL_USERNAME,
password: process.env.MDL_PASSWORD,
database: process.env.MDL_NAME,
entities: [
CertScan,
Cidr,
Contact,
DL_Cpe,
DL_Cve,
DL_Domain,
HostScan,
Host,
Ip,
Kev,
Location,
DL_Organization,
PortScan,
PrecertScan,
Report,
Request,
Sector,
Snapshot,
SslyzeScan,
Tag,
Tally,
TicketEvent,
Ticket,
TrustymailScan,
VulnScan
],
synchronize: false,
name: 'mini_data_lake',
dropSchema: false,
logging: logging ?? false,
cache: true
});
return dl_connection

Check failure on line 93 in backend/src/models/connection.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
}

Check failure on line 94 in backend/src/models/connection.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

export const connectToDatalake = async (logging?: boolean) => {
if (!dl_connection?.isConnected) {
dl_connection = await connectDl(logging);
}

Check failure on line 99 in backend/src/models/connection.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎·`
else {
console.log("didn't connect")

Check failure on line 101 in backend/src/models/connection.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
}
return dl_connection;
};

const connectDb = async (logging?: boolean) => {
const connection = createConnection({
type: 'postgres',
Expand Down
26 changes: 26 additions & 0 deletions backend/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,29 @@
export * from './api-key';
export * from './saved-search';
export * from './organization-tag';

cduhn17 marked this conversation as resolved.
Show resolved Hide resolved
export * from './mini_data_lake/cert_scans';
export * from './mini_data_lake/cidrs';
export * from './mini_data_lake/contacts';
export {Cpe as DL_Cpe} from './mini_data_lake/cpes';

Check failure on line 20 in backend/src/models/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `Cpe·as·DL_Cpe` with `·Cpe·as·DL_Cpe·`
export {Cve as DL_Cve} from './mini_data_lake/cves';

Check failure on line 21 in backend/src/models/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `Cve·as·DL_Cve` with `·Cve·as·DL_Cve·`
export {Domain as DL_Domain} from './mini_data_lake/domains';

Check failure on line 22 in backend/src/models/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `Domain·as·DL_Domain` with `·Domain·as·DL_Domain·`
export * from './mini_data_lake/host_scans';
export * from './mini_data_lake/hosts';
export * from './mini_data_lake/ips';
export * from './mini_data_lake/kevs';
export * from './mini_data_lake/locations';
export {Organization as DL_Organization} from './mini_data_lake/organizations';

Check failure on line 28 in backend/src/models/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `Organization·as·DL_Organization` with `·Organization·as·DL_Organization·`
export * from './mini_data_lake/port_scans';
export * from './mini_data_lake/precert_scans';
export * from './mini_data_lake/reports';
export * from './mini_data_lake/requests';
export * from './mini_data_lake/sectors';
export * from './mini_data_lake/snapshots';
export * from './mini_data_lake/sslyze_scan';
export * from './mini_data_lake/tag';
export * from './mini_data_lake/tallies';
export * from './mini_data_lake/ticket_events';
export * from './mini_data_lake/tickets';
export * from './mini_data_lake/trustymail_scans';
export * from './mini_data_lake/vuln_scans';
61 changes: 61 additions & 0 deletions backend/src/models/mini_data_lake/cert_scans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// The data in this table is derived from the Vulnerability Scans Database,
// the [certs Collection] (https://github.com/cisagov/ncats-data-dictionary/blob/develop/NCATS_Data_Dictionary.md#certs-collection).

import {
Entity,
Column,
PrimaryColumn,
BaseEntity,
ManyToMany,
JoinTable
} from 'typeorm';

import {Domain} from "./domains"

@Entity()
export class CertScan extends BaseEntity {
@PrimaryColumn()
id: string

@Column({
nullable: true,
type: 'varchar'
})
issuer: string | null;

@Column({ nullable: true, type: 'timestamp' })
expirationTimestamp: Date | null;

@Column({ nullable: true, type: 'timestamp' })
certStartTimestamp: Date | null;

@Column({
nullable: true,
type: 'varchar'
})
pem: string | null;

@Column()
sctExists: boolean;

@Column({ nullable: true, type: 'timestamp' })
sctOrNotBefore: Date | null;

@Column({
nullable: true,
type: 'varchar'
})
serial: string | null;

@ManyToMany(
(type) => Domain,
(domain) => domain.certScans,
{
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
@JoinTable()
domains: Domain[];

}
68 changes: 68 additions & 0 deletions backend/src/models/mini_data_lake/cidrs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
Entity,
Index,
Column,
PrimaryColumn,
CreateDateColumn,
BaseEntity,
ManyToMany,
JoinTable
} from 'typeorm';

import {Request } from './requests';
import { Organization } from './organizations';
@Entity()
export class Cidr extends BaseEntity {
@PrimaryColumn()
id: string

@CreateDateColumn()
createdDate: Date;

@Index()
@Column({
nullable: true,
type: 'cidr',
unique: true
})
network: string | null;

@Column({
nullable: true,
type: 'inet'
})
startIp: string | null;

@Column({
nullable: true,
type: 'inet'
})
endIp: string | null;

@Column({nullable: true})
retired: boolean;

@ManyToMany(
(type) => Request,
(request) => request.cidrs,
{
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
@JoinTable()
requests: Request[];

@ManyToMany(
(type) => Organization,
(org) => org.cidrs,
{
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
@JoinTable()
organizations: Organization[];


}
58 changes: 58 additions & 0 deletions backend/src/models/mini_data_lake/contacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// The data in this table is derived from the Vulnerability Scans Database,
// the [requests Collection] (https://github.com/cisagov/ncats-data-dictionary/blob/develop/NCATS_Data_Dictionary.md#requests-collection).

import {
Entity,
Column,
PrimaryGeneratedColumn,
BaseEntity,
ManyToMany,
Unique,
JoinTable
} from 'typeorm';
import {Organization} from './organizations'
@Entity()
@Unique(['name','email','type'])
export class Contact extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({
nullable: true,
type: 'varchar'
})
name: string | null;

@Column({
nullable: true,
type: 'varchar'
})
email: string | null;

@Column({
nullable: true,
type: 'varchar'
})
phoneNumber: string | null;

@Column({
nullable: true,
type: 'varchar'
})
type: string | null;

@Column()
retired: boolean;

@ManyToMany(
(type) => Organization,
(org) => org.contacts,
{
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
@JoinTable()
organizations: Organization[];

}
32 changes: 32 additions & 0 deletions backend/src/models/mini_data_lake/cpes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToMany,
BaseEntity,
Unique
} from 'typeorm';
import { Cve } from './cves';

@Entity()
@Unique(['name', 'version', 'vendor'])
export class Cpe extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
name: string;

@Column()
version: string;

@Column()
vendor: string;

@Column()
lastSeenAt: Date;

@ManyToMany(() => Cve, (cve) => cve.cpes)
cves: Cve[];
}

Loading
Loading