Problem/Motivation
I would think that drupal/core-composer-scaffold definitely has the potential to alter other packages. The README has a section "Altering Scaffold Files" so you can change other package scaffold files.
Also the file-mapping section doesn't seem to put any restrictions on where you can place the scaffold files so I would assume you could put them anywhere even within another package and even overwrite files in that package.
Actually in the section composer/installers it says
However, Composer and the
composer/installers plugin have a limitation that one project cannot be moved
inside of another project. Therefore, if you use composer/installers to place
Drupal modules inside the directory web/modules/contrib, then you cannot also
use composer/installers to place files such as index.php and robots.txt
into the web directory. The drupal-scaffold plugin was created to work around
this limitation.
So it definitely sounds like you can places scaffold files inside other projects
Actually drupal/core-composer-scaffold seems like such a unique plugin that I think we might need a follow-up to force sites to opt-in the ability for other packages to use this besides the known Drupal core uses. Looking at \Drupal\Composer\Plugin\Scaffold\AllowedPackages::getTopLevelAllowedPackages():
$implicit_packages = [
'drupal/legacy-scaffold-assets',
'drupal/core',
];
These are special cases but besides that you have to opt-in packages into via the allowed-packages setting. If I look at github dependents https://github.com/drupal/core-composer-scaffold/network/dependents I don't find any. So my guess is this composer plugin is not used very much at all outside of Drupal core itself. I think like composer plugins itself a plugin like this that lets other packages copy files literally anywhere seems to be incompatible with a staged update system. In #3331310: Exclude unknown paths in project base: only allow vendor + web root + whatever drupal/core-composer-scaffold allows we attempted to determine where all files to be scaffolded were but because there is no API for this it involved copying a bunch of internal code. If we were able to get that list we would probably have to do more with it that just worry about files in the base project directory. For instance what if a plugin moves a scaffold file into a directory that we are excluding from the apply phase?
Steps to reproduce
Proposed resolution
Don't support drupal/core-composer-scaffold if you have set any allowed-packages since core's own use it implicitly allowed by AllowedPackages::getTopLevelAllowedPackages().
It think this would save use a ton of complexity and actually only affect a very few sites who probably have complex use cases which is not the primary target of AU at least.
Remaining tasks
Determine if we want to let sites to override this to allow allowed-packages to be set. We could have something like allow-non-core-scaffold-packages that is simply a true or false.
This could be done in a core-post-mvp follow-up.
We also might want to consider at some supporting any package if drupal/core-composer-scaffold provided a UI like getAllScaffoldfiles() that would return all files across all packages that are allowed. Without this I don't think we can support it.
Issue fork automatic_updates-3338346
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tedbowComment #3
wim leers👏 Great find, and thanks for the detailed write-up! 🙏🤩
Issue summary update: improved markup and issue links; no material changes.
This definitely improves reliability, arguably also security. Added to roadmap at #3319030: Drupal Core Roadmap for Package Manager and Update Manager because you tagged it
core-mvp.Woah, this very much sounds like the "inter-package symlinks should indeed not be allowed, but intra-package symlinks should be!" problem that is described in #3319507: Add symlink support to Composer Stager 2.0, require that version, and simplify UX & tests accordingly and being solved in https://github.com/php-tuf/composer-stager/issues/58. i.e.
composer/installersmakes sure that each installed package remains one atomic unit. That is exactly what the symlink support is aiming to do going forward!(I bet they did that for
composer/installersto allow parallellization in the future: if each package is an atomic unit, operations can be run in parallel. If that is not the case, they must be run serially. Clearly, thedrupal/core-composer-scaffoldplugin must execute after all other packages have been installed/updated!)🤔I don't understand yet how this can happen; isn't that exactly what the code in #3331310: Exclude unknown paths in project base: only allow vendor + web root + whatever drupal/core-composer-scaffold allows is proposing to do? (Take into account the targets of the scaffold plugin, and not exclude those?)
Very interesting! Tagging for that: that plugin is part of Drupal core, and so we can just file a Drupal core issue that blocks general Automatic Updates/Package Manager support for this plugin 👍
Comment #4
tedbowre @Wim Leers question about
What I mean is a scaffold plugin could more files into any of the directories that excluded by any of the classes in
package_manager/src/PathExcluder. for instanceSiteFilesExcluderexcludes our files directories but for all we know a scaffold plugin could move file in there and then that file would be excluded when we apply the update to the siteComment #5
wim leersCouldn't that be prevented by ensuring that a new validator + excluder run last? 🤔
Comment #6
tedbowso that is why I think we should not support it for core-mvp. then we can decide later if there is actually a need to support it.
I think if it turns out that there very few site that are affecting by this restriction then I think it might be reasonable that those sites have to custom or contrib solution
For instance we exclude directories like the file directory because 1, it could be very large, 2. we expect files could be adding there during the update process.
If a scaffold move a file into the sites directory we would have to stop an update if we detected that.
Comment #7
wim leersComment #8
tedbowComment #9
wim leersDoesn't make sense to do this until #3342227: ScaffoldFilePermissionsValidator should use ComposerInspector instead of ComposerUtility is done, otherwise we're doing double work.
Comment #10
wim leersComment #11
wim leers#3342227: ScaffoldFilePermissionsValidator should use ComposerInspector instead of ComposerUtility landed!
Comment #12
wim leersDiscussed this with @omkar.podey, who'd already started looking into this! 👍 He has a pretty clear idea of how to approach this, very curious to see what he comes up with! 😄
Comment #13
omkar.podey commentedUsing
composer/Plugin/Scaffold/AllowedPackages.phpmakes it easier to manage which packages are allowed to scaffold files.sample code -
Comment #15
omkar.podey commented@Wim.leers i talked with @phenaproxima yesterday and he confirmed that any modules not in the allowed packages list except
"drupal/legacy-scaffold-assets", "drupal/core", will not be allowed to scaffold files by default, He also helped writing the documentation fordrupal/core-composer-scaffoldand has vouched for it's implementation (also agreed on the documentation needs to be clearer). So I was able to simplify the validator as well as the tests.Comment #16
wim leersLooking good! And thanks for catching "strict types" just in time before my review! 😁👍
Comment #17
omkar.podey commentedComment #18
wim leersPlease just mark going forward — I will have reduced capacity for reviews. @tedbow or @phenaproxima can also review! 😊
Comment #19
phenaproximaThis is looking very good. There is one choice here that I strongly object to, though.
Comment #20
omkar.podey commentedComment #21
phenaproximaThis looks really good. Thanks for addressing my feedback! A few more things and then IMHO this is good to go.
Comment #22
omkar.podey commentedComment #23
omkar.podey commentedComment #24
phenaproximaLooks great to me! This is still tagged for a follow-up, originating in #3. Once that's filed, this is RTBC!
Comment #25
omkar.podey commentedCreated #3350172: [PP-1] Support any package to scaffold files in Automatic Updates + blocked that issue on a core feature request #3350176: Create something like getAllScaffoldfiles() in core-composer-scaffold.
Comment #26
omkar.podey commentedComment #27
omkar.podey commentedComment #28
phenaproximaComment #30
phenaproximaComment #31
wim leersBeautiful end result! 👏😄