I'm just taking the recent Mark Zuckerberg Senate hearings which were held in the open in the United States. Is there some sort of fine line that the Senate has to follow? Can they ask any questions even if it may impinge upon any non-disclosure agreements signed by the defendant, e.g. regarding trade secrets?
Senators, and anyone else for that matter, can ask any questions they want.
The witness is required to answer the questions only if under subpoena, and only if the answer of the question would neither require disclosure of privileged information nor violate a 5th Amendment right (which is a form of privilege).
Many things that are the subject of an NDA are not privileged information, and the fact that someone claims that something is a trade secret does not automatically make it privileged information.
Privileges can be established by statute, court rule or at common law.