How is it attached and how to keep it from leaking?
It is the rectangular type with what appears to be a foam rubber gasket where it attaches to the tank.
You can remove the flush valve by loosening the three screws.
Check the inside of the tank for smoothness, and the gasket for wear and tear, and reinstall.
The gasket can be purchased on the Kohler site.