For retiring Navy Cmdr. Bruce L. Valley, the seemingly simple task of filing to run against Sen. Warren B. Rudman (R-N.H.) has turned into a mountain almost too high to climb.

Valley, 42, a test pilot and published poet who has been a Pentagon speech writer and spokesman for President Reagan's Strategic Defense Initiative, is leaving the Navy on July 1. At the urging of conservative groups in New Hampshire, he has been preparing to challenge the heavily favored Rudman in his bid for a second term.

But wherever Valley has turned, someone seems to throw an unexpected obstacle in his way.

The first came from Navy Secretary John F. Lehman Jr., on whose staff he had served for 2 1/2 years. Valley asked Lehman in February for a 17-day waiver of regulations banning political activity, so that he could meet the filing deadline for the New Hampshire Republican primary at 5 p.m. today. Lehman bucked the question to Assistant Secretary Chase G. Untermeyer. Citing a memo Valley had written friends in January about his possible interest in opposing Rudman, Untermeyer refused the request May 14, saying it would set a bad precedent.

Lehman's office said neither he nor Untermeyer had any contact on the issue with Rudman, a member of the Appropriations subcommittee on defense, or his staff.

Valley's conservative backers then sought to place him on the ballot by collecting 200 petition signatures, but the New Hampshire attorney general's office came down with a ruling that revised decades of practice and required Valley to submit a signed declaration of candidacy along with the petitions -- something the Navy says he cannot do.

Assistant Attorney General Ronald F. Rodgers, who made the ruling, said he had no contact with Rudman or Rudman's campaign manager, Thomas Rath, both former New Hampshire attorneys general.

Nancy Gilbertson of Mount Vernon, N.H., a conservative activist who organized the petition drive, said, "Every door we try is slammed in our face. I don't want to sound paranoid, but I have to ask myself, who does this benefit? It benefits Warren Rudman."

Rudman said, "I did not get involved or ask anyone to get involved in any way. Absolutely not. There is a federal law and a state law, and if Mr. Valley has problems with them, those are his problems."

"I really wouldn't be that concerned about a primary challenge," said Rudman, who is bringing 13 of his Senate colleagues to New Hampshire tonight for what is being billed as the biggest fund-raiser in the state's history.

Valley has never run for office, but he has some useful New Hampshire credentials. A native of Rye, he graduated from Phillips Exeter Academy and went on to the Naval Academy at Annapolis and later the Naval War College. His wife is a former Miss New Hampshire.

In recent months, while assigned to a planning group in the undersecretary of defense's office, he has made several speeches and appearances in New Hampshire, usually advocating President Reagan's "Star Wars" program.

His speeches drew the interest of a grass-roots conservative group called the New Hampshire Association for Freedom Through Strength. Gilbertson, the group's chairman, said she and others have been "kind of upset with Rudman" on aid to the contras and other issues, and encouraged Valley to challenge him.

She was particularly critical of the attorney general's ruling that knocked out the petition drive.

Secretary of State William Gardner said that in the 72 years New Hampshire has had a primary, candidates could get on the ballot either by signing a declaration of candidacy and paying a filing fee or by having supporters submit 200 petition signatures along with an assent by the candidate to having his name appear on the ballot.

Valley told his backers he was free under Navy regulations to sign the assent, since he would be a civilian by the time ballots are printed, even though he could not formally declare his candidacy while in uniform.

Gardner said a query from a reporter about that distinction caused him to call Rodgers for a ruling. Rodgers said that when the election laws were recodified in 1979, the legislature in effect required a declaration of candidacy even for petition candidacies. He said it was "just a coincidence" that his new interpretation was being applied for the first time to a prospective Rudman opponent.

The senator may yet find Valley in his path to reelection. On Wednesday Valley signed a notice of "intent to run" as an independent. He can become a candidate after his Navy discharge if his backers can collect 3,000 petition signatures this summer.