A simpler solution is to put all of this into 1 route and use Artisan::call() instead of shell_exec().
routes/gae.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;
Route::get('scheduler', function (Request $request) {
if(!$request->hasHeader('X-Appengine-Cron')) {
return abort(401);
}
Artisan::call('schedule:run');
return response('', 204); // no content
});
then load this routes file in the app/Providers/RouteServiceProvider.php
public function boot()
{
// ...
$this->routes(function () {
// ...
$this->mapGaeRoutes();
});
}
protected function mapGaeRoutes()
{
Route::group(base_path('routes/gae.php'));
}
Or, just throw that one route into routes/web.php and skip the route provider modification.
Authorization
This project from github user stackkit has better security checking, but it only runs jobs, not scheduled tasks. Perhaps Artisan::call('schedule:run') can find it's way into this cloud tasks project.
You can see how this project are authorizing the Oidc token given by google by checking the signature and the issuer (iss claim).
You can trivially examine the Oidc token given by google without verifying the signature, if you could hide a known shared secret in the custom claims for the service account, you could verify that and be given a modicum of security.
Since this is only running artisan schedule, and it's running every minute, the only thing you have to guard against is DoS attack.
https://github.com/stackkit/laravel-google-cloud-tasks-queue/blob/master/src/TaskHandler.php