I've read in this article that the 3 valence quarks make up only 0.2% of the mass of a proton (or neutron) and the remaining 99.8% comes from gluons. From other sources we know that there are an infinite number of sea quarks popping in and out of existence, being created from and returning to gluons. Is it worthwhile to look at the contribution of these sea quarks as a source of mass, or do we just state that the gluons are the source of mass, regardless of the state they happen to be in at the moment?
The answer is 98.5% is the contribution of the sea of virtual gluons, quarks and antiquarks (that is, the interaction between the virtual gluons, quarks and antiquarks in the sea) to the total rest mass of the proton.
The masses of the quarks entering the proton when summed have mass less than 15 MeV, and the proton has a mass close to 1000. The mass of the proton comes up by the vector addition of the four dimensional vectors entering the problem, gluons, quark antiquark pairs that are holding the three basic quarks bound as a proton. The invariant mass resulting by adding up these innumerable constituents' four vectors, gives the mass of the proton.
The valence quarks' rest mass (the three quarks displayed in popular science models), on the other hand only contribute to the total proton mass by about 1.5%. So the answer to your question is that it is the interaction between all these virtual particles (quarks, antiquarks, gluons) that contributes most of the mass. They are virtual, off mass shell.