Skip to content

SSH Identity enrollment silently swallows duplicate keys instead of informing the user #6846

Description

@luizhf42

Problem

When a user uploads an SSH public key that is already enrolled as an SSH Identity, the backend returns HTTP 200 with the existing record unchanged. The frontend receives no signal that the key was not actually created, so the user sees no feedback — no error, no toast, no indication that the operation was a no-op.

This happens because enrollSSHIdentity in server/api/services/ssh-identity.go treats same-fingerprint-same-user as an idempotent success (lines 126–128), returning the existing *models.SSHIdentity with a nil error. The route handler then responds with 200 and the old record, which is indistinguishable from a successful creation.

For comparison, the legacy Public Keys endpoint (CreatePublicKey in server/api/services/sshkeys.go) returns ErrPublicKeyDuplicated (→ HTTP 409) when the fingerprint already exists, giving the frontend a clear signal to display an error.

Expected behavior

The user should see a clear message (e.g. "This key is already enrolled") when they attempt to add a key that already exists.

Suggested fix

Return a 409 Conflict (or a dedicated error like ErrSSHIdentityAlreadyEnrolled) when the fingerprint belongs to the same user, instead of silently returning the existing record. This aligns with how CreatePublicKey handles duplicates and gives the frontend the error it needs to display a meaningful message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions