In #2625846, support for a run-as parameter to the drush commands was added to allow running the export as a particular user - typical scenario being exporting user data likely requires the command being run as user 1 to allow access to protected user properties like email address.

Drush natively provides support for this, with --user=[uid]. As mentioned by ao2 in https://www.drupal.org/node/2625846#comment-11965919, this means that the --run-as is not necessary.

I have tried to export a node with drush dcer node 12345, and the user it exported did not contain any private information (email & so on). Running drush dcer node 12345 --user=1 however did.

I think we could revert the change to add the run-as parameter, and instead update documentation to note the --user feature & that it is (likely) required if trying to export content/data anonymous users/drush user doesn't have access to?

Another suggestion by ao2 is to instead always run the export command as user 1 by switching to them in code regardless. Would that be a preferred solution?

Comments

smaz created an issue. See original summary.

ao2’s picture

andypost’s picture

Title: Drush run-as argument is not required » Document export of user entity
Component: Code » Documentation
Parent issue: #2625846: Run drush export commands as customized user » #2829042: unclear how to import the export

update documentation to note the --user feature & that it is (likely) required if trying to export content/data anonymous users/drush user doesn't have access to

Nice catch!

I think that should be mentioned at https://www.drupal.org/docs/8/modules/default-content
..and probably readme

andypost’s picture

geerlingguy’s picture

So, a year later, it looks like the --user option might not be supported by Drush 9 anymore? I get the following when I try exporting with that option:

  The "--user" option does not exist.

See: What happen with --user option in Drush 9?. It looks like you have to support the user changes within the Drush command using the AccountSwitcherInterface.

So the run-as parameter does seem to be necessary, unless a patch like #2861591-6: Export content as user 1 when running in a CLI context is adopted.

ao2’s picture

Probably this can be closed as "outdated", AFAIU the issue is going to be fixed by #2861591: Export content as user 1 when running in a CLI context.

berdir’s picture

Status: Active » Closed (outdated)

Agreed, also 2.0.x doesn't care about permissions anymore and the user switching for export is gone.