Skip to content

Enforce user ownership on application list and datasource connections - #1655

Merged
mkumatag merged 7 commits into
IBM:mainfrom
mkumatag:fix-application-datasource-ownership
Oct 28, 2026
Merged

mkumatag merged 7 commits into
IBM:mainfrom
mkumatag:fix-application-datasource-ownership

Conversation

@mkumatag

@mkumatag mkumatag commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Description

This PR enforces user ownership checks on application listing and datasource connect/disconnect routes:

  • List Applications (GET /api/v1/applications/): Filters applications by the authenticated user ID (created_by), ensuring callers only receive applications they own.
  • Connect Datasources (PUT /api/v1/applications/:id/datasources): Passes the authenticated user identity to the datasource service and rejects connection attempts on applications owned by other users with 403 Forbidden.
  • Disconnect Datasources (DELETE /api/v1/applications/:id/datasources/:datasource_id): Passes the authenticated user identity to the datasource service and rejects disconnection attempts on applications owned by other users with 403 Forbidden.

Changes

  • application_repo.go: Added CreatedBy field to ApplicationFilters and bound a.created_by = $N in query building.
  • application_service/common.go: Forwarded CreatedBy from list request to repository filters, updated DatasourceConnector interface and post-deploy attachment.
  • application_handler.go: Extracted userID from authentication context and populated CreatedBy in list requests.
  • interface.go & datasource_service.go: Updated ConnectDatasourcesToApplication and DisconnectDatasourcesFromApplication to accept caller identity and enforce app.CreatedBy == userID.
  • datasource_handler.go: Extracted userID from authentication context and passed it to connect/disconnect service methods.
  • Added comprehensive unit and handler authorization tests in authorization_test.go, datasource_service_test.go, and application_repo_test.go.

Testing

  • go test -count=1 -tags containers_image_openpgp ./internal/pkg/catalog/... passes.
  • Verified isolation between distinct authenticated user tokens.

- Filter application list results by authenticated user ID (created_by)
- Pass authenticated caller identity to datasource connect and disconnect operations
- Reject datasource connect/disconnect requests on applications owned by another user with 403 Forbidden
- Add repository, service, and handler tests for user-scoped queries and ownership enforcement

Signed-off-by: Manjunath Kumatagi <mkumatag@in.ibm.com>
@mkumatag
mkumatag requested a review from mayuka-c October 27, 2026 06:42
- Extract loadAppWithOwnership helper in datasource service to reduce complexity
- Extract parseDatasourceIDs helper in datasource handler
- Regenerate swagger documentation

Signed-off-by: Manjunath Kumatagi <mkumatag@in.ibm.com>
Comment thread ai-services/internal/pkg/catalog/apiserver/handlers/application_handler.go Outdated
Comment thread ai-services/internal/pkg/catalog/apiserver/handlers/datasource_handler.go Outdated
Comment thread ai-services/internal/pkg/catalog/apiserver/handlers/datasource_handler.go Outdated
Signed-off-by: Manjunath Kumatagi <mkumatag@in.ibm.com>
Signed-off-by: Manjunath Kumatagi <mkumatag@in.ibm.com>
Signed-off-by: Manjunath Kumatagi <mkumatag@in.ibm.com>
mayuka-c
mayuka-c previously approved these changes Oct 28, 2026

@mayuka-c mayuka-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mkumatag
mkumatag merged commit 488e302 into IBM:main Oct 28, 2026
9 of 10 checks passed
@mkumatag
mkumatag deleted the fix-application-datasource-ownership branch October 28, 2026 14:37
mkumatag added a commit that referenced this pull request Oct 29, 2026
…ce connections (#1655) (#1678)

Cherry-pick of #1655 (488e302) to release-0.4.

Enforces user ownership on application listing and datasource
connect/disconnect:
- `GET /api/v1/applications/` filters by authenticated user
(`created_by`)
- Datasource connect/disconnect return 403 when the application is owned
by another user

Conflict resolution notes (release-0.4 differs from main):
- Dropped the `Search` filter hunks (not present on release-0.4); kept
only `CreatedBy`.
- Skipped version bumps in Makefile/values.yaml.
- Did not carry `application_repo_test.go` (does not exist on
release-0.4).
- Added the `created_by` filter to `GetCount` (it builds its own query
on this branch) so pagination totals match the filtered list.

Validated: `go build`, `go test -tags containers_image_openpgp
./internal/pkg/catalog/...` pass.

---------

Signed-off-by: Manjunath Kumatagi <mkumatag@in.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants