Galactic cosmic rays are commonly believed to be accelerated at supernova remnants via diffusive shock acceleration. Despite the popularity of this idea, a conclusive proof for its validity is still missing. Gamma-ray astronomy provides us with a powerful tool to tackle this problem, because gamma rays are produced during cosmic ray interactions with the ambient gas. The detection of gamma rays from several supernova remnants is encouraging, but still does not constitute a proof of the scenario, the main problem being the difficulty in disentangling the hadronic and leptonic contributions to the emission. Once released by their sources, cosmic rays diffuse in the interstellar medium, and finally escape from the Galaxy. The diffuse gamma-ray emission from the * Principal corresponding author, stefano.gabici@apc.univ-paris7.fr, tel. +33157277024, fax. +33157276071 * * Corresponding author Galactic disk, as well as the gamma-ray emission detected from a few galaxies is largely due to the interactions of cosmic rays in the interstellar medium. On much larger scales, cosmic rays are also expected to permeate the intracluster medium, since they can be confined and accumulated within clusters of galaxies for cosmological times. Thus, the detection of gamma rays from clusters of galaxies, or even upper limits on their emission, will allow us to constrain the cosmic ray output of the sources they contain, such as normal galaxies, AGNs, and cosmological shocks. In this paper, we describe the impact that the Cherenkov Telescope Array, a future ground-based facility for very-high energy gamma-ray astronomy, is expected to have in this field of research.