You are correct about galvanic corrosion. Two opposite metals in close proximity, with an electrolyte. In the case of battery posts, it's usually the difference between the battery post (Lead) and the electrical strap (Brass). Usually most new battery straps AND the clamping fasteners will be Lead plated, but the plating can be short lived. Electrolyte is supplied by humidity in the air, from wash water, and/
or seepage from around the battery posts. Each is easy to come by; pick one. The chart below shows the compatibility of metals....
If "2 dissimilar metals and an electrolyte" sound like a battery, then you're correct. What's happening is that a tiny battery is formed. So the "corrosion" is the result of an electrical process. Of course, the additional presence of an acid (if your post is leaking) doesn't help one bit.
Prevention is easy: exclude the electrolyte. This can be done by coating the post and terminal with any type of thick grease. This could be a specialized battery post protector grease or a bulk automotive grease. If your posts are leaking then the felt battery post protectors can help.