Skip to content

fix(#10073): creating a user under a taken name answers 409, not 403 'Security error' - #10076

Merged
robfrank merged 2 commits into
mainfrom
fix/10073-user-already-exists-answers-409
Oct 15, 2026
Merged

robfrank merged 2 commits into
mainfrom
fix/10073-user-already-exists-answers-409

Conversation

@robfrank

@robfrank robfrank commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #10073

Creating a user under a name that is already taken now answers 409, not 403 Security error. Previously the duplicate was raised as a ServerSecurityException, which AbstractServerHttpHandler.isSecurityFailure maps to 403. That is the same status a non-root caller gets, so a client could not tell "this user already exists" apart from "you may not do this". The duplicate is now a dedicated UserAlreadyExistsException. It extends ServerException, not ServerSecurityException. Both throw sites raise it: ServerSecurity.createUser (local) and the HA branch of createUserClusterWide. The HTTP error mapper answers it 409 User already exists, and the gRPC admin service answers ALREADY_EXISTS, as it already did for a taken API-token name. The createUser operation in the OpenAPI document now declares a 409 for the conflict. A 403 still means the caller is not root.

Coverage

Invariant: creating a user whose name is taken is reported as a conflict (HTTP 409 / gRPC ALREADY_EXISTS) on every entry point, never as a security refusal.

Enumeration:

$ grep -rn "already exists" server/src/main --include='*.java' | grep -i user
ServerSecurity.java:477  throw new ServerSecurityException("User '" + name + "' already exists");   (createUser)
ServerSecurity.java:600  throw new ServerSecurityException("User '" + name + "' already exists");   (createUserClusterWide, HA)
$ grep -rn "createUser(\|createUserClusterWide(" --include='*.java' . | grep -v /test/
PostUserHandler.java:90                 security.createUserClusterWide(userConfig)
ServerControlPlane.java:1390            createUserClusterWide (POST /server 'create user', gRPC CreateUser)
ArcadeDBServer.java:2589                security.createUser(...)  (database auto-create, guarded by existsUser)
ServerSecurity.java:837                 createUser(name,password) -> createUserClusterWide
ServerSecurity.java:2272                root bootstrap
Entry point Covered by fix? Covered by a test?
POST /api/v1/server/users -> createUserClusterWide yes Issue10073DuplicateUserAnswers409IT.aTakenNameOnTheRestRouteAnswers409AndLeavesTheFirstUserAlone
POST /api/v1/server create user -> ServerControlPlane.createUser yes ...aTakenNameOnTheServerCommandAnswers409
gRPC CreateUser -> ServerControlPlane.createUser yes Issue7309GrpcSecurityControlPlaneIT.createUserRefusesATakenNameWithAlreadyExists
ServerSecurity.createUser / createUserClusterWide (the two throw sites) yes Issue10073UserAlreadyExistsTest (both)
Java RemoteServer.createUser yes, it no longer surfaces SecurityException ...theRemoteClientNoLongerReportsATakenNameAsASecurityFailure
non-root caller still gets 403 unchanged (control) ...aNonRootCallerStillGets403EvenForATakenName
ArcadeDBServer database auto-create user argued checks existsUser first, so it never reaches the duplicate (L2570)
createOrUpdateGroup (issue's suggestion) argued an upsert, so there is no duplicate to report
createApiToken (issue's suggestion) already 409 PostApiTokenHandler maps ServerControlPlane.AlreadyExistsException to 409
HA follower yes LeaderCommandForwarder relays the leader's status unchanged

Known gaps:

Behaviour changes

  • Java RemoteServer.createUser on a taken name throws RemoteException instead of SecurityException. That is the point of the fix, but code catching SecurityException for the duplicate will see the change.
  • In a mixed-version cluster during a rolling upgrade, a request forwarded to a leader still running old code still gets 403, because the leader decides the status.

Test plan

  • Issue10073UserAlreadyExistsTest (2) - new
  • Issue10073DuplicateUserAnswers409IT (4) - new. Before the fix, the REST and command cases failed with 403
  • Issue7309GrpcSecurityControlPlaneIT (19, incl. the new case). The new case failed with INTERNAL when the mapping was removed
  • Regression: UserManagementIT (7), PostServerCommandHandlerIT (25), Issue7578SecurityAdminContractMatchesBehaviourIT (3), ServerSecurityIT (6), ServerSecurity*Test (19), OpenApiSpecGeneratorTest (3), GrpcErrorMapperTest (24), GrpcAdminServiceIT (14): all green

Adversarial pass

A separate reviewer read the issue and the diff with no other context. It found no in-scope gap.

Review cycles

cycle head review changes
1 6fffc68f0f claude: LGTM, 4 non-blocking points 79f9e078a9: the IT closes the request body stream (point 4)
2 79f9e078a9 claude: no blocking issues, 5 suggestions, all covered below none

Final state: clean-approval.

Skipped review items (with rationale)

  • HA follower path test: LeaderCommandForwarder.relayedResponse passes the leader's status and body through unchanged (L481, L613, L664), and the existing forwarding ITs pin that relay. An HA IT for one more status was not worth a Raft cluster fixture.
  • Release-note line for the 403 -> 409 change and SecurityException -> RemoteException in the Java client: agreed; it goes into the 26.11.1 release notes at merge, outside this PR. A typed client exception is Java remote clients have no typed exception for an 'already exists' conflict (409 / ALREADY_EXISTS) #10075.
  • Concurrent-create race: checked. The loser of the HA compare-and-set waits for its node to catch up, reads the user list again on its next attempt and throws UserAlreadyExistsException (ServerSecurity L594-608), so it also gets 409, not 403.
  • classifyError ordering: the new arm sits with the other 409 arms, and there is no generic ServerException arm before it.
  • Studio: studio-security.js renders every status other than the ones it handles specially through globalNotifyError(), and none of them depends on 403 for a duplicate (L177, L767).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Duplicate username creation now returns a clear conflict response: HTTP clients receive 409 Conflict, and gRPC clients receive ALREADY_EXISTS.
    • The conflict message identifies that the requested username is already in use. Existing user accounts remain intact, and non-root callers continue to receive 403 Forbidden when attempting user creation.

…'Security error'

A duplicate user name was raised as a ServerSecurityException, which the HTTP
boundary maps to 403 like an authorization refusal. It is now a dedicated
UserAlreadyExistsException (not a security failure): HTTP 409 on both the REST
route and the 'create user' server command, gRPC ALREADY_EXISTS, and the
createUser contract documents the 409.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cda7d736-9b15-44a2-8ef7-416ae979036f
📥 Commits

Reviewing files that changed from the base of the PR and between 6b1f278 and 79f9e07.

📒 Files selected for processing: 8
  • grpcw/src/main/java/com/arcadedb/server/grpc/ArcadeDbGrpcAdminService.java
  • grpcw/src/test/java/com/arcadedb/server/grpc/Issue7309GrpcSecurityControlPlaneIT.java
  • server/src/main/java/com/arcadedb/server/http/handler/AbstractServerHttpHandler.java
  • server/src/main/java/com/arcadedb/server/http/handler/openapi/SecurityAdminApiSpec.java
  • server/src/main/java/com/arcadedb/server/security/ServerSecurity.java
  • server/src/main/java/com/arcadedb/server/security/UserAlreadyExistsException.java
  • server/src/test/java/com/arcadedb/server/Issue10073DuplicateUserAnswers409IT.java
  • server/src/test/java/com/arcadedb/server/security/Issue10073UserAlreadyExistsTest.java
+----------------------------------------------------+
| Your logging is so chatty it needs a podcast deal. |
+----------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review

Clean, focused change. A dedicated `UserAlreadyExistsException` that extends `ServerException` (not `ServerSecurityException`) is the right way to separate "conflict" from "not authorized". Both throw sites, the HTTP classifier, the gRPC mapping and the OpenAPI spec are covered.

Checked

  • I grepped the `catch (ServerSecurityException)` sites in `server/src/main` (ArcadeDBServer auto-create, WebSocket, root bootstrap). None depended on the duplicate-user case, and the auto-create path is guarded by `existsUser`.
  • `ServerException` is a `RuntimeException`, so there is no signature fallout.
  • The classifier branch sits next to the other 409 cases and uses `firstOf(e, cause, ...)` like its neighbours, so wrapped causes (e.g. forwarded-to-leader) should map correctly.
  • Tests cover the REST route, the server command, gRPC, both throw sites, the Java remote client, and a 403 control for a non-root caller. They use `getServerHttpUrl`, so no hardcoded ports.

Minor suggestions

  1. Forwarded-to-leader path. On a follower, a duplicate create is forwarded to the leader, and the follower returns whatever status the leader sent. That should work now, but no test covers it. If an HA IT fixture is cheap to reuse, one assertion would lock it in.
  2. Behavior change for API consumers. Clients that matched on 403 for a duplicate user (e.g. some Studio or scripts) will now see 409. That is the intent, but it deserves a line in the release notes. The `RemoteServer.createUser` change from `SecurityException` to `RemoteException` is also visible to Java users. Consider a dedicated client-side conflict type later, as the test Javadoc already hints.
  3. Time-of-check race. `createUserClusterWide` HA branch reads `users` once and replicates with a fingerprint. If two concurrent creates both pass the check, the loser fails on fingerprint mismatch with a different error. This is pre-existing and out of scope, but it is worth confirming that it doesn't map to a 403.
  4. In `Issue10073DuplicateUserAnswers409IT`, the `open()` helper writes the body without closing the output stream. It works, but a try-with-resources would be tidier.

No blocking issues. LGTM.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review

Overall this is a clean, well-scoped fix. A dedicated UserAlreadyExistsException that deliberately sits outside the ServerSecurityException family is the right way to separate "taken" from "forbidden". It is raised at both throw sites, and the HTTP, gRPC and OpenAPI mappings are consistent. I found no blocking issues. I read the diff and grepped for other "already exists" user sites, but did not build or run the tests.

Strengths

  • The tests cover every entry point, including a control test that a non-root caller still gets 403.
  • The tests also check that the first user is left untouched after the conflict.
  • The comments explain why the exception does not extend ServerSecurityException.

Suggestions (non-blocking)

  1. Behavior change for clients. RemoteServer.createUser used to throw SecurityException for a duplicate and now throws RemoteException. The PR documents and tests this. It is still worth a release-note line, because callers that catch SecurityException to treat "exists" as success will break silently. A dedicated remote exception, or mapping 409 in the remote client, would be friendlier but can be a follow-up.
  2. HA forwarding. createUserClusterWide on a follower forwards to the leader. If the leader's exception is re-thrown as a generic error text on the follower, the 409 may be lost. If Issue10073 has no HA coverage, consider a test for the follower path, or confirm that the mapping survives the forwarding.
  3. Cause chain. firstOf(e, cause, ...) handles wrapping. Check that the placement in classifyError comes before any generic ServerException branch, so the more specific mapping always wins. It appears to.
  4. Studio. Check whether Studio JS or other clients match on 403 for "user exists" messages. A quick grep of studio/src/main/resources would settle it.
  5. Style. Issue10073UserAlreadyExistsTest and the other new tests follow the CLAUDE.md conventions (AssertJ, ports via getServerHttpPort). Nothing to change there.

Nice work.

@robfrank
robfrank merged commit 0f5e45e into main Oct 15, 2026
robfrank added a commit to ArcadeData/arcadedb-drivers that referenced this pull request Oct 15, 2026
Upstream fixed #10073 the same day: creating a user under a taken name now
answers 409 instead of 403 "Security error". The e2e tests pin 409, and the
docstrings, README and CLAUDE.md say a 409 from create_user means "already
there", noting that older servers answered 403.

Also from review: document that a database name is sent as given beyond the
trim check (one command per request, so no second command, but validate
untrusted names), and cover update_user/save_group with no optional
arguments and an embedded-space database name in unit tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
robfrank added a commit to ArcadeData/arcadedb-drivers that referenced this pull request Oct 15, 2026
…P client (#130)

Completes #122 after Go (#126) and Python (#128). ArcadeDBServer gains,
each throwing ArcadeDBError on failure:

- createUser, updateUser, dropUser, listUsers, saveGroup, deleteGroup and
  listGroups on /api/v1/server/users and /groups
- createDatabase and dropDatabase through POST /api/v1/server, rejecting a
  name the server would silently trim with RangeError
- serverCommand, returning the parsed body as Record<string, unknown>
  because the contract types it QueryResponse while admin commands answer
  {"result":"ok"}
- "sqlscript" in QueryLanguage, which previously did not compile

A duplicate user is 409 (403 before ArcadeData/arcadedb#10076) and a
duplicate database 400; both pinned in e2e.

Closes #122
robfrank added a commit to ArcadeData/arcadedb-drivers that referenced this pull request Oct 15, 2026
…o) (#129)

Upstream fixed #10073 the day #126 merged: creating a user under a taken
name now answers 409 instead of 403 "Security error", so the e2e pin in
go/e2e/admin_test.go fails against the current SNAPSHOT. Pin 409 and update
CreateUser's doc comment, the README and go/CLAUDE.md, noting that older
servers answered 403.

Also documents, as the Python review of #128 asked, that CreateDatabase sends
a name as given beyond the trim check.
robfrank added a commit that referenced this pull request Oct 21, 2026
…'Security error' (#10076)

* fix(#10073): creating a user under a taken name answers 409, not 403 'Security error'

A duplicate user name was raised as a ServerSecurityException, which the HTTP
boundary maps to 403 like an authorization refusal. It is now a dedicated
UserAlreadyExistsException (not a security failure): HTTP 409 on both the REST
route and the 'create user' server command, gRPC ALREADY_EXISTS, and the
createUser contract documents the 409.

(cherry picked from commit 0f5e45e)
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.

POST /api/v1/server/users answers 403 'Security error' for an existing user; the contract declares 409

1 participant