Commit graph

149 commits

Author SHA1 Message Date
Ian Roberts
98cf5d0163
Add support for systemd socket activation (#704)
* feat: add support for systemd socket activation

If webhook has been launched via systemd socket activation, simply use the systemd-provided socket rather than opening our own.

* docs: documentation for the systemd socket activation mode

* refactor: moved setuid and setgid flags into platform-specific section

The setuid and setgid flags do not work on Windows, so moved them to platform_unix so they are only added to the flag set on compatible platforms.

Also disallow the use of setuid and setgid in combination with -socket, since a setuid webhook process would not be able to clean up a socket that was created while running as root.  If you _need_ to have the socket owned by root but the webhook process running as a normal user, you can achieve the same effect with systemd socket activation.
2024-10-25 23:18:04 +02:00
Ian Roberts
eddeb82032
Add option to bind to a Unix socket instead of a TCP port (#703)
* feat: add ability to listen on unix socket/named pipe

Add a -socket option that configures the server to listen on a Unix-domain socket or Windows named pipe instead of a TCP port.  This allows webhook to be used behind a reverse proxy on multi-tenant shared hosting without the need to choose (and the permission to bind to) a free port number.

On Windows, -socket is expected to be a named pipe such as \\.\pipe\webhook, and the code uses https://github.com/microsoft/go-winio to bind the listening socket.  On other platforms, -socket is the path to a Unix domain socket such as /tmp/webhook.sock, or an abstract socket name starting with @, bound using the regular net.Listen function with the "network" parameter set to "unix".

Note: this pushes our minimum Go version up to 1.21 as that is what go-winio requires, but that is already the minimum version against which we are testing in the CI matrix.

* tests: add test for the -socket option

Refactored webhook_test so that the test HTTP requests are made using an explicitly-provided http.Client, so we can run at least one test with the server bound to a socket instead of a port number, using an http.Client whose transport has been configured with a suitable Unix-domain or Windows named pipe dialer function.

* tests: use GOROOT to find go command

This should ensure that, even if a developer or CI server has multiple versions of go installed, the version used to build the tools under test will be the same version that is running the test harness.

* fix: clean up Unix socket file before exit

If webhook is restarted with the same settings but the socket file has not been deleted, webhook will be unable to bind and will exit with an error.

* docs: add -socket option to documentation

* docs: add a note about reverse proxies

- README mentions the idea of using webhook behind a reverse proxy, including with the -socket flag
- added a note in Hook-Rules that the ip-whitelist rule type does not work as expected behind a reverse proxy, and you should configure IP restrictions at the proxy level instead
2024-10-25 09:38:22 +02:00
Adnan Hajdarevic
48c76cf80d Bump version 2024-04-13 23:27:55 +02:00
Cameron Moore
0fa8bbf710
Update GH actions and dependencies (#681)
* Update go-chi dependency to v5

* Update gofrs/uuid dependency to v5

* Update gorilla/mux dependency to v1.8.1

* Update go-humanize dependency to v1.0.1

* Update mxj dependency to v2.7.0

* Update fsnotify dependency to v1.7.0

* Update Go versions in GH build workflow

* Update gopkg.in/yaml.v2 indirect dependency to v2.4.0

* Bump GH actions
2024-04-13 12:27:49 +02:00
Adnan Hajdarevic
f187592147 Bump version to 2.8.1 2023-05-22 21:03:40 +02:00
Cameron Moore
3285288f03
Send cli headers on default http handler
Fixes #553
2021-09-02 19:24:34 -05:00
Adnan Hajdarevic
159cb4a911 bump version to 2.8.0 2020-12-06 08:42:09 +01:00
Adnan Hajdarević
b6e5b11174
Merge pull request #485 from moorereason/iss234-soft-sig-errors
Add soft signature failure support
2020-12-06 08:39:31 +01:00
Cameron Moore
6d2f26d952 Add soft signature failure support
Add a new trigger-signature-soft-failures option to allow soft signature
failures in Or rules.

Fixes #234
2020-11-24 21:16:57 -06:00
Cameron Moore
c2ffd465c4 Add support for slashes in hook IDs
When matching variables in routes, gorilla/mux uses a default pattern of
"[^/]+", thereby prohibiting slashes in variable matching.  Override the
default pattern to remove this restriction.

See https://github.com/gorilla/mux/blob/v1.8.0/regexp.go#L50

Fixes #421
2020-11-24 16:56:54 -06:00
Cameron Moore
22c8a1670b Move some request parsing into hook package
Trying to simplify hookHandler.  No functional changes introduced.
2020-11-17 15:00:58 -06:00
Cameron Moore
c6603894c1 Add Request object to hook package to simplify API
To avoid having to pass around so many parameters to the hook package,
create a Request object to store all request-specific data.  Update APIs
accordingly.
2020-09-25 19:46:06 -05:00
Cameron Moore
dd5fa20415 Log stdlib error on failed exec.LookPath
The error returned by exec.LookPath was never surfaced to the user.
Without that detail, the user can't tell the difference between a
non-existent path and a permissions issue.

Additionally, when ExecuteCommand is an absolute path, we were still
attempting to prepend the CommandWorkingDirectory if the ExecuteCommand
was not found, which made it difficult to know which path the user
intended to execute.

This commit simplifies the logic to avoid multiple attempts with
ExecuteCommand is an absolute path and changes the error message from:

  error locating command: '/path/to/file'

to:

  error in exec: "/path/to/file": stat /path/to/file: no such file or directory
  error in exec: "/path/to/file": permission denied

Fixes #457
2020-09-24 21:02:07 -05:00
Cameron Moore
0e90ccb441 Add support for top-level JSON array in payload
Detect if leading character in JSON payload is an array bracket.  If
found, decode payload into an interface{} and then save the results into
payload["root"].  References to payload values would need to reference
the leading, "virtual" root node (i.e. "root.0.name").

Fixes #215
2020-07-29 16:56:25 -05:00
Adnan Hajdarevic
e6e324235d Bump version to v2.7.0 2020-05-12 19:14:25 +02:00
Cameron Moore
4407c0190b Add request ID logging on missing command 2020-04-24 15:32:33 -05:00
Adnan Hajdarević
38294cd0c6
Merge pull request #383 from moorereason/feature/pidfile
Add pidfile support
2020-02-14 19:35:18 +01:00
Cameron Moore
7fa3a8900c Show failed parameter node lookups
When attempting to match a JSON path for initial setup, it would be
helpful to know where the path failed. This change logs the failed
parameter node. For example, if you are trying to match path "a.b.d.e",
but you failed to include the "c" node, webhook will log an error
"parameter node not found: d.e" to assist in troubleshooting.
2019-12-30 21:51:11 -06:00
Cameron Moore
876c853073 Add pidfile support
Copy a simple implementation from the Moby project, since importing
their package would pull in too many dependencies.

Fixes #320
2019-12-29 18:00:55 -06:00
Adnan Hajdarević
569921cd72
Merge pull request #381 from moorereason/feature/logfile
Feature/logfile
2019-12-29 20:10:16 +01:00
Cameron Moore
fda328dc23 Refactor fatal logging during service startup
Create a log queue to postpone the first log write until after
privilege dropping and log file opening.
2019-12-28 20:50:33 -06:00
Cameron Moore
811481298a Fix method not allowed log message 2019-12-28 07:09:36 -06:00
Cameron Moore
5af6e4d1ec Open listener port earlier 2019-12-27 12:01:12 -06:00
Cameron Moore
725fda68dc Add logfile feature 2019-12-27 11:51:44 -06:00
Cameron Moore
157f468e0c Refactor cli HTTP methods behavior
The CLI HTTP methods option now sets the default allowed methods while
allowing an individual hook definition to override the default.
2019-12-27 11:22:04 -06:00
Cameron Moore
e1249a9ddb Add global HTTP methods to starting log message 2019-12-26 15:17:01 -06:00
Cameron Moore
a03e812615 Update HTTP methods to sanitize user input 2019-12-26 14:54:27 -06:00
Cameron Moore
c38778ba62 Add HTTP methods cli parameter
Allows to globally restrict HTTP methods.

Fixes #248
2019-12-26 14:54:27 -06:00
Cameron Moore
3414f34025 Add per-hook HTTP method restrictions 2019-12-26 14:54:01 -06:00
Cameron Moore
77159d9db6 Add setuid & setgid options
Only applicable on unix systems, although Go doesn't support Linux at
this time.
2019-12-26 10:30:31 -06:00
Cameron Moore
35d1cedc24 Rewrite server to use explicit listener 2019-12-26 10:29:14 -06:00
Cameron Moore
1c779a0d75 Update multipart form data logic
All form values are simply added to the payload map without processing.
JSON parsing of values happens later.
2019-12-25 09:08:23 -06:00
Cameron Moore
93632d077c Add multipart form data support 2019-12-25 09:05:15 -06:00
Cameron Moore
779ff0ad10 Fix XML error message 2019-12-24 19:47:21 -06:00
Cameron Moore
3463804a7c Add XML payload support
Fixes #238
2019-12-24 15:58:49 -06:00
Cameron Moore
be815d0a41 Use gorilla/mux for middleware and extend
- Use gorilla/mux for middleware.
- Add Dumper, RequestID, and Logger middlewares.
- Add makeURL helper
2019-12-24 11:57:26 -06:00
Cameron Moore
40d9dcd6d4 Make hook package internal
The hook package API is not meant for public consumption.
2019-12-21 11:55:42 -06:00
Cameron Moore
8ff3848ea3 Use gofrs/uuid instead of satori/go.uuid
The satori package appears to be unmaintained.  The gofrs package is a
fork that is actively maintained by a larger group of Go developers.
2019-12-18 21:17:13 -06:00
Adnan Hajdarevic
8fe6c9a05d Update version to 2.6.11 2019-12-15 14:30:54 +01:00
Cameron Moore
f1003560f1 Add list cipher suites support 2019-12-03 21:35:16 -06:00
Cameron Moore
43f519a712 Add TLS version and cipher suites options
Default to TLS 1.2 and secure cipher suites.

Built for Go 1.13. Code in cipher_suites.go taken from Go tip commit
0ee22d9, which is scheduled for the upcoming Go 1.14 release.  Once Go
1.14 is released, we can remove this file and use the stdlib.

Fixes #244
2019-12-03 15:13:12 -06:00
Adnan Hajdarevic
ce186487f4 Format the file using go fmt. 2019-12-02 19:03:38 +01:00
Adnan Hajdarevic
a99abd4e6f Fix invalid assumption in code that multipart forms can be parsed in the same way as urlencoded forms.
Refactored code to use switch-case statement over the `Content-Type` header and log unsupported content types instead of silently failing.
Also made the `x-www-form-urlencoded` content type handler more specific (as opposed to the previous code which looked for `form` occurence in the value),
as we need to use different logic for multipart forms, which we'll hopefully implement soon.

The issue with multipart forms that we have to handle first is that the files are being written to temporary files, and as such, for async hooks
webhook cannot guarantee they'll be available after we close the request; that, and the fact that we don't have code that will properly serialize
and pass such Golang objects to the script, as there are several fields which might be interesting to the end user.
2019-12-02 18:49:24 +01:00
Adnan Hajdarevic
34ae132930 Bump webhook version to 2.6.10 2019-09-24 19:45:40 +02:00
Adnan Hajdarević
002c332b68
Merge pull request #327 from dexpota/master
Fix issue with relative paths and command execution
2019-09-18 18:07:07 +02:00
Fabrizio Destro
d3fd9bddd9 Fix issue with relative paths and command execution 2019-08-25 20:08:39 +02:00
Christiaan Kras
c6939d57dc Replaced fmt.Frpintf calls with fmt.Fprint when there's no formatting used
This fixes #313
2019-04-24 14:59:38 +02:00
Adnan Hajdarević
e86c2cf610
Merge branch 'development' into development 2019-04-17 18:11:12 +02:00
Adnan Hajdarevic
f76426e9b0 add handler for the route to be used as a healtcheck endpoint, fixes #233 2018-11-17 19:01:26 +01:00
Adnan Hajdarevic
fc0544e4a2 Bump version to 2.6.9 2018-11-13 21:01:42 +01:00