Can the FBI or the CIA keep things secret from the President? Or does the FBI and the CIA always have to reveal the whole extent of the truth whenever the President is informed of something? Can they keep something secret if the President doesn't ask specifically for it? Like the President's life being in danger or that there's a mole working for Russia within the White House? I am thinking there might be exceptional cases where this is allowed, but I don't know what they are.
Different questions here.
- The President is never told everything. The various agencies produce thousands of pages of reports each day. Briefers make the decision what the President needs to be told, hopefully by their professional judgement and not out of other concerns (e.g. what would upset the President).
- If the President does ask, agencies like the CIA, DIA, NSA, ... have to provide a full answer (see the last paragraph of this article for presidential clearances). As chrylis mentioned in a comment, in practice the agencies could lie to the President. Wikipedia calls a deep state like this a conspiracy theory.
- It is traditional that the President keeps a distance from the workings of the Justice Department and related agencies. At times this tradition came under stress, like the Saturday Night Massacre when President Nixon
firedaccepted the 'voluntary' resignation of first the Attorney General and then the Deputy Attorney General for refusing to fire a special prosecutor. Or, more recently, the Trump presidency. Just how far the ability of the President goes to break tradition is a bit of an open question.
The US President can ask questions of US Government employees in the executive branch, which includes the CIA and FBI. If the employee refuses to answer then the US President can't compel an answer, since that is a judicial power. They can, of course, fire any employee who refuses a lawful direction. This firing of recalcitrant employees has notably been done by presidents Nixon (the "Saturday Night Massacre"), Reagan (every air-traffic controller), and Trump (FBI Director Comey).
The US President has no direct power over members of the judicial branch of government and no direct power over the agencies of the legislature itself.
In practice a lot of sensible government is knowing what you don't want to know. The strongest example of that is that no President wants to know the details of their employees acting covertly on international assignment, or the details of overseas' residents who may be covertly assisting the USA. One of the issues for the US agencies recruiting overseas' assistance has been that a recent US President did take an interest in such matters in the Ukraine; and the senior leadership of a previous administration leaked the name of a CIA intelligence officer to the Washington Post, which potentially placed at risk people who had contacted that officer.
Of course, they can. Even the US military have secrets.
One of the brightest examples, for me, was Edgar Hoover. A man who've stayed in power from 1935 till his death in 1972 definitely had secrets from the six presidents he overseat.
But generally, considering such situation, if things turn public, and there would be a scandal, FBI/CIA chief might be fired. But I don't remember anything more than firing a chief - all other people do stay in system.
In fact, I consider it's normal in such decentralized system as the US power system. NSA, FBI, CIA, Military, and hoard of other agencies and lobby groups - they definitely do have secrets from anyone other, including POTUS. But such behaviour is part of the system, I think.
I've hit this theme in another question some time ago.
Of course they can keep some things secret from the president. A quick example would be any investigations into the president or their administration. If there is information like that which could impact a criminal investigation they are not going to inform the target about what is going on and what they find.
As for the examples you give why would they ever hide that information from the president when it could cause massive damage to this country? Are you suggesting that the FBI or CIA want to harm/destroy the country?
Honestly why would they not inform the president if his life was in danger? Or why would they even let a known or suspected mole work in the White House?
I think they can especially if the President does not specifically ask for it. This can be considered a bit like lying by omission which I suppose may depend on the context of the situation. Sort of like how one cannot gain entry into the Vatican Archives to browse through records unless they specify what it is that they are looking for in particular. Not necessarily the same thing but somewhat similar. Sometimes one may not be aware of a thing that is there for one to ask about and focusing on one thing will require that attention be taken away from another. So a President would have to ask what all there may be to learn more about and if all is revealed what to do with that information. Whether or not the agency is being totally transparent is a problem to consider indeed. If there are exceptional cases one would have to ask what the sufficient reasons are for granting an exception. This cannot occur if all that is presented by them is taken at face value and knowing when something should or should not be taken as such I think is a part of the challenge overall. That is, when you should or should not trust what it is that you are given.
Now, perhaps these questions may have answers and I just have not seen them but a couple of examples where your inquiry is applicable to me at least is whether or not the President(s) knew about Project Mk-ultra at the time that the agency(ies) is purported to have conducted all of the experiments that were mentioned? What about as of recent with the claim that Jeffrey Epstein had been an asset of intelligence by Acosta? If that were indeed true did the President know and if not should they have been informed about it?
I am confident that they have lied at least once!