ABSTRACT We demonstrate that supernova remnant (SNR) shocks embedded within massive star clusters can reproduce both the cosmic-ray proton and all-particle spectra measured in the vicinity of the Earth up to hundreds of peta-electronvolts (PeV). We model two classes of massive star clusters. The first population are ‘loose clusters’ that do not power a collective wind termination shock. SNR shocks then expand in a low-density and weakly magnetized medium, and this population mainly contributes up to the ‘knee’ of the CR spectrum around 1 PeV. The second population are young compact clusters, which are powerful and compact enough to sustain a collective wind outflow. SNR shocks then expand from the cluster into the strongly magnetized wind and accelerate nuclei up to ultra-high energies. This population, representing only about 15 per cent of all Galactic massive star clusters, nevertheless dominates the spectrum between ∼1 and 100 PeV. While these two components alone can reproduce the shape of the CR spectrum up to hundreds of PeV, adding a light subankle extragalactic component motivated by composition and anisotropy measurements, allows to reproduce the spectrum up to the highest energies. Fitting parameters are systematically linked to physical variables whose values are in line with theoretical expectations.