Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[http] Add unix socket option #2764

Merged

Conversation

LaurenceJJones
Copy link
Contributor

@LaurenceJJones LaurenceJJones commented Jan 20, 2024

Implement #2757

Add unix socket option to http plugin, we have to use this in conjunction with URL parameter as we dont know which path the user wants so if they would like to communicate over unix socket they need to use both, however, the hostname can be whatever they want. (All communication will be over the unix socket but we dont know the path or scheme and rather not add specific arguments just for that when they can define within URL param)

Example of pushing to Gotify over unix socket (Dont worry about token as it is just a local version)

type: http
name: http_default
log_level: info

format: |
  {{ range . -}}
  {{ $alert := . -}}
  {
    "extras": {
      "client::display": {
      "contentType": "text/markdown"
    }
  },
  "priority": 3,
  "title": "test from crowdsec!",
  "message": "message!"
  }
  {{ end -}}

url: "http://_/message?token=AxHH7ZX1ttm-ZWc"
unix_socket: /opt/gotify.sock

# Any of the http verbs: "POST", "GET", "PUT"...
method: POST

headers:
  Content-Type: application/json
#   Authorization: token 0x64312313
$ sudo cscli notifications test http_default
WARN[2024-01-20T14:32:49Z] You are using sqlite without WAL, this can have a performance impact. If you do not store the database in a network share, set db_config.use_wal to true. Set explicitly to false to disable this warning.
INFO[2024-01-20T14:32:49Z] loaded capi whitelist from /etc/crowdsec/capi_whitelists.yaml: 1 IPs, 0 CIDRs
DEBU[0000] starting plugin                               args="[/usr/local/lib/crowdsec/plugins/notification-http]" path=/usr/local/lib/crowdsec/plugins/notification-http
DEBU[0000] plugin started                                path=/usr/local/lib/crowdsec/plugins/notification-http pid=61824
DEBU[0000] waiting for RPC address                       path=/usr/local/lib/crowdsec/plugins/notification-http
DEBU[0000] using plugin                                  version=1
TRAC[0000] waiting for stdio data
INFO[0000] Using socket '/opt/gotify.sock'               @module=http-plugin
INFO[2024-01-20T14:32:49Z] registered plugin http_default
INFO[2024-01-20T14:32:49Z] pluginTomb dying
INFO[0000] received signal for http_default config       @module=http-plugin
INFO[2024-01-20T14:32:49Z] killing all plugins
DEBU[0000] received EOF, stopping recv loop              err="rpc error: code = Unavailable desc = error reading from server: EOF"
INFO[0000] plugin process exited                         path=/usr/local/lib/crowdsec/plugins/notification-http pid=61824
DEBU[0000] plugin exited

image

…tion with URL parameter as we dont know which path the user wants so if they would like to communicate over unix socket they need to use both, however, the hostname can be whatever they want. We could be a little smarter and actually parse the url, however, increasing code when a user can just define it correctly make no sense
Copy link

@LaurenceJJones: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind fix
  • /kind chore
  • /kind dependencies
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

Copy link

@LaurenceJJones: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

Copy link

codecov bot commented Jan 20, 2024

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (3e3df5e) 57.93% compared to head (d4e5f6e) 57.93%.

Files Patch % Lines
cmd/notification-http/main.go 0.00% 21 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2764   +/-   ##
=======================================
  Coverage   57.93%   57.93%           
=======================================
  Files         239      239           
  Lines       30983    30988    +5     
=======================================
+ Hits        17950    17953    +3     
- Misses      11399    11403    +4     
+ Partials     1634     1632    -2     
Flag Coverage Δ
bats 37.86% <0.00%> (+0.01%) ⬆️
unit-linux 52.29% <ø> (+0.01%) ⬆️
unit-windows 47.76% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LaurenceJJones
Copy link
Contributor Author

/kind enhancement
/area agent

@mmetc mmetc self-assigned this Feb 1, 2024
@LaurenceJJones LaurenceJJones added this to the 1.6.1 milestone Feb 2, 2024
@LaurenceJJones
Copy link
Contributor Author

Did you manage to test and review @mmetc

@mmetc mmetc self-requested a review February 15, 2024 09:06
@LaurenceJJones LaurenceJJones merged commit 0df8f54 into crowdsecurity:master Feb 22, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/agent kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants