Skip to content

Commit

Permalink
feat(csaf): add csaf_ tables needed to store csaf data
Browse files Browse the repository at this point in the history
RHINENG-6814
  • Loading branch information
psegedy authored and jdobes committed Jan 22, 2024
1 parent 2e9b3a3 commit 96dbd27
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
60 changes: 60 additions & 0 deletions database/upgrade_scripts/018-csaf_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- -----------------------------------------------------
-- Table vmaas.csaf_product_status
-- https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#3239-vulnerabilities-property---product-status
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS csaf_product_status (
id INT NOT NULL,
name TEXT UNIQUE NOT NULL, CHECK (NOT empty(name)),
PRIMARY KEY (id)
)TABLESPACE pg_default;

INSERT INTO csaf_product_status (id, name)
VALUES (1, 'first_affected'),
(2, 'first_fixed'),
(3, 'fixed'),
(4, 'known_affected'),
(5, 'known_not_affected'),
(6, 'last_affected'),
(7, 'recommended'),
(8, 'under_investigation')
ON CONFLICT DO NOTHING;


-- -----------------------------------------------------
-- Table vmaas.csaf_products
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS csaf_products (
id SERIAL,
cpe TEXT NOT NULL, CHECK (NOT empty(cpe)),
package TEXT NULL, CHECK (NOT empty(package)),
module TEXT NULL, CHECK (NOT empty(module)),
PRIMARY KEY (id)
)TABLESPACE pg_default;


-- -----------------------------------------------------
-- Table vmaas.csaf_cves
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS csaf_cves (
id SERIAL,
cve TEXT NOT NULL, CHECK (NOT empty(cve)),
csaf_product_id INT NOT NULL,
product_status_id INT NOT NULL,
PRIMARY KEY (id),
CONSTRAINT csaf_product_id
FOREIGN KEY (csaf_product_id)
REFERENCES csaf_products (id),
CONSTRAINT csaf_product_status_id
FOREIGN KEY (product_status_id)
REFERENCES csaf_product_status (id)
)TABLESPACE pg_default;


-- -----------------------------------------------------
-- vmaas users permission setup:
-- vmaas_writer - has rights to INSERT/UPDATE/DELETE; used by reposcan
-- vmaas_reader - has SELECT only; used by webapp
-- -----------------------------------------------------
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO vmaas_writer;
GRANT USAGE, SELECT, UPDATE ON ALL SEQUENCES IN SCHEMA public TO vmaas_writer;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO vmaas_reader;
54 changes: 53 additions & 1 deletion database/vmaas_db_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS db_version (
)TABLESPACE pg_default;

-- Increment this when editing this file
INSERT INTO db_version (name, version) VALUES ('schema_version', 17);
INSERT INTO db_version (name, version) VALUES ('schema_version', 18);

-- -----------------------------------------------------
-- evr type
Expand Down Expand Up @@ -1284,6 +1284,58 @@ CREATE TABLE IF NOT EXISTS csaf_file (
)TABLESPACE pg_default;


-- -----------------------------------------------------
-- Table vmaas.csaf_product_status
-- https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#3239-vulnerabilities-property---product-status
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS csaf_product_status (
id INT NOT NULL,
name TEXT UNIQUE NOT NULL, CHECK (NOT empty(name)),
PRIMARY KEY (id)
)TABLESPACE pg_default;

INSERT INTO csaf_product_status (id, name)
VALUES (1, 'first_affected'),
(2, 'first_fixed'),
(3, 'fixed'),
(4, 'known_affected'),
(5, 'known_not_affected'),
(6, 'last_affected'),
(7, 'recommended'),
(8, 'under_investigation')
ON CONFLICT DO NOTHING;


-- -----------------------------------------------------
-- Table vmaas.csaf_products
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS csaf_products (
id SERIAL,
cpe TEXT NOT NULL, CHECK (NOT empty(cpe)),
package TEXT NULL, CHECK (NOT empty(package)),
module TEXT NULL, CHECK (NOT empty(module)),
PRIMARY KEY (id)
)TABLESPACE pg_default;


-- -----------------------------------------------------
-- Table vmaas.csaf_cves
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS csaf_cves (
id SERIAL,
cve TEXT NOT NULL, CHECK (NOT empty(cve)),
csaf_product_id INT NOT NULL,
product_status_id INT NOT NULL,
PRIMARY KEY (id),
CONSTRAINT csaf_product_id
FOREIGN KEY (csaf_product_id)
REFERENCES csaf_products (id),
CONSTRAINT csaf_product_status_id
FOREIGN KEY (product_status_id)
REFERENCES csaf_product_status (id)
)TABLESPACE pg_default;


-- -----------------------------------------------------
-- vmaas users permission setup:
-- vmaas_writer - has rights to INSERT/UPDATE/DELETE; used by reposcan
Expand Down

0 comments on commit 96dbd27

Please sign in to comment.