Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Authorization failed" on new build at install civivolunteer #486

Closed
artfulrobot opened this issue Nov 6, 2019 · 14 comments
Closed

"Authorization failed" on new build at install civivolunteer #486

artfulrobot opened this issue Nov 6, 2019 · 14 comments

Comments

@artfulrobot
Copy link
Contributor

Expected: successful build

Actual: I get this error:

+++ drush -y cvapi extension.install key=org.civicrm.volunteer debug=1

Authorization failed                                                                                                                                                               [error]
Array
(
    [error_code] => unauthorized
    [entity] => Extension
    [action] => install
    [trace] => #0 /buildkit/build/dmaster/sites/all/modules/civicrm/Civi/API/Kernel.php(166): Civi\API\Kernel->authorize(Object(Civi\Api4\Provider\ActionObjectProvider), Object(Civi\Api4\Generic\DAOSaveAction))
#1 /buildkit/build/dmaster/sites/all/modules/civicrm/Civi/Api4/Generic/AbstractAction.php(235): Civi\API\Kernel->runRequest(Object(Civi\Api4\Generic\DAOSaveAction))
#2 /buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Utils/Migrate/Import.php(371): Civi\Api4\Generic\AbstractAction->execute()
#3 /buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Utils/Migrate/Import.php(82): CRM_Utils_Migrate_Import->customFields(Object(SimpleXMLElement), Array)
#4 /buildkit/build/dmaster/sites/all/modules/civicrm/tools/extensions/civivolunteer/CRM/Volunteer/Upgrader.php(836): CRM_Utils_Migrate_Import->runXmlElement(Object(SimpleXMLElement))
#5 /buildkit/build/dmaster/sites/all/modules/civicrm/tools/extensions/civivolunteer/CRM/Volunteer/Upgrader.php(48): CRM_Volunteer_Upgrader->executeCustomDataTemplateFile('volunteer-custo...')
#6 /buildkit/build/dmaster/sites/all/modules/civicrm/tools/extensions/civivolunteer/CRM/Volunteer/Upgrader/Base.php(306): CRM_Volunteer_Upgrader->install()
#7 /buildkit/build/dmaster/sites/all/modules/civicrm/tools/extensions/civivolunteer/volunteer.civix.php(131): CRM_Volunteer_Upgrader_Base->onInstall()
#8 /buildkit/build/dmaster/sites/all/modules/civicrm/tools/extensions/civivolunteer/volunteer.php(204): _volunteer_civix_civicrm_install()
#9 /buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Extension/Manager/Module.php(76): volunteer_civicrm_install()
#10 /buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Extension/Manager/Module.php(48): CRM_Extension_Manager_Module->callHook(Object(CRM_Extension_Info), 'install')
#11 /buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Extension/Manager.php(264): CRM_Extension_Manager_Module->onPreInstall(Object(CRM_Extension_Info))
#12 /buildkit/build/dmaster/sites/all/modules/civicrm/api/v3/Extension.php(58): CRM_Extension_Manager->install(Array)
#13 /buildkit/build/dmaster/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(101): civicrm_api3_extension_install(Array)
#14 /buildkit/build/dmaster/sites/all/modules/civicrm/Civi/API/Kernel.php(168): Civi\API\Provider\MagicFunctionProvider->invoke(Array)
#15 /buildkit/build/dmaster/sites/all/modules/civicrm/Civi/API/Kernel.php(99): Civi\API\Kernel->runRequest(Array)
#16 /buildkit/build/dmaster/sites/all/modules/civicrm/api/api.php(23): Civi\API\Kernel->runSafe('extension', 'install', Array, NULL)
#17 /buildkit/build/dmaster/sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc(1557): civicrm_api('extension', 'install', Array)
#18 phar:///buildkit/extern/drush8.phar/includes/command.inc(422): drush_civicrm_api('extension.insta...', 'key=org.civicrm...', 'debug=1')
#19 phar:///buildkit/extern/drush8.phar/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#20 phar:///buildkit/extern/drush8.phar/includes/command.inc(199): drush_command('extension.insta...', 'key=org.civicrm...', 'debug=1')
#21 phar:///buildkit/extern/drush8.phar/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#22 phar:///buildkit/extern/drush8.phar/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#23 phar:///buildkit/extern/drush8.phar/includes/startup.inc(465): drush_main()
#24 phar:///buildkit/extern/drush8.phar/includes/startup.inc(369): drush_run_main(false, '/', 'Phar detected. ...')
#25 phar:///buildkit/extern/drush8.phar/drush(114): drush_startup(Array)
#26 /buildkit/extern/drush8.phar(10): require('phar:///buildki...')
#27 {main}
    [is_error] => 1
    [error_message] => Authorization failed
@wmortada
Copy link

wmortada commented Nov 6, 2019

I'm getting the same error.

@ginkgomzd
Copy link
Contributor

does this mean that VOL is d8 incompatible?
Why is API4 in the picture?

@artfulrobot
Copy link
Contributor Author

Sorry, this is on a d7 build.

@artfulrobot
Copy link
Contributor Author

artfulrobot commented Nov 6, 2019

I wondered about the api4 stuff but just figured as it's being pushed now that maybe v3 defers/uses v4 in doing its thing now. (but this was just a guess, I'm v. unfamiliar with apiv4 and also the way buildkit works)

@ginkgomzd
Copy link
Contributor

against core master branch??
Seems like a change in CRM_Utils_Migrate_Import->runXmlElement() could be the cause of this.
It would be nice to have a better idea of the type of authorization... I'm guessing API authorization.
I wondered about SQL permissions, since this has to do with creating custom fields, but builldkit should be handling that fine.

@artfulrobot
Copy link
Contributor Author

To clarify, I'm just running

civibuild create dmaster

@seamuslee001
Copy link
Contributor

I believe it will be fixed by civicrm/civicrm-core#15741

@totten
Copy link
Member

totten commented Nov 6, 2019

Seems like a change in CRM_Utils_Migrate_Import->runXmlElement() could be the cause of this.
It would be nice to have a better idea of the type of authorization... I'm guessing API authorization.

Quite right. Specifically, a recent commit swapped CRM_Core_BAO_CustomField::bulkSave with \Civi\Api4\CustomField::save, which subtly changes the permissioning. In BAO+APIv3, the default behavior is to "do what I say, regardless of permissions"; but in APIv4, the default is to check the logged-in-user permissions. If the operation is run via CLI, then you probably don't have a logged-in-user, so the check fails. The fix just restores the old permission/behavior.

Tangential factoids:

  • If one comes across a similar bug and needs a temporary work-around, just set an admin user (drush ... -u myadmin or cv ... -U myadmin).
  • For cv api4, it uses setCheckPermissions(FALSE) on the main API call. (Otherwise, you'd have to pass -U myadmin all the time...)

Anyway, the fix is merged into civicrm-core. Just make a new build or do a git pull on your current build.

@totten totten closed this as completed Nov 6, 2019
@artfulrobot
Copy link
Contributor Author

Thanks all

@wolfsden3
Copy link

@totten for the uninitiated muddling through what .php file do I need to edit? Which one in the Api4 folder is "...the main API call"...? I had this bork a wordpress site and this is surely the "fix" but I can't figure it out :p

Error from a CLI:
`PHP Fatal error: Uncaught CRM_Core_Exception: [unauthorized: Authorization failed

thrown in /home/hosted_site/civi.hosted_site.net/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php on line 232`

Thanks.

@artfulrobot
Copy link
Contributor Author

@wolfsden3 is your issue related to this specific issue?

Because this issue was solved by the following commit in 2019:
civicrm/civicrm-core@f6168ef

and affected building a buildkit dev version of civi, but it sounds like you're getting an authorization failed error while running a cli command on a pre-existing wordpress site? If so, this isn't the right place to get help. You could try posting more info at civicrm.stackexchange.org or on chat.civicrm.org

But if you are trying to build an offline test version of Civi and getting this error during the build, then we should reopen this issue.

@wolfsden3
Copy link

No it's not but the permissions issue from cli is the issue. I farted around with it for a hot minute then decided to just upgrade to the .0.0.1 release above what I had (the latest) LOL. It "fixed" whatever the issue was. Others had similar problems where the cli was working along just fine calling an api for things like sending email and they suddenly got that authorization problem. Why it magically happened who knows but doing the upgrade seemed to resolve this issue. The real problem is it crashed the entire Wordpress website just because civi crashed. That seems rude :P

Thanks for your reply.

@wolfsden3 is your issue related to this specific issue?

Because this issue was solved by the following commit in 2019: civicrm/civicrm-core@f6168ef

and affected building a buildkit dev version of civi, but it sounds like you're getting an authorization failed error while running a cli command on a pre-existing wordpress site? If so, this isn't the right place to get help. You could try posting more info at civicrm.stackexchange.org or on chat.civicrm.org

But if you are trying to build an offline test version of Civi and getting this error during the build, then we should reopen this issue.

@totten
Copy link
Member

totten commented Jun 22, 2023

@wolfsden3 Yeah, that error doesn't quite tell you enough to pick a file to edit. It would help to:

  • Clarify the command/context where it failed
  • If possible, get a longer backtrace.

In terms of quick mitigations, if there's a CLI command that hits a permission error, you can often resolve it by specifying a user, e.g.

cv php:eval 'doSomething();'

cv php:eval --user=admin 'doSomething();'

(I'm pretty sure drush has the same --user flag.)

@aydun
Copy link
Contributor

aydun commented Jun 23, 2023

Might be related to this: https://lab.civicrm.org/dev/core/-/issues/4362#note_91616

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants