-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: add indexes to assets and relations tables #21
Conversation
- Index on `$.content.Name` for FQDN assets - index on assets.type - index on assets.last_seen - index on relations.last_seen Closes owasp-amass#19
includes important details related to postgres
|
||
```sql | ||
-- Create a new database to store assets and relations. | ||
CREATE SCHEMA assetdb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likely need to create a schema, update default schema for user if postgres 15 (public
schema is no longer accessible by standard users / roles).
not using the public
schema is also a security best practice for postgres but not everyone follows this
|
||
-- Create a user | ||
CREATE USER your_username WITH PASSWORD 'your_password'; | ||
GRANT ALL ON ALL TABLES IN SCHEMA assetdb to your_username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grants will need to be validated once the schema part is fixed
CREATE INDEX idx_fqdn_content_name ON assets USING gin ((content->>'name') gin_trgm_ops) WHERE type = 'FQDN'; | ||
|
||
-- Index assets.type | ||
CREATE INDEX idx_assets_type_hash ON assets USING hash (type); | ||
|
||
-- Index last_seen | ||
CREATE INDEX idx_as_last_seen ON assets (last_seen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding IF NOT EXISTS
to these
@@ -0,0 +1,7 @@ | |||
-- +migrate Up | |||
|
|||
CREATE INDEX idx_rel_last_seen ON assets (last_seen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding IF NOT EXISTS
here as well
CREATE INDEX fqdn_name ON assets (content->>'name' COLLATE NOCASE) WHERE type = 'FQDN'; | ||
|
||
-- Index assets.type | ||
CREATE INDEX idx_assets_type ON assets (type); | ||
|
||
-- Index last_seen | ||
CREATE INDEX idx_as_last_seen ON assets (last_seen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IF NOT EXISTS
here as well
@@ -0,0 +1,7 @@ | |||
-- +migrate Up | |||
|
|||
CREATE INDEX idx_rel_last_seen ON assets (last_seen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IF NOT EXISTS
here as well
This is in draft as the migration currently requires an admin to the user_guide.md & migrations can only be run by someone with a super user for postgres 15. this needs to be fixed before this is ready |
$.content.Name
for FQDN assetsCloses #19