In general some department of the air force that ordered the plane would tell the factory how and with what colours they wanted it painted. However there are lots of exceptions to this.
British, Italian, German and US aircraft were fairly well documented WRT colours and schemes. You can often work out the whole scheme by just looking at a single photo of the plane and referring to drawings of the scheme. However there is the issue of repaints done at a depot or squadron level when a plane was moved to a new theater. For instance a lot of USAAF bare metal planes were given a top coat of olive drab or RAF green when they redeployed to France in 1944. Also some lend lease aircraft ordered by Britain would turn up in the UK painted in the RAF scheme but using the nearest USAAF equivalent colours.
Soviet and Japanese aircraft are a bit more of a minefield, part of the problem being a lack of documentation, although that has improved recently. Photos are often of very poor quality making it difficult to make out the scheme. Also Soviet aircraft schemes tended to a lot less strictly applied, with different factories using there own variations of the official scheme. There is still a lot of debate about what the correct shades are for the various colours used on Soviet aircraft.
Japanese aircraft used fairly standardised factory schemes but in the early to mid war years there was a lot of depot and squadron level repainting going on using all sorts of colours. Also different factories would use different shades of paint to each other. So for instance a Zero made by Mitsubishi would be a different shade of green and grey to one made by Nakajima. Luckily there are various clues that can be got from a B&W photo to tell which factory made the aircraft .