Repository navigation
Limit roles to chosen companies, so a role's users reach only those companies' devices - #289
Merged
Merged
Conversation
…ompanies' devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Every role now covers every company (the default) or only chosen companies, so a team of technicians can be given its own customers' devices and nothing else. The built-in Administrator role always covers every company.
users.manage,roles.manage,settings.manage,authentication.manage,api_tokens.manage,audit.view,companies.manage,tags.manage,scripts.manage_shared,files.manage_shared,applications.manage,automation.manage,alerts.manage,custom_fields.manage) count only from roles over every company. A limited role can't be saved with one (400 instance_permission_on_limited_role), and one written into the database anyway grants nothing. Every permission is classified with aReachnext to its definition inrbac.rs, andGET /v1/permissionsreports it.404exactly as a missing device or company does, and lists leave it out: the device wall and its event socket, device pages (notes, tags, metrics, thumbnail, system info, monitors, wakes), software search, the Updates and outdated-applications views, remote handoffs and sessions, terminals, the file browser, Wake-on-LAN, script runs and file deliveries and their history, jobs, alerts (list, counts, pages, acknowledgement, realtime), enrollment installers and deployment tokens, and the companies list.403 permission_denied) unless the role holding the payload's permission andjobs.run_widecovers every company. A job none of whose devices are in reach is hidden; its other devices are left off its pages.403 permission_escalation).role.create/role.updateaudit events recordall_companiesandcompany_ids, plusprevious_companieswhen they change.devices.maintenanceis per company. A limited user sees and changes only windows on devices in reach, and starts maintenance on chosen devices, companies or tags in reach. "Every device" is refused; a device, company or window out of reach answers like a missing one; ending by tag ends only windows in reach. Maintenance policies, and install policies or jobs that set windows, needdevices.maintenancein every company or within the job's reach.reports.manageis instance-wide (schedules run on any device and email anyone), and saving or running a schedule needsreports.viewin every company. A user whosereports.viewreaches only some companies runs reports on chosen companies or tags. The report keeps the maker's reach (withinin its stored scope), so it covers only devices in reach. "Every device" is refused, and a company out of reach answers like a missing one. They see only reports they made, while what those covered stays in reach, and no schedules. New indexidx_reports_requesterserves their list.custom_fields.manage). Device values are read and set within the device's company (devices.view/devices.edit), and company values within that company (companies.view/companies.manage).custom_fields.revealis per company, so a secret is revealed only when the role holding it covers the device's or company's company. Bulk set refuses a device out of reach as missing, and the device wall filter matches only devices in reach. The Agent's script read and write path is unchanged: an Agent writes only its own device's run, and starting a run already needs reach.tools.*route goes throughrequire_device, so a device out of reach answers like a missing one.Website: the role editor has an "Every company / Only some companies" choice with a company picker, a Companies column, and disables instance-wide permissions (with an "Every company only" note) while limited. The job, deploy, report and maintenance dialogs hide "Every device" unless the user holds the permissions in every company (
limited_permissionsonGET /v1/account).Docs: new
docs/users-and-roles.md, README feature list and docs index,architecture.md,api.md,patch-management.md,custom-fields.md,remote-tools.md.Design
server/src/access.rsholds the rules.Accessmaps each permission to theCompanySet(AllorOnly(ids)) of the roles that grant it, andAccess::of(roles)builds it with instance permissions taken only from all-companies roles.Authorizedcarries it, withrequire_device(403 without the permission anywhere, 404 when missing or out of reach),require_company,require_everywhere, anddevices_condition/companies_conditionfor SQL. Lists filter in their one query (anINoveragents.company_id, served byidx_agents_company), with no per-device round trips.roles.all_companiesand arole_companiestable (cascade on role and company delete), edited directly in both0001_initial.sqlfiles.{"type":"skipped","revision":n}, so the website's revision sequencing still holds. A device moving out of reach arrives asagent_deleted, and one moving in asagent_upsert. Alert and job events are filtered the same way, and alert counts are counted within reach.device_packagesof devices in reach.Judgment calls
alerts.viewholder sees the rules list. Only alerts are scoped.audit.view, which is instance-wide, so limited users see only their own jobs.400 company_required).How tested
server/tests/company_scope.rs, with a limited technician against two companies plus a device in no company, on SQLite and PostgreSQL:roles.manageskipped, moves, company eventsallrefused, and companies, tags and devices narrowed; jobs hidden after a move and devices pages filteredserver/tests/query_plans.rsgains limited variants of the Updates fleet, outdated packages, device search and job device pages, checking they use indexes on both backends.access.rsunit tests cover the anti-leak rule, NULL companies, instance permissions, administrators and tokens.company_scope.rscoversallrefused, out-of-reach companies and devices answering as missing, starts by device, company and tag reaching only in-reach devices, others' windows hidden from list, get, end and edit, a device's windows, and ending by tag.company_scope.rscoversallrefused, out-of-reach company = missing, company and tag reports counting only in-reach devices, hiding others' reports and schedules, hiding reports after the role's scope moves, and schedule saving refused with limitedreports.view.company_scope.rscovers device and company values (read, set and reveal) in reach and as missing out of reach, with only in-reach reveals audited. It also covers bulk set with an outside device, the wall filter on text and secret fields, script read and write through a connected Agent (another device's Agent can't write into the run), split roles (view in one company, reveal in another) revealing nothing, and an all-companies role.company_scope.rscovers all 12 process, service and registry routes: they work in reach, answer as missing out of reach and in no company, and an all-companies role reaches every device.realtime.rs: device moves now bump the access generation, so the "everyday work" test was changed to match.cargo clippy --all-targets -D warnings,cargo fmt --check, andcargo teston SQLite and PostgreSQL 16.npm run verifyfor the website.