A federal appeals court panel here yesterday upheld the authority of independent counsel Lawrence E. Walsh to investigate the Iran-contra affair and ruled that Marine Lt. Col. Oliver L. North must comply with a grand jury subpoena or face prison.

The U.S. Circuit Court of Appeals for the District of Columbia, in a decision filed late yesterday, upheld a ruling by U.S. District Court Judge Aubrey E. Robinson Jr. that Walsh's "backup" appointment by Attorney General Edwin Meese III is legal.

Meese gave Walsh the secondary appointment March 5 after Walsh's investigation of the secret sales of arms to Iran and the diversion of profits to aid the Nicaraguan contras was endangered by North's challenge of the constitutionality of the law. Walsh was initially appointed independent counsel by a special three-judge panel.

The court rejected claims by North that Walsh's investigation is unconstitutional.

The judges also found that North, who was fired from the National Security Council staff last November because of his role in the affair, must comply with a grand jury subpoena for a sample of his handwriting or face contempt charges and possible imprisonment.

Defense lawyers for North and other individuals who are targets of independent counsel investigations have argued that, under the Constitution, the independent counsels are "superior officers" who must be appointed by the president and confirmed by the Senate. Instead, under the 1978 Ethics in Government Act, the independent counsels are appointed by a special federal three-judge panel.

Yesterday's appeals court decision stopped short of commenting on the constitutionality of the independent counsel provisions under the Ethics in Government Act. And, in a dissenting opinion, Judge Stephen Williams said the court should have addressed that issue.

But Williams agreed with Judges Douglas H. Ginsburg and Ruth Bader Ginsburg that Walsh is operating legally.

"We hold that Walsh and the associate counsel derive the necessary legal authority from the attorney general's regulation of March 5, 1987, regardless of whether they also have the authority pursuant to their appointment under the ethics act," said the opinion, written by Douglas Ginsburg.

The 31-page opinion continued, "We have no difficulty concluding that the attorney general possessed the statutory authority" to appoint Walsh. "North's challenge to the subpoena does not make his constitutional challenge . . . reviewable at this time."

Robinson, in his July 10 opinion, also found there was no need to address the constitutionality of the Ethics in Government Act.

North, held in contempt by Robinson for failing to comply with the subpoena, is expected to appeal the decision to the Supreme Court.

Paul Friedman, who represented Walsh's office in the lawsuit, said, "We are pleased . . . . This permits us to proceed with the investigation."

North's lawyer was not available for comment.