Legally OK: depends on jurisdiction, I imagine.
Morally OK: 100% of the time, as long as the ebook is identical to the physical one other than its format. That is, if you could scan and OCR the physical book and end up with the same result as the ebook, yes. If the ebook comes with extra content that you would not have access to without buying it in that format, I would say that's not OK. (Table of contents and indexes that link directly to a page rather than just listing its page number don't count in my opinion. Those are just the electronic equivalents of the paper indexing system.)
https://www.dmlp.org/legal-guide/circumventing-copyright-con...
Even in the US, not all of this is settled law.
https://en.m.wikipedia.org/wiki/Sony_Corp._of_America_v._Uni....
In other countries, your mileage will most definitely vary.
(IAtotallyNAL)
> For example, you can use copyrighted work for the purpose of research, private study, education, parody or satire. You can also reproduce copyrighted work to ensure interoperability of computer programs or for backup copies.
It never really made sense to me to view copyright as dictating what you are allowed to do with something. People do try to turn it into that, but it makes far more sense if you view the act of publishing as the step that is protected by copyright.
Laws do differ on this point but if we want to have any hope of owning anything in a digital world we need to push back against the idea that copyright allows someone to dictate the lives of anyone using their intellectual property.