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:
- DeployKey has no username method, so gl_username in the /allowed response is nil
- gitlab-shell sends username: nil to /git_audit_event
- Rails from_params creates an empty actor (no params matched)
- 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.