Legal basis is the GDPR, however it's possible to use services outside the UK/EU if similar data protection is possible. For the US this is not the case, at least this is the ruling of the CJEU. Google would have to provide additional guarantees to protect the data.
The case is identical for Microsoft 365.
I would advice for Nextcloud and Onlyoffice. If you are hardcore data protection.