|I may have altered this chocolate pudding photo a smidgen (Source)|
Two bacterial culprits were isolated from greened pudding, a Klebsiella species and a Pseudomonas species. Unlike some bacteria, which live in very particular settings (e.g. sewage treatment plants or the antennae of bee-killing wasps), Klebsiella and Pseudomonas are happy in a wide range of environments. They're commonly found in water, soil, plants, and many animals including people.
The bacterial pudding residents, which were suspected to have come from the milk used to reconstitute the powder, had the ability to degrade a red azo dye included in the pudding to ensure it looked a proper chocolate brown.
Azo dyes come in a variety of colours. They contain two nitrogen atoms, each of which is twice bonded to the other with a third bond to adjoining bits of carbon (usually containing benzene-based rings). This sets up a pathway for electrons to move about the dye molecules, enabling the preferential absorption of certain wavelengths of light and thus producing a colour.
The pudding bacteria happened to produce an enzyme capable of taking electrons from a molecule called NADH and adding them to the double bonded nitrogen atoms in an azo dye, severing the bonds and breaking dye molecules apart into two colourless products. The loss of red colour caused the pudding to turn green.
Azo-degrading bacteria are of interest to industry folks since they help clean up wastewater containing azo dyes. These dyes, being synthetic, are otherwise resistant to being broken down by natural processes. The bacteria are also found in our intestines, meaning we can degrade the dyes present in processed foods we eat.
Dykes GA, Timm RG, von Holy A. 1994. Azoreductase activity in bacteria associated with the greening of instant chocolate puddings. Applied and Environmental Microbiology 60(8):3027-3029. [Full text]