There were quite a few attacks on harbours by subs in WW2, pioneered by the Italian manned torpedo attacks on Alexandria and Gibraltar, which, inter alia, crippled two British battleships. The Brits clearly much admired this and set about developing their own forces, including a true mini-sub, the X craft (you can see one at the Gosport submarine museum.)
The Brits saw no cultural need for suicide attacks. However, no X craft survived their most famous mission, the successful attack on the Tirpitz. I know that's not a harbour, but working your way up a defended fiord must be just as difficult.
Appropriately, a joint Italian-British outfit was set up to carry out operations against what remained of Fascist Italy. They penetrated Italian harbours and blew up a large floating dock and (in a separate raid) an 8-inch cruiser (the Bolzano, I think.)
Finally, an Anglo-Australian submarine raid on Singapore harbour blew up a Japanese cruiser.
On the German side, there was of course Prien's famous sinking of the Royal Oak in Scapa Flow, but that was bravado rather than a specific operation. They developed their own human torpedoes and mini-subs and committed over 100 of the craft to attacking the shipping lanes to Normandy. Many of the crews resolved on suicide attacks, but in the event most were lost through accident or rough seas. One of them torpedoed the Polish cruiser Dragon, but this made little difference as she was to be scuttled as part of the Mulberry mole anyway.