Pass key_id from gitlab-shell to /git_audit_event endpoint for SSH authentication

Summary

Git streaming audit events fail with 404 errors for deploy key authentication via SSH when the
log_git_streaming_audit_events feature flag is enabled.

Root Cause

The /api/v4/internal/shellhorse/git_audit_event endpoint receives username from gitlab-shell, but not key_id. For deploy
keys:

  1. DeployKey has no username method, so gl_username in the /allowed response is nil
  2. gitlab-shell sends username: nil to /git_audit_event
  3. Rails from_params creates an empty actor (no params matched)
  4. can_read_project? fails → 404 error

Proposed Solution

Pass key_id from gitlab-shell to the /git_audit_event endpoint.

The /allowed response already contains gl_key_id, so gitlab-shell has access to this value. Rails from_params already
handles key_id with highest priority and correctly creates a DeployKey actor via STI.

Changes Required

gitlab-shell (internal/gitlabnet/gitauditevent/client.go):

  • Add KeyID field to the Request struct
  • Pass response.KeyID when calling the audit endpoint

No Rails changes required.

Additional Benefit

This fix also improves user SSH key authentication. Currently, username is sent and the actor is created as User. With
key_id, the actor becomes Key, which more accurately represents what authenticated.

Verification

Tested locally by passing key_id to the /git_audit_event endpoint. can_read_project? returned true for the deploy key case.

epic: gitlab-org#20506 (closed)

Edited by Emma Park