summaryrefslogtreecommitdiff
path: root/internal/command
Commit message (Collapse)AuthorAgeFilesLines
* Add context fields to loggingid-context-fieldsIgor Drozdov2021-09-151-1/+1
| | | | It adds correlation ids wherever possible
* refactor: rearchitect command and executable Go modulesfeistel2021-09-084-467/+0
|
* Merge branch 'remove/generic-args' into 'main'Nick Thomas2021-09-085-28/+28
|\ | | | | | | | | | | | | refactor: remove commandargs.GenericArgs Closes #212 See merge request gitlab-org/gitlab-shell!506
| * refactor: add acceptargs field to executablefeistel2021-09-083-9/+11
| | | | | | | | | | parse logic will only run if the executable accept args. healthcheck is the only one not accepting arguments.
| * refactor: improve unknown executable error messagefeistel2021-09-081-1/+2
| |
| * refactor: remove commandargs.GenericArgsfeistel2021-08-113-21/+18
| |
* | refactor: move away from ioutil (deprecated)feistel2021-08-196-16/+16
|/
* Merge branch 'security-300265' into 'main'Patrick Bajao2021-08-042-4/+9
|\ | | | | | | | | Modify regex to prevent partial matches See merge request gitlab-org/security/gitlab-shell!6
| * Modify regex to prevent partial matchesRobert May2021-06-292-4/+9
| |
* | Remove some unreliable testsNick Thomas2021-07-303-46/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | Logrus buffers its output internally, which makes these tests fail intermittently. They're also not a good example to follow generally. We now have acceptance tests that exercise this functionality so I'm pretty relaxed about losing the expectations. However, we can test them by inspecting the server-received metadata too, so there's no loss of coverage here. The move from logrus to labkit for logging also makes these tests hard to justify keeping.
* | Switch to labkit/log for logging functionalityIgor Drozdov2021-07-221-1/+2
| |
* | Fix the Geo SSH push proxy hangingValery Sizov2021-07-012-5/+27
|/ | | | | | | | | | Geo SSH proxy push currently impossible when the only action that happens is branch removal. This fix works in a way that it waits for flush packet from git and then checks pkt lines to determine is pack data is expected. The thing is that git doesnt send pack data when only branch removal happens. Explanation is in https://gitlab.com/gitlab-org/gitlab/-/issues/330494
* fix: upgrade of the gitaly dependencyPavlo Strokov2021-06-023-6/+6
| | | | | | | | | | | Gitaly project now properly respects module release flow and includes a module suffix in the package name. It requires to re-write all non-suffixed imports with suffixed of a specific version of tha module. With proper module versioning we don't need to use a 'replace' directive to point to specific commit and can use semantic versioning for the gitaly dependency. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/3177
* Fix opentracing setup for gitlab-sshdNick Thomas2021-05-175-17/+39
| | | | | | | | | | | | | | | | | | | | Previously, opentracing (if configured) was initialized late in the gitlab-shell process's lifespan, coming just before making a gRPC call to Gitaly. By moving the opentracing initialization to be at process startup, we make it available for the whole process lifecycle, which is very useful to gitlab-sshd, as it means we'll only call tracing.Initialize() once on process startup, rather than once per SSH connection. To get this working, we need to introduce a context to gitlab-sshd. This carries the client/service name, but also carries an initial correlation ID. The main outcome of this is that all calls to the authorized_keys endpoint from a given gitlab-sshd process will now share a correlation ID. I don't have a strong opinion about this either way. Changelog: fixed
* Merge branch '501-gitaly-respect-parent-context' into 'main'Nick Thomas2021-05-109-15/+21
|\ | | | | | | | | Respect parent context for Gitaly calls See merge request gitlab-org/gitlab-shell!469
| * Respect parent context for Gitaly callsNick Thomas2021-05-059-15/+21
| | | | | | | | | | | | | | | | | | Without these changes, Gitaly calls would not be linked to a parent context. This means that they would have an unassociated correlationID, and Gitaly RPC calls would not be cancel()ed by parent context cancellation. Changelog: fixed
* | Merge branch '516-handle-ssl-cert-dir-correctly' into 'main'Nick Thomas2021-05-042-87/+60
|\ \ | | | | | | | | | | | | | | | | | | gitlab-sshd: Respect the ssl_cert_dir config Closes #516 See merge request gitlab-org/gitlab-shell!467
| * | gitlab-sshd: Respect the ssl_cert_dir config516-handle-ssl-cert-dir-correctlyNick Thomas2021-04-302-87/+60
| |/ | | | | | | Changelog: fixed
* | Don't finish the opentracing span earlydont-close-span-earlyNick Thomas2021-04-301-1/+0
|/ | | | | | | | | Calling finished() in `ContextWithCorrelationID` breaks opentracing, since it expects us to call it just before exiting, and this defer runs on function completion. All existing users of ContextWithCorrelationID already `defer finish()` themselves, so this call is entirely surplus to requirements.
* Replace cleanup functions with t.CleanupIgor Drozdov2021-03-1715-57/+32
| | | | | In this case we don't need to propagate cleanup function. It simplifies the code.
* chore: Refactor env introspection to rely on command initialization496-move-env-introspection-to-sshenvLucas Charles2021-03-1511-173/+100
| | | | | | | Refactors introspection of execution environment to rely on per-connection state (`gitlab-shell`) or per request (`gitlab-sshd`) Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/496
* Use eventually to assert log entriesJaime Martinez2021-02-221-6/+11
|
* Read limited input for yes answerIgor Drozdov2021-02-052-1/+12
|
* Remove session duration information from output of 2fa_verify command504-remove-the-session-duration-information-from-the-output-of-2fa_verify-commandManoj M J2021-01-292-2/+2
| | | | | This change removes session duration information from output of 2fa_verify command
* RFC: Simple built-in SSH serverLorenz Brun2021-01-186-13/+33
|
* Add 2fa_verify commandImre Farkas2020-12-105-0/+190
|
* Fix incorrect actor used to check permissions for SSH receive-packsh-fix-wrong-user-deploy-key-checkStan Hu2020-10-192-25/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | During a SSH receive-pack request (e.g. `git push`), gitlab-shell was incorrectly using the user returned by the `/internal/allowed` API endpoint to make an SSHReceivePack RPC call. This caused a number of problems with deploy keys with write access: 1. Keys that were generated by a blocked user would be denied the ability to write. 2. Keys that were generated by user that did not have write access to the project would also be denied. GitLab 12.4 removed the Ruby implementation of gitlab-shell in favor of the Golang implementation, and these implementations worked slightly differently. In https://gitlab.com/gitlab-org/gitlab-shell/blob/v10.1.0/lib/gitlab_shell.rb, the Ruby implementation would always use `@who` (e.g. `key-123`), but in gitlab-shell v10.2.0 the Go implementation would always use the user from the API response. Reads did not have this issue because the user/deploy key is never passed to Gitaly for additional permission checks. Writes need this information for the pre-receive to check access to protected branches, push rules, etc. Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/479
* Set SSL_CERT_DIR env var when building commandashmckenzie/set-ssl-cert-dir-env-varAsh McKenzie2020-10-192-46/+84
|
* Remove prefixing with SSL_CERT_DIRAsh McKenzie2020-10-192-28/+2
|
* tests: Replace assert with requirezj-remove-testify-assertZeger-Jan van de Weg2020-10-153-12/+9
| | | | | | | | | Testify features sub packages `assert` and `require`. The difference is subtle, and lost on novice Golang developers that don't read the docs. To create a more consistent code base `assert` will no longer be used. This change was generated by a running a sed command on all `_test.go` files, followed by `goimports -w`.
* Drop "generated random correlation ID" log messagesh-suppress-random-correlation-id-logStan Hu2020-10-131-1/+0
| | | | | | This message happens all the time and doesn't add a lot of value. Relates to https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1275
* Make it possible to propagate correlation ID across processesStan Hu2020-09-2029-77/+200
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, gitlab-shell did not pass a context through the application. Correlation IDs were generated down the call stack instead of passed around from the start execution. This has several potential downsides: 1. It's easier for programming mistakes to be made in future that lead to multiple correlation IDs being generated for a single request. 2. Correlation IDs cannot be passed in from upstream requests 3. Other advantages of context passing, such as distributed tracing is not possible. This commit changes the behavior: 1. Extract the correlation ID from the environment at the start of the application. 2. If no correlation ID exists, generate a random one. 3. Pass the correlation ID to the GitLabNet API requests. This change also enables other clients of GitLabNet (e.g. Gitaly) to pass along the correlation ID in the internal API requests (https://gitlab.com/gitlab-org/gitaly/-/issues/2725). Fixes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/474
* Add support obtaining personal access tokens via SSHTaylan Develioglu2020-08-175-6/+289
| | | | | | | | | | | | | | | | | | | | | | | | Implements the feature requested in gitlab-org/gitlab#19672 This requires the internal api counterpart in gitlab-org/gitlab!36302 to be merged first. It can be used as follows: ``` censored@censored-VirtualBox:~/git/gitlab$ ssh git@gitlab-2004 personal_access_token remote: remote: ======================================================================== remote: remote: Usage: personal_access_token <name> <scope1[,scope2,...]> [ttl_days] remote: remote: ======================================================================== remote: censored@censored-VirtualBox:~/git/gitlab$ ssh git@gitlab-2004 personal_access_token newtoken read_api,read_repository 30 Token: aAY1G3YPeemECgUvxuXY Scopes: read_api,read_repository Expires: 2020-08-07 ```
* Generate and log correlation IDsStan Hu2020-07-314-9/+4
| | | | | This will make it easier to tie an SSH access request to Rails API and Gitaly requests.
* Log SSH key detailsStan Hu2020-07-233-0/+6
| | | | | | | | | | | | | | | | | | | | | Right now when a client such as gitlab-shell calls the `/api/v4/internal/allowed` API, the response only tells the client what user has been granted access, and it's impossible to tell which deploy key/token was used in the authentication request. This commit adds logs for the following when available: 1. `gl_key_type` (e.g. `deploy_key` or `key`) 2. `gl_key_id` These fields make it possible for admins to identify the exact record that was used to authenticate the user. API changes in the `/internal/allowed` endpoint in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/37289 are needed to support this. Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/203
* Log remote IP for executed commandssh-log-remote-ipStan Hu2020-07-201-1/+6
| | | | | | | | Admins may want to know what client IP originated the request. This commit adds a `remote_ip` field to the log that extracts the IP address from the `SSH_CONNECTION` environment variable. Closes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/199
* Pass in ssl_cert_dir config settingAsh McKenzie2020-07-024-4/+36
|
* Fix race conditions with logrus testingsh-fix-logrus-raceStan Hu2020-05-112-0/+3
| | | | | | | | | logrus fires a Goroutine to write logs, so the tests could fail if they checked the event queue before the logrus have fired. Since there isn't an easy way to flush all outstanding hooks, we just retry every 100 ms for up to a second for log to arrive in the queue. Closes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/450
* Fix race conditions in testssh-add-http-status-codeStan Hu2020-05-083-14/+15
| | | | | | | | Calling logrus hook.LastEntry() can lead to race conditions. Use AllEntries instead: https://github.com/sirupsen/logrus/blob/60c74ad9be0d874af0ab0daef6ab07c5c5911f0d/hooks/test/test.go#L77 Closes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/450
* Move gitlabnet client to client packagejc-refactor-gitlabnet-clientJohn Cai2020-05-0414-14/+16
|
* Geo Pull custom action supportAsh McKenzie2020-04-174-9/+136
|
* Extract customaction into a separate moduleid-extract-custom-action-in-separate-moduleIgor Drozdov2020-04-144-45/+50
| | | | We'll reuse this module for uploadpack in the future
* Add missed protocol againsh-log-git-upload-receive-packDavid Kim2020-04-081-1/+1
|
* Remove unnecessary command argumentDavid Kim2020-04-083-3/+3
|
* Move logging to handler insteadDavid Kim2020-04-074-29/+6
|
* Change git command logging keys to be be snake casedDavid Kim2020-04-031-5/+5
|
* Add test for command loggingDavid Kim2020-04-037-38/+35
|
* Add tests for loggingDavid Kim2020-03-303-0/+24
|
* Add git-archive-packStan Hu2020-03-263-12/+23
|
* Log git-{upload-pack,receive-pack} requestsStan Hu2020-03-262-0/+24
| | | | This restores the previous Ruby gitlab-shell behavior.