How to get all users with a specific permission Is there a way to retrieve all users with a specific permission (eg "Post comments").
I only found the possibility to get them by their role:

Drupal::entityQuery('user')
-&gt;condition('status', 1)
-&gt;condition('roles', 'administrator')
-&gt;execute();


or

Drupal::service('entity_type.manager')
-&gt;getStorage('user')
-&gt;loadByProperties(['roles' =&gt; 'administrator']);
I had to get the roles that had a given permission to get users with a permission, example:
$roles = user_role_names(FALSE, 'example_permission');
$rids = array_keys($roles);

$uids = Drupal::service('entity_type.manager')-&gt;getStorage('user')-&gt;getQuery()
  -&gt;condition('roles', $rids, 'IN')
  -&gt;execute();

Apparently thats what Drupal core does in the permission filter for views, see:
\Drupal\user\Plugin\views\filter\Permissions
Hope that helps some!