Skip to content

Search update command requires more permissions than needed #50

@godismyjudge95

Description

@godismyjudge95

Description

I just ran into this issue where we wanted to use scoped keys on our Meilisearch instance - only allowing keys to modify the index allocated to the site. But we run into a problem as on deploy we run php please search:update --all which according to this code:
https://github.com/statamic-rad-pack/meilisearch/blob/main/src/Meilisearch/Index.php#L88-L96

deletes and recreates the index before re-indexing everything. This is a problem because:

  1. All your custom index settings get wiped if you don't have them in Statamic's search config itself
  2. Deleting the index causes the scoped keys to not be associated to anything
  3. You can't delete/create indexes without having Master key level permissions on each site which is a security risk we'd like to avoid.

The solution is already laid out in Scout:
https://github.com/laravel/scout/blob/11.x/src/Engines/MeilisearchEngine.php#L55-L106
https://github.com/laravel/scout/blob/11.x/src/Engines/MeilisearchEngine.php#L373-L378

When they perform an update they only push content - they don't delete it. And if they do flush the index they just call deleteAllDocuments on the index instead of deleting + creating.

Steps to reproduce

  1. Set up a Meilisearch instance with a scoped key to an index
  2. Set up Statamic with the Meilisearch instance using the scoped key
  3. Run php please search:update --all - it will error due to the scoped key not having permissions to create indexes

Environment

Environment
Application Name: Website
Laravel Version: 11.47.0
PHP Version: 8.4.19
Composer Version: 2.9.5
Environment: local
Debug Mode: ENABLED
URL: website.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: redis
Session: file

Livewire
Livewire: v3.7.3

Statamic
Addons: 1
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.70.0 PRO

Statamic Addons
statamic-rad-pack/meilisearch: 3.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions