feat: switch RAG service to connect_as credentials#346
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 27 minutes and 39 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes implement a new authentication model for RAG services by introducing a preflight resource validation step and passing explicit connect-as credentials through the orchestration pipeline instead of relying on ServiceUserRole resources. Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 17 |
| Duplication | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
server/internal/orchestrator/swarm/rag_preflight_resource.go (1)
84-110: Consider adding a timeout for database operations.The
validatefunction performs database connectivity and role existence checks without an explicit timeout. If the database is slow to respond or the connection hangs, this could block indefinitely.The
ServiceUserRole.Refreshmethod (inservice_user_role.go) uses a 30-second timeout for similar database operations:ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel()Consider applying the same pattern here for consistency and reliability.
♻️ Proposed fix to add timeout
+import "time" + func (r *RAGPreflightResource) validate(ctx context.Context, rc *resource.Context) error { + ctx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + primary, err := database.GetPrimaryInstance(ctx, rc, r.NodeName)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/internal/orchestrator/swarm/rag_preflight_resource.go` around lines 84 - 110, The validate function may block on DB ops; wrap the incoming ctx with a timeout (e.g., 30s) using ctx, cancel := context.WithTimeout(ctx, 30*time.Second) and defer cancel(), then use that timed ctx for the calls in RAGPreflightResource.validate (notably primary.Connection(ctx, rc, r.DatabaseName), conn.QueryRow(ctx, ...).Scan(&exists) and conn.Close(ctx)) so all database operations honor the timeout and get cancelled consistently; ensure the cancel() is deferred immediately after creating the timed context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@server/internal/orchestrator/swarm/service_instance_spec.go`:
- Around line 97-101: The early-return for RAG/MCP in the method handling
ServiceInstanceSpecResource leaves legacy credentials intact; before returning
when s.ServiceSpec.ServiceType == "mcp" || "rag", explicitly clear the legacy
field by setting ServiceInstanceSpecResource.Credentials to nil (or empty) so
RAG records cannot carry stale creds forward—locate the block that checks
s.ServiceSpec.ServiceType and add the credentials reset (s.Credentials = nil)
immediately before the return.
In `@server/internal/orchestrator/swarm/service_instance.go`:
- Around line 35-38: The new ServiceInstance field ConnectAsUsername is never
populated from persisted/deserialized state so it stays empty and causes
spurious diffs; update the Refresh method on ServiceInstance to set
s.ConnectAsUsername = desired.ServiceSpec.ConnectAs (or the appropriate path to
the desired spec's connect_as value) when loading the desired state so the
persisted field is synchronized, or alternatively add "ConnectAsUsername" to
DiffIgnore if it is purely informational.
---
Nitpick comments:
In `@server/internal/orchestrator/swarm/rag_preflight_resource.go`:
- Around line 84-110: The validate function may block on DB ops; wrap the
incoming ctx with a timeout (e.g., 30s) using ctx, cancel :=
context.WithTimeout(ctx, 30*time.Second) and defer cancel(), then use that timed
ctx for the calls in RAGPreflightResource.validate (notably
primary.Connection(ctx, rc, r.DatabaseName), conn.QueryRow(ctx,
...).Scan(&exists) and conn.Close(ctx)) so all database operations honor the
timeout and get cancelled consistently; ensure the cancel() is deferred
immediately after creating the timed context.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 53a1b24e-8953-4f1b-9a0a-149bab32ef1e
📒 Files selected for processing (11)
e2e/rag_service_test.goserver/internal/api/apiv1/validate.goserver/internal/orchestrator/swarm/orchestrator.goserver/internal/orchestrator/swarm/rag_config_resource.goserver/internal/orchestrator/swarm/rag_config_resource_test.goserver/internal/orchestrator/swarm/rag_instance_resources_test.goserver/internal/orchestrator/swarm/rag_preflight_resource.goserver/internal/orchestrator/swarm/rag_preflight_resource_test.goserver/internal/orchestrator/swarm/resources.goserver/internal/orchestrator/swarm/service_instance.goserver/internal/orchestrator/swarm/service_instance_spec.go
Summary
This PR switch the RAG service from auto-generated
ServiceUserRolecredentials toconnect_ascredentials sourced fromdatabase_users.connect_asis now required when provisioning aRAG service.
Changes
connect_asis now required for RAG service specs;API returns 400 if omitted or if the referenced user is not in
database_usersServiceUserRolepath for RAG: no auto-generated Postgresroles are created;
generateRAGInstanceResourcesno longer emitsServiceUserRoleresourcesRAGConfigResource: always usesConnectAsUsername/ConnectAsPasswordfrom the spec; removed
ServiceUserRoledependency and legacy credentiallookup from
writeConfigFileServiceInstanceSpecResource/ServiceInstanceResource: RAG no longerdepends on
ServiceUserRole;RAGPreflightResource: addedPostgresDatabaseResourceIdentifieras adependency so the preflight runs after the database is created.
rag_userindatabase_usersandconnect_as: "rag_user"on the service specTesting
Verification:
rag_create_db_connect_as.json
Verified config file contains connect_as credentials
pgedge-rag-server.yaml
Verified API returns 400 when connect_as is omitted from a RAG service spec
Verified API returns 400 when connect_as references a user not in database_users
Checklist
PLAT-552