Skip to content

asn, fake expert: default paths, asn: add checks #2606

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

sebix
Copy link
Member

@sebix sebix commented Apr 23, 2025

asn, fake expert: use state path for database default
asn: Check for database file existence and writability fixes #2566

@sebix sebix added the bug Indicates an unexpected problem or unintended behavior label Apr 23, 2025
@sebix sebix added this to the 3.4.1 Patch release milestone Apr 23, 2025
@sebix sebix force-pushed the sane-default-path branch 2 times, most recently from bf38b18 to 905a62e Compare April 28, 2025 08:28
@sebix
Copy link
Member Author

sebix commented Apr 28, 2025

rebased to fix the tests

@@ -40,6 +41,8 @@ def init(self):
self.logger.error("Read 'bots/experts/asn_lookup/README' and "
"follow the procedure.")
self.stop()
if not Path(self.database).is_file:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An idea - maybe add also a check in the check method that would verify if the file is not a file or is not writable (also check from L121)? Not existing file should not cause a failure in check (it could be like this for a new bot), but could be an info

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line is actually wrong. is_file is a method, not a member, therefore is_file always evaluates to true.

An idea - maybe add also a check in the check method that would verify if the file is not a file or is not writable (also check from L121)?

I updated the existence check and added a type check

Not existing file should not cause a failure in check (it could be like this for a new bot), but could be an info

I can follow you, but on the other hand, if the database file does not exist at the time of checking, the bot can also not operate with this current state and needs intervention by the admin to get into a working state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good that you caught it!

I can follow you, but on the other hand, if the database file does not exist at the time of checking, the bot can also not operate with this current state and needs intervention by the admin to get into a working state.

This is also true, so a failure may be expected. I'd anyway keep it more as warning as an error as it could be handled automatically, and is a desired state on the first run - until manual or automated action take place - and the bot configuration itself might be correct.

@sebix sebix requested a review from kamil-certat May 21, 2025 19:25
@sebix sebix force-pushed the sane-default-path branch from d50588a to 3092f9e Compare May 21, 2025 19:48
try:
pyasn.pyasn(parameters['database'])
except Exception as exc:
return [["error", "Error reading database: %r." % exc]]
return [["error", f"Error reading database ({database_path!s}): %r." % exc]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mixing f-string and %? Let's pack exc inside the f-string

return [["error", "File given as parameter 'database' does not exist."]]
database_path = Path(parameters.get('database', ''))
if not database_path.exists():
return [["error", f"File given as parameter 'database' ({database_path!s}) does not exist."]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Light suggestion: make it as warning
Strong suggestion: "...not exists. You may need to trigger first downloading manually. See: https://docs.intelmq.org/latest/user/bots/#asn-lookup"

Otherwise we create an error message for eventually expected state, and people will think the bot is buggy

@@ -66,12 +67,15 @@ def process(self):

@staticmethod
def check(parameters):
if not os.path.exists(parameters.get('database', '')):
return [["error", "File given as parameter 'database' does not exist."]]
database_path = Path(parameters.get('database', ''))
Copy link
Contributor

@kamil-certat kamil-certat May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think about adding a one more check - how old the file is? And issue a warning if it's older than a week (I think it should be updated more often, right?)? Something like "The ASN database is older than 7 days and may be not up-to-date any more. Is automated database update working?"

Copy link
Contributor

@kamil-certat kamil-certat May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall we had once a problem with broken ASN update cronjob, and it resulted in wrong assigning and wrong addressing some events - so a check for that might help someone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASN Lookup expert: Missing sane default value for database path
2 participants