Problem/Motivation
#3323461: Hosting environment (e.g. cPanel) may add additional files (including symlinks) to the project, which breaks AU showed the problem that there may be unrelated files and folders in the base directory of the composer project that we don't want to stage because of 2 reasons
- The may contain symlinks
- The may contain important hosting config which would not want to overwrite because the could be managed a unknown Composer plugin
#3331168: Limit trusted Composer plugins to a known list, allow user to add more should take care of 2). After that it should be ok to exclude this paths automatically
Proposed resolution
We need a subscriber that listens to CollectIgnoredPathsEvent and excludes any paths in the base directory of the project that are not 1 of the following
- The vendor directory
- The webroot
- In the list of scaffold files as determined by the
drupal/core-composer-scaffoldplugin
For number 3) \Drupal\Composer\Plugin\Scaffold\Handler::scaffold() seems to have rather complex logic to determine the scaffold files as it seems any package can provide scaffold files, not just Drupal core. We could copy this logic for now but as a follow-up we could create a Drupal core issue to propose refactoring this logic into 1 public method like getScaffoldFiles()
We should probably not commit this until #3331168: Limit trusted Composer plugins to a known list, allow user to add more is committed by we can work on getting this to RTBC in the meantime.
Remaining tasks
Create core follow-up if this issue is successful
Issue fork automatic_updates-3331310
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
kunal.sachdev commentedComment #4
kunal.sachdev commentedPostponed on #3328985: Allow Validators/Excluders to store info on an individual stage use..
Comment #5
wim leersComment #6
wim leers#3331168: Limit trusted Composer plugins to a known list, allow user to add more is no longer postponed, so decreasing postponedness.
Comment #7
tedbow@kunal.sachdev or @Wim Leers re #4 I am not sure why this issue is postponed on #3328985: Allow Validators/Excluders to store info on an individual stage use..
Does this validator need to store metadata in the stage? If so what?
Comment #8
tedbowRelating #3338346: Do not allow drupal/core-composer-scaffold to be used by packages other than core because if we didn't allow other uses besides drupal core then this issue would only have to worry about what files drupal core puts in the base folder, probably my inspecting a composer.json directly rather than worry what any package might use the scaffold for.
Comment #9
wim leers#7: Yes, @kunal.sachdev should've documented the reason when he postponed it in #4… Almost a month later, it's no longer clear to me either.
I suspect it's due to some need for first gathering information during
PreCreateEvent(i.e. "active") and passing that on to a later event just before applying duringPreApplyEvent(i.e. "stage"), to ensure differences in scaffolded files between "active" and "stage" are taken into account, and the superset of the two is allowed — to ensure scaffolded files can be added or deleted?(Otherwise a file scaffolded pre-update could not be deleted post-update, because it'd be excluded.)
@kunal.sachdev: Can you please confirm/deny my theory? 🙏🤓
Comment #10
wim leersI think the more explicit title makes the connection with #3338346: Do not allow drupal/core-composer-scaffold to be used by packages other than core clearer and sets clearer expectations.
Also: AFAICT this can happen independently of #3338346: Do not allow drupal/core-composer-scaffold to be used by packages other than core.
Comment #11
kunal.sachdev commentedI definitely didn’t postponed it because of the reason in #9, I had postponed this issue on #3328985: Allow Validators/Excluders to store info on an individual stage use.. because it was needed in #3315834: GitExcluder should not ignore .git directories that belong to packages installed by Composer so I thought we might need it in our issue as this is similar to GitExcluder. But now I think I can continue to work on this issue and will postpone if needed.
Comment #12
wim leers👍 Great! 😊
Comment #13
tedbowPostponed on #3335908: The 'fake_site' fixture cannot be using with `composer show` because the packages are not installed because we need to test that case where project root and web root are different. We don't want to make another `fake_site` fixture until we fix the current one
Comment #14
tedbowComment #15
wim leersLooks like some essential files are being excluded … like
composer.lock😳😁Comment #16
tedbowI have pushed up a start to how I think we can test a project with different web and project root. see the comments in
\Drupal\Tests\package_manager\Kernel\PathExcluder\UnknownPathExcluderTest::createTestProjectForTemplateAt least 1 test should fail now until it is implemented
Comment #17
kunal.sachdev commentedComment #18
wim leersLooking great — this needs docs improvements and additional test cases, but it looks superb otherwise! 🤩
Comment #19
kunal.sachdev commentedComment #20
kunal.sachdev commentedComment #21
wim leersDisabling
UnknownPathExcluderyields:→ test coverage works as expected! 👍
I left one documentation nit suggestion that I cannot apply because GitLab is once again buggy 🤷♂️ @tedbow or @phenaproxima can apply it prior to commit. I suggest @phenaproxima commits this one because @tedbow has many other things on his plate today.
Comment #22
phenaproximaI think this generally makes sense but there are a few things we could change, IMHO, to increase the clarity of the code and the comments. Nothing major, though.
Comment #23
tedbow@phenaproxima thanks for the review. The feedback was pretty straight forward so I addressed. There were a couple parts we could just remove so we didn't need update those comments.
going to self RTBC because the feedback was straight forward
Comment #25
tedbow@phenaproxima hopefully I addressed your feedback correctly. I pretty much copied your suggested improvements
Comment #26
wim leersYay, this unpostponed #3323461: #3323461-19: Hosting environment (e.g. cPanel) may add additional files (including symlinks) to the project, which breaks AU.
The commits after I RTBC'd all look like solid improvements 👍