ISIS attacked Russia because of Putin's big claim to be "Christian" (LOL) and because they are vying for attention.
Given the probable history of Russian false flag operations justifying the second Chechen War, there's a distinct possibility this was an FSB operation or that the FSB allowed it to move forward simply because Putin found it politically useful to justify further mobilization.
Cui bono? Certainly not Ukraine.
The terrorists heading toward Ukraine could have been done to make it look like Ukraine. See also this theory:
https://freerepublic.com/focus/bloggers/4226710/posts?page=1