One exception
scripter1 said:
keep it in the back of your mind that maybe, just mayyyyyybe if your script hits too close to home the FBI could stop by to ask you a few questions.
Scripter1 is right there, all smilies aside. If a story is based on an actual event that's classified, and you were there and/or had knowledge of it as an employee of the government, then you no doubt signed a muzzle agreement. Violate it and, yes, you can have serious legal problems that can/will involve the production company.
Some authors and screenwriters ask for permission first. It's a good idea. Sometimes Big Brother will give you the go ahead (usually by ignoring the request), sometimes they won't and they'll send a couple of suits around to give you the rejection in person. It depends on the political situation. Those are reasons why there are so few stories based on
secret events that are written in first person by former spooks and S/As.
Also, if your story involves military hardware, say the use of a war-ship, DOD has to sign off on the script (making sure that branch of the service looks good) and will assign someone on their "side" to be there to make sure the script is followed. If it isn't to the letter, or their liking, then they can take their toys and go home, and bring legal action against anyone they want. In short, if you want their cooperation, they have to have script approval.