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

Icinga DB: don't write negative Downtime durations into Redis #9775

Conversation

Al2Klimov
Copy link
Member

via std::max(0, x) not to crash the Go daemon which can't handle such.

fixes #9774

Test cases (which don't crash anymore now)

  • curl -fvku root:123456 -X POST -H 'Accept: application/json' 'https://127.0.0.1:5665/v1/actions/schedule-downtime?type=Host&filter=true&start_time=14000&end_time=2000000000&author=ak&comment=-&fixed=0&duration=-14'
  • curl -fvku root:123456 -X POST -H 'Accept: application/json' 'https://127.0.0.1:5665/v1/actions/schedule-downtime?type=Host&filter=true&start_time=2010000000&end_time=2000000000&author=ak&comment=-'

@Al2Klimov Al2Klimov added this to the 2.14.0 milestone May 30, 2023
@cla-bot cla-bot bot added the cla/signed label May 30, 2023
@icinga-probot icinga-probot bot added area/icingadb New backend bug Something isn't working labels May 30, 2023
@julianbrost
Copy link
Contributor

What about any kind of input validation for new downtimes? end_time <= start_time and fixed && duration <= 0 is guaranteed to result in broken/useless downtimes, so it doesn't make sense to accept that.

@Al2Klimov
Copy link
Member Author

Sure. I have this on my to do list. But this PR doesn’t depend on that, does it?

@julianbrost
Copy link
Contributor

This PR on its own doesn't make clear what exactly your plan is. Also you said nothing about why you're changing this in the Icinga DB specific code instead of earlier in the downtime code so that no other code has to have special cases for strange values. Is there something you expect to work better this way for later changes you're planning?

@Al2Klimov
Copy link
Member Author

This code on its own just behaves like the other stuff which mitigates Icinga DB crashes.

Regarding preventing bad user behaviour in the future: the newly discovered existing ability to create end < start changes the whole picture of what's necessary for this (and for what you suggested). Whatever my plan was, it's now in the trash bin.

@julianbrost
Copy link
Contributor

Sure. I have this on my to do list.

Nobody besides you know that list, so please share what you're planning so that others can follow. This PR started as an alternative to #9773, so it would be much more helpful if the description included a summary what is different, what's in here and what isn't and what the plan is for things that aren't in here.

But this PR doesn’t depend on that, does it?

When following #9774 to the word, yes, this PR probably fixes it. But #9773 started with some better validation which would still be useful, but probably in a more compatible way. If you want to treat that separately, please create an issue for this so that we don't forget it.

@julianbrost
Copy link
Contributor

As the return value of GetDuration() isn't restricted to non-negative values, the following computation could result in a negative value (the same is also done in other places in that file):

attributes->Set("end_time", TimestampToMilliseconds(downtime->GetFixed() ? downtime->GetEndTime() : (downtime->GetTriggerTime() + downtime->GetDuration())));

In Go, the end time is parsed into a float64 and converted to a time.Time, both of which can handle pre-1970 values (i.e. negative Unix timestamps), the database columns are unsigned though.

However, I wasn't able to actually trigger that bug due to #9726 immediately removing the downtime when it triggers (as it's ending before its trigger time) so it's gone again before it makes its way to Icinga DB. Not sure if that's guaranteed though, maybe with enough load the timer might be delayed for long enough so that it's actually written to Redis and it might be a good idea to add a safeguard for this nonetheless.

via `std::max(0, x)` not to crash the Go daemon which can't handle such.
@Al2Klimov Al2Klimov force-pushed the icingadb-service-crashes-on-negative-downtime-duration-or-end-before-start-9774 branch from c3ff2fb to 75eaa81 Compare May 30, 2023 15:56
@julianbrost julianbrost merged commit 8a42c3b into master May 31, 2023
18 checks passed
@icinga-probot icinga-probot bot deleted the icingadb-service-crashes-on-negative-downtime-duration-or-end-before-start-9774 branch May 31, 2023 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/icingadb New backend bug Something isn't working cla/signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

icingadb service crashes on negative downtime duration or end before start
2 participants