A paper I received to review has (independently) duplicated work that we are writing up. How to proceed in light of peer-review confidentiality? I did some research with some collaborators, and we have been writing an article ("paper A") describing the work.

A few days ago I received a request to review an article ("paper B") that covers most of our work. The authors of paper B have clearly worked independently on the same topic and beaten us to submission. (And fair play to them.)

This leads me to a number of related dilemmas:

The first, and I think easiest to resolve, is whether I have a conflict of interest in reviewing paper B. I think I can write a fair review, but I intend to tell the editor and allow them to decide whether I should proceed.

The other dilemmas arise mainly because I am bound by peer-review confidentiality. I should note that paper B is not available as a preprint.

Can tell my co-authors about paper B? I am convinced that confidentiality forbids me from showing paper B to them, but can I tell them that it exists and what it covers? My feeling is that the answer is 'no'.

But then, if I cannot tell my co-authors about paper B, then it seems I have to allow our paper A to proceed to submission even although I know of the overlap with paper B.

I am extremely uncomfortable with this, although one can take the view that since our work was independent, our paper A could still be published.

Furthermore, my first impression is that paper B is not suitable for the general journal to which it was submitted, but that I would recommend acceptance to a high-quality specialist journal, such as the one to which we intended to submit our paper A. This raises an unpleasant prospect: if our paper A proceeds to submission and publication, the authors of paper B might believe that I had rejected their paper and plagarized their work (a situation discussed in this question). This situation could arise even if I turn down the review request. Naturally, I want to avoid this.

How should I proceed? Could I ask the editor for permission to inform my co-authors about paper B?
Your question raises several quite serious ethical questions - thank you for posting it!

From the last part of your question it looks to me that you actually do have a conflict of interest, since you are afraid that what you write in your review may impact your future relations with this research group. I think it is best for you to withdraw from reviewing this manuscript, and fully explain your decision to the editors. I would even consider sending them a draft of your manuscript, if this does not violate your arrangements with other authors.

I am not sure your own paper can not be published. In my area it is not uncommon for two groups to produce similar results almost simultaneously (the second paper is submitted before the first is printed). This does bring some hard discussions sometimes, especially if the ideas are published on arXiv or presented at conferences. However, this does not stop papers from being published. Of course, you should not use anything from paper B to improve your paper A. 

To summarise: In my opinion, it's best for you not to study paper B in too much details, withdraw from reviewing it, explain this decision to Editors, and continue working on your paper A.