NO-ISSUE: Tighten tenant creation restrictions - #593
Conversation
|
@jhernand: This pull request explicitly references no jira issue. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: osac-project/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (13)
💤 Files with no reviewable changes (1)
WalkthroughPublic Organizations server write RPCs removed; PrivateOrganizationsServer builds a typed DAO, validates tenant metadata (mandatory name, id/tenant defaulting), and rejects immutable-field changes. A DB trigger enforces immutability; DAO maps trigger errors to ErrImmutable and generic server returns gRPC InvalidArgument. Tests and migration added. ChangesPublic/Private Organizations Server Separation with Tenancy Validation
Sequence Diagram(s)sequenceDiagram
participant Client
participant PrivateOrgServer
participant GenericDAO
participant Postgres
Client->>PrivateOrgServer: Create OrganizationsCreateRequest(metadata.name)
PrivateOrgServer->>PrivateOrgServer: validate metadata.name, default id/tenant
PrivateOrgServer->>GenericDAO: Create Organization
GenericDAO->>Postgres: INSERT
Postgres-->>GenericDAO: OK
GenericDAO-->>PrivateOrgServer: CreateResponse
PrivateOrgServer-->>Client: CreateResponse
Client->>PrivateOrgServer: Update (change metadata.name)
PrivateOrgServer->>GenericDAO: Update
GenericDAO->>Postgres: UPDATE (trigger enforces immutable)
Postgres-->>GenericDAO: ERROR (errImmutableCode, detail JSON)
GenericDAO->>GenericDAO: translateError(pgErr) -> ErrImmutable
GenericDAO-->>PrivateOrgServer: ErrImmutable
PrivateOrgServer-->>Client: gRPC InvalidArgument (ErrImmutable message)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Security ConsiderationsSeverity: MEDIUM — Impact: Public write surface reduced; immutable-field enforcement moves to DB/DAO layer. Verify private-server authorization boundaries remain strict and that translated DB error messages do not leak unexpected internal details. Poem
🚥 Pre-merge checks | ✅ 10 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (10 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/servers/private_organizations_server.go`:
- Around line 187-203: The code currently calls s.generic.Update(...) and
persists the change before checking immutable fields; move the immutability
checks so they run before invoking s.generic.Update: compare metadataBefore
(existing object's metadata) with the incoming request/object metadata to ensure
metadata.name and metadata.tenant are unchanged, and only call s.generic.Update
if both checks pass; reference the metadataBefore/metadataAfter comparison logic
and the s.generic.Update call (and the OrganizationUpdate request handling in
private_organizations_server.go) to locate and adjust the flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: osac-project/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 0cf51149-28c9-4aae-91ca-a16d121242d3
📒 Files selected for processing (5)
internal/servers/organizations_server.gointernal/servers/organizations_server_test.gointernal/servers/private_organizations_server.gointernal/servers/private_organizations_server_test.gointernal/servers/servers_suite_test.go
💤 Files with no reviewable changes (1)
- internal/servers/organizations_server.go
961109a to
1096739
Compare
Remove the `Create`, `Update` and `Delete` operations from the public organizations API, as tenants should only be managed through the private API. The public server now returns `Unimplemented` for those RPCs. In the private server, enforce that tenants use themselves as their own identifier and tenant: the `metadata.name` field is mandatory, the `id` must be empty or equal to the name (defaulting to the name), and `metadata.tenant` must also be empty or equal to the name (defaulting to the name). Enforce immutability of the `name` and `tenant` columns at the database level using a PL/pgSQL trigger function `check_immutable_columns`. The function accepts column names as trigger arguments, converts OLD and NEW rows to JSONB, and raises an exception with SQLSTATE `Z0001` when any of the specified columns have changed. The detail field of the exception contains a JSON array with the names of the modified columns, which the DAO `translateError` method parses into an `ErrImmutable` error with field names mapped to their protobuf paths (e.g. `metadata.name`). The generic server translates this into a gRPC `InvalidArgument` status. These constraints prepare the ground for introducing a foreign key on the tenant column in a later patch, which will require every tenant row to reference itself consistently. Update tests to reflect the new behaviour: the public server tests now create tenants through the private server and verify that mutating operations are rejected, while the private server tests cover the new validation rules. Add migration tests verifying that the trigger function and trigger are created, and DAO-level tests exercising the immutability enforcement and error translation. Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com> Assisted-by: Cursor
1096739 to
558a149
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CrystalChun, jhernand The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/override ci/prow/e2e-vmaas |
|
@jhernand: Overrode contexts on behalf of jhernand: ci/prow/e2e-vmaas DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Summary
Create,UpdateandDeleteoperations from the public organizations API, returningUnimplementedfor those RPCs, so that tenants can only be managed through the private API.(
metadata.nameis mandatory,iddefaults to/must equal the name,metadata.tenantdefaultsto/must equal the name).
nameandtenantcolumns at the database level using a PL/pgSQLtrigger function
check_immutable_columns. The trigger raises a customZ0001SQLSTATE with thechanged column names as a JSON array in the detail field. The DAO translates this into an
ErrImmutableerror, and the generic server maps it to a gRPCInvalidArgumentstatus.immutability enforcement and error translation, and server tests cover the validation rules.
These constraints prepare the ground for introducing a foreign key on the tenant column in a later
patch, which will require every tenant row to reference itself consistently.
Test plan
ginkgo run -r internal)UnimplementedZ0001errors intoErrImmutableInvalidArgumentfor immutable field updatesSummary by CodeRabbit
Breaking Changes
Improvements
Tests