fix: shortcut KV permissions

All users have access to KV, however the permission system is used
because:
1. KV is a driver, and all drivers have access checks
2. The rate limit policy comes from the permission system

This change uses support for implicit permission shortcuts to prevent
any of the permission association tables from being read. It also
hard-codes the policy so that KV's rate-limit policy is not read from
the policy.json file.
This commit is contained in:
KernelDeimos
2025-07-06 15:52:11 -04:00
parent 3f0e7659f3
commit f6e6e8dff8
2 changed files with 33 additions and 0 deletions

View File

@@ -394,6 +394,9 @@ const install = async ({ services, app, useapi, modapi }) => {
const { WorkerService } = require('./services/worker/WorkerService');
services.registerService("worker-service", WorkerService)
const { PermissionShortcutService } = require('./services/auth/PermissionShortcutService');
services.registerService('permission-shortcut', PermissionShortcutService);
}
const install_legacy = async ({ services }) => {

View File

@@ -0,0 +1,30 @@
const BaseService = require("../BaseService");
const { PermissionImplicator } = require("./PermissionService");
class PermissionShortcutService extends BaseService {
_init () {
const svc_permission = this.services.get('permission');
svc_permission.register_implicator(PermissionImplicator.create({
id: 'kv permissions are easy',
shortcut: true,
matcher: permission => {
return permission === 'service:puter-kvstore:ii:puter-kvstore';
},
checker: async ({ actor }) => {
return {
policy: {
"rate-limit": {
max: 3000,
period: 30000,
}
}
};
}
}));
}
}
module.exports = {
PermissionShortcutService,
};