mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does `cozy:tenant:super-admin:base` granted `'*'` on `kubevirt.io/virtualmachines`, so a tenant super-admin could create a `VirtualMachine` of any size in their namespace, or edit the one a `VMInstance` release rendered and raise its guest size. Such a VM is not a HelmRelease the tenant ordered, so nothing that accounts for applications sees it. The grant arrived in #516 together with a `'*'` on `helmreleases`; that one was removed since, this one was not. Nothing in tree needs the write. Power goes through the `virtualmachines/start|stop|restart` subresources and console/VNC through the VMI subresources, both granted at the `use` level; size, disks and networking go through `VMInstance` values; Forklift's Plan admission check runs against the migration-controller's own service account, not the tenant. The rule becomes `get`, `list`, `watch`. `watch` stays on purpose: the dashboard's power controls and VNC/serial tabs watch the `VirtualMachine` for its live state, and no other tenant role grants it. The tenant roles are aggregated from ClusterRoles in several packages (`cozystack-basics`, `backup-controller`, `migration-controller`, `cozystack-scheduler`), so a write path can reach a tenant without touching the role that names it. A new test in `hack/e2e-install-cozystack.bats`, right after `tenant-test` is created, reads the effective rules of the `tenant-test-super-admin` group back from the apiserver in a single `SelfSubjectRulesReview`, fails if that review reports itself incomplete or carries an `evaluationError` (both of which `kubectl auth can-i --list` lets through with exit 0), subtracts what a bare `system:authenticated` identity already holds, and fails on any write verb that `hack/e2e-tenant-super-admin-write-verbs.yaml` does not name. A line covered by a wildcard grant is folded into it, so a new `apps.cozystack.io` kind does not need an allowlist edit. An allowlisted entry the cluster does not grant is printed without failing, for lanes that disable a package through `COZY_DISABLED_PACKAGES`. The allowlist sits under `hack/e2e-*.yaml`, which `select-e2e.sh` already escalates to the full suite. A helm-unittest on the role catches the same regression on the unit lane. Verified outside CI on a throwaway k3s v1.33 loaded with the rendered tenant ClusterRoles and the tenant RoleBindings, through `hack/cozytest.sh`: with `main`'s roles the test fails and names `virtualmachines.kubevirt.io - *`; with this change it passes; with the migration-controller roles removed it passes and prints the eight `forklift.cozystack.io` entries as not granted. The two awk programs give the same result under mawk and dash (`ubuntu:24.04`) as on macOS. The new helm-unittest fails against `main`'s template and passes here. `hack/bats-runner-coverage.bats`, `hack/bats-no-exit-trap.bats` and `hack/select-e2e_test.bats` pass. This change is the standalone fix of the RBAC prerequisite described in the tenant-quota design proposal, cozystack/community#48, where review asked for it to land on `main` independently of that design. ### Screenshots No UI change. ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: Walked the trigger map against the diff: an RBAC narrowing in `cozystack-basics` plus e2e harness files touch no values key, CRD, `ApplicationDefinition`, package list or tooling path. The one website page that patches `virtualmachines.kubevirt.io` directly, `networking/virtual-router.md`, is a procedure that "requires a Cozystack administrator account", which this change does not affect. ### Release note ```release-note fix(cozystack-basics): tenant super-admins can no longer create, edit or delete `kubevirt.io` VirtualMachines directly; they keep read and watch. Virtual machines are managed through VMInstance and VMDisk applications, power through the start/stop/restart actions. The install e2e now fails when a tenant super-admin gains a write verb outside a checked-in allowlist. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Access Control** * Tenant super-admins can view KubeVirt virtual machines with read-only permissions through the base role; it no longer grants broad write access to these resources. * Tenant super-admin write permissions are checked against an explicit allowlist. Permissions outside the approved list cause the end-to-end check to fail, while approved permissions not currently granted do not. <!-- end of auto-generated comment: release notes by coderabbit.ai -->