How to run certain scripts under the authority of a specific user?

Probably the easiest way to do this would be to avoid using a button and using a checkbox with a installable edit trigger, which also has a great side effect of mobile support.

Proposed solution:

  • Using a checkbox
  • Hook it to a installable edit trigger, which runs as the user who installed the trigger. Therefore, if the owner installs the trigger, no matter who edits the sheet, the trigger runs as the owner, giving access to privileged resources including protected ranges.

The installable version runs with the authorization of the user who created the trigger, even if another user with edit access opens the spreadsheet.

Notes:

  • Advantage:

    Code simplicity and maintainabilty. No need for webapp or any complicated setup.

  • Disadvantage: Security (with possible workaround)

    If the code is bound to the sheet, editors of the sheet get direct access to the script of the sheet. So, any editor with malicious intentions would be able to modify the code. If the function with installable trigger has gmail permissions, any editor would be able to log all the emails of the owner. So,special attention needs to be paid to permissions requested. Note that, this is already the case with your web app setup. Any editor maybe able to modify doGet to access protected data. If the webapp is in a separate standalone script, this isn’t a issue. You may also be able to fix this issue by setting the trigger at a predetermined version instead of Head version. See this answer for more information.

Leave a Comment