Skip to content

Commit 3ad624f

Browse files
committed
Merge branch 'master' into releases/1.6.x
2 parents bc27449 + 5fe038d commit 3ad624f

File tree

26 files changed

+354
-216
lines changed

26 files changed

+354
-216
lines changed

.github/release-drafter.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ categories:
2323
- 'kind/dependencies'
2424
- 'kind/chore'
2525
tag-template: "- $TITLE @$AUTHOR (#$NUMBER)"
26+
exclude-labels:
27+
- 'skip-changelog'
2628
template: |
2729
## Changes
2830
@@ -31,8 +33,8 @@ template: |
3133
## Geolite2 notice
3234
3335
This product includes GeoLite2 data created by MaxMind, available from <a href="https://www.maxmind.com">https://www.maxmind.com</a>.
34-
36+
3537
## Installation
3638
3739
Take a look at the [installation instructions](https://doc.crowdsec.net/docs/getting_started/install_crowdsec).
38-
40+

.github/workflows/ci_release-drafter.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ on:
44
push:
55
# branches to consider in the event; optional, defaults to all
66
branches:
7+
- main
78
- master
89
- releases/**
910

11+
permissions:
12+
contents: read
13+
1014
jobs:
1115
update_release_draft:
16+
permissions:
17+
contents: write
18+
pull-requests: read
1219
runs-on: ubuntu-latest
1320
steps:
1421
# Drafts your next Release notes as Pull Requests are merged into "master"
1522
- uses: release-drafter/release-drafter@v6
1623
with:
17-
config-name: release-drafter.yml
1824
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
19-
# config-name: my-config.yml
25+
config-name: release-drafter.yml
2026
env:
2127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ check_golangci-lint:
317317
ifeq ($(OS),Windows_NT)
318318
@where golangci-lint >nul || (echo "Error: golangci-lint is not installed. Install it from https://github.com/golangci/golangci-lint" && exit 1)
319319
else
320-
@command -v galangci-lint > /dev/null 2>&1 || (echo "Error: golangci-lint is not installed. Install it from https://github.com/golangci/golangci-lint" && exit 1)
320+
@command -v golangci-lint > /dev/null 2>&1 || (echo "Error: golangci-lint is not installed. Install it from https://github.com/golangci/golangci-lint" && exit 1)
321321
endif
322322

323323
.PHONY: lint

cmd/crowdsec-cli/clicapi/capi.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
2222
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
2323
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
24+
"github.com/crowdsecurity/crowdsec/pkg/database"
2425
"github.com/crowdsecurity/crowdsec/pkg/models"
2526
"github.com/crowdsecurity/crowdsec/pkg/types"
2627
)
@@ -120,7 +121,7 @@ func (cli *cliCapi) register(ctx context.Context, capiUserPrefix string, outputF
120121

121122
log.Infof("Central API credentials written to '%s'", dumpFile)
122123
} else {
123-
fmt.Println(string(apiConfigDump))
124+
fmt.Fprintln(os.Stdout, string(apiConfigDump))
124125
}
125126

126127
if msg := reload.UserMessage(); msg != "" {
@@ -154,8 +155,8 @@ func (cli *cliCapi) newRegisterCmd() *cobra.Command {
154155
return cmd
155156
}
156157

157-
// queryCAPIStatus checks if the Central API is reachable, and if the credentials are correct. It then checks if the instance is enrolle in the console.
158-
func queryCAPIStatus(ctx context.Context, hub *cwhub.Hub, credURL string, login string, password string) (bool, bool, error) {
158+
// queryCAPIStatus checks if the Central API is reachable, and if the credentials are correct. It then checks if the instance is enrolled in the console.
159+
func queryCAPIStatus(ctx context.Context, db *database.Client, hub *cwhub.Hub, credURL string, login string, password string) (bool, bool, error) {
159160
apiURL, err := url.Parse(credURL)
160161
if err != nil {
161162
return false, false, err
@@ -172,7 +173,6 @@ func queryCAPIStatus(ctx context.Context, hub *cwhub.Hub, credURL string, login
172173
client, err := apiclient.NewClient(&apiclient.Config{
173174
MachineID: login,
174175
Password: passwd,
175-
Scenarios: itemsForAPI,
176176
URL: apiURL,
177177
// I don't believe papi is neede to check enrollement
178178
// PapiURL: papiURL,
@@ -198,6 +198,10 @@ func queryCAPIStatus(ctx context.Context, hub *cwhub.Hub, credURL string, login
198198
return false, false, err
199199
}
200200

201+
if err := db.SaveAPICToken(ctx, apiclient.TokenDBField, authResp.Token); err != nil {
202+
return false, false, err
203+
}
204+
201205
client.GetClient().Transport.(*apiclient.JWTTransport).Token = authResp.Token
202206

203207
if client.IsEnrolled() {
@@ -207,7 +211,7 @@ func queryCAPIStatus(ctx context.Context, hub *cwhub.Hub, credURL string, login
207211
return true, false, nil
208212
}
209213

210-
func (cli *cliCapi) Status(ctx context.Context, out io.Writer, hub *cwhub.Hub) error {
214+
func (cli *cliCapi) Status(ctx context.Context, db *database.Client, out io.Writer, hub *cwhub.Hub) error {
211215
cfg := cli.cfg()
212216

213217
if err := require.CAPIRegistered(cfg); err != nil {
@@ -219,7 +223,7 @@ func (cli *cliCapi) Status(ctx context.Context, out io.Writer, hub *cwhub.Hub) e
219223
fmt.Fprintf(out, "Loaded credentials from %s\n", cfg.API.Server.OnlineClient.CredentialsFilePath)
220224
fmt.Fprintf(out, "Trying to authenticate with username %s on %s\n", cred.Login, cred.URL)
221225

222-
auth, enrolled, err := queryCAPIStatus(ctx, hub, cred.URL, cred.Login, cred.Password)
226+
auth, enrolled, err := queryCAPIStatus(ctx, db, hub, cred.URL, cred.Login, cred.Password)
223227
if err != nil {
224228
return fmt.Errorf("failed to authenticate to Central API (CAPI): %w", err)
225229
}
@@ -263,12 +267,20 @@ func (cli *cliCapi) newStatusCmd() *cobra.Command {
263267
Args: args.NoArgs,
264268
DisableAutoGenTag: true,
265269
RunE: func(cmd *cobra.Command, _ []string) error {
266-
hub, err := require.Hub(cli.cfg(), nil)
270+
cfg := cli.cfg()
271+
ctx := cmd.Context()
272+
273+
hub, err := require.Hub(cfg, nil)
274+
if err != nil {
275+
return err
276+
}
277+
278+
db, err := require.DBClient(ctx, cfg.DbConfig)
267279
if err != nil {
268280
return err
269281
}
270282

271-
return cli.Status(cmd.Context(), color.Output, hub)
283+
return cli.Status(ctx, db, color.Output, hub)
272284
},
273285
}
274286

cmd/crowdsec-cli/cliconsole/console.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"net/http"
1010
"net/url"
1111
"os"
12-
"strconv"
1312
"slices"
13+
"strconv"
1414
"strings"
1515

1616
"github.com/fatih/color"
@@ -85,9 +85,11 @@ func (cli *cliConsole) enroll(ctx context.Context, key string, name string, over
8585
c, _ := apiclient.NewClient(&apiclient.Config{
8686
MachineID: cli.cfg().API.Server.OnlineClient.Credentials.Login,
8787
Password: password,
88-
Scenarios: hub.GetInstalledListForAPI(),
8988
URL: apiURL,
9089
VersionPrefix: "v3",
90+
UpdateScenario: func(_ context.Context) ([]string, error) {
91+
return hub.GetInstalledListForAPI(), nil
92+
},
9193
})
9294

9395
resp, err := c.Auth.EnrollWatcher(ctx, key, name, tags, overwrite)
@@ -157,12 +159,14 @@ func optionFilterDisable(opts []string, disableOpts []string) ([]string, error)
157159
// discard all elements == opt
158160

159161
j := 0
162+
160163
for _, o := range opts {
161164
if o != opt {
162165
opts[j] = o
163166
j++
164167
}
165168
}
169+
166170
opts = opts[:j]
167171
}
168172

@@ -323,7 +327,7 @@ func (cli *cliConsole) newStatusCmd() *cobra.Command {
323327
if err != nil {
324328
return fmt.Errorf("failed to serialize configuration: %w", err)
325329
}
326-
fmt.Println(string(data))
330+
fmt.Fprintln(os.Stdout, string(data))
327331
case "raw":
328332
csvwriter := csv.NewWriter(os.Stdout)
329333
err := csvwriter.Write([]string{"option", "enabled"})

cmd/crowdsec-cli/climetrics/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (cli *cliMetrics) NewCommand() *cobra.Command {
2828
Use: "metrics",
2929
Short: "Display crowdsec prometheus metrics.",
3030
Long: `Fetch metrics from a Local API server and display them`,
31-
Example: `# Show all Metrics, skip empty tables (same as "cecli metrics show")
31+
Example: `# Show all Metrics, skip empty tables (same as "cscli metrics show")
3232
cscli metrics
3333
3434
# Show only some metrics, connect to a different url

cmd/crowdsec-cli/clisupport/support.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ func (cli *cliSupport) dumpLAPIStatus(ctx context.Context, zw *zip.Writer, hub *
256256
return nil
257257
}
258258

259-
func (cli *cliSupport) dumpCAPIStatus(ctx context.Context, zw *zip.Writer, hub *cwhub.Hub) error {
259+
func (cli *cliSupport) dumpCAPIStatus(ctx context.Context, zw *zip.Writer, hub *cwhub.Hub, db *database.Client) error {
260260
log.Info("Collecting CAPI status")
261261

262262
out := new(bytes.Buffer)
263263
cc := clicapi.New(cli.cfg)
264264

265-
err := cc.Status(ctx, out, hub)
265+
err := cc.Status(ctx, db, out, hub)
266266
if err != nil {
267267
fmt.Fprintf(out, "%s\n", err)
268268
}
@@ -534,7 +534,7 @@ func (cli *cliSupport) dump(ctx context.Context, outFile string) error {
534534
}
535535

536536
if !skipCAPI {
537-
if err = cli.dumpCAPIStatus(ctx, zipWriter, hub); err != nil {
537+
if err = cli.dumpCAPIStatus(ctx, zipWriter, hub, db); err != nil {
538538
log.Warnf("could not collect CAPI status: %s", err)
539539
}
540540

cmd/crowdsec/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func initAPIServer(ctx context.Context, cConfig *csconfig.Config) (*apiserver.AP
3838

3939
err = pluginBroker.Init(ctx, cConfig.PluginConfig, cConfig.API.Server.Profiles, cConfig.ConfigPaths)
4040
if err != nil {
41-
return nil, fmt.Errorf("unable to run plugin broker: %w", err)
41+
return nil, fmt.Errorf("plugin broker: %w", err)
4242
}
4343

4444
log.Info("initiated plugin broker")

cmd/crowdsec/lapiclient.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

pkg/acquisition/modules/kafka/kafka.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ var linesRead = prometheus.NewCounterVec(
3333
[]string{"topic"})
3434

3535
type KafkaConfiguration struct {
36-
Brokers []string `yaml:"brokers"`
37-
Topic string `yaml:"topic"`
38-
GroupID string `yaml:"group_id"`
39-
Partition int `yaml:"partition"`
40-
Timeout string `yaml:"timeout"`
41-
TLS *TLSConfig `yaml:"tls"`
36+
Brokers []string `yaml:"brokers"`
37+
Topic string `yaml:"topic"`
38+
GroupID string `yaml:"group_id"`
39+
Partition int `yaml:"partition"`
40+
Timeout string `yaml:"timeout"`
41+
TLS *TLSConfig `yaml:"tls"`
42+
BatchConfiguration KafkaBatchConfiguration `yaml:"batch"`
4243
configuration.DataSourceCommonCfg `yaml:",inline"`
4344
}
4445

@@ -49,6 +50,14 @@ type TLSConfig struct {
4950
CaCert string `yaml:"ca_cert"`
5051
}
5152

53+
type KafkaBatchConfiguration struct {
54+
BatchMinBytes int `yaml:"min_bytes"`
55+
BatchMaxBytes int `yaml:"max_bytes"`
56+
BatchMaxWait time.Duration `yaml:"max_wait"`
57+
BatchQueueSize int `yaml:"queue_size"`
58+
CommitInterval time.Duration `yaml:"commit_interval"`
59+
}
60+
5261
type KafkaSource struct {
5362
metricsLevel int
5463
Config KafkaConfiguration
@@ -294,6 +303,22 @@ func (kc *KafkaConfiguration) NewReader(dialer *kafka.Dialer, logger *log.Entry)
294303
logger.Warnf("no group_id specified, crowdsec will only read from the 1st partition of the topic")
295304
}
296305

306+
if kc.BatchConfiguration.BatchMinBytes != 0 {
307+
rConf.MinBytes = kc.BatchConfiguration.BatchMinBytes
308+
}
309+
if kc.BatchConfiguration.BatchMaxBytes != 0 {
310+
rConf.MaxBytes = kc.BatchConfiguration.BatchMaxBytes
311+
}
312+
if kc.BatchConfiguration.BatchMaxWait != 0 {
313+
rConf.MaxWait = kc.BatchConfiguration.BatchMaxWait
314+
}
315+
if kc.BatchConfiguration.BatchQueueSize != 0 {
316+
rConf.QueueCapacity = kc.BatchConfiguration.BatchQueueSize
317+
}
318+
if kc.BatchConfiguration.CommitInterval != 0 {
319+
rConf.CommitInterval = kc.BatchConfiguration.CommitInterval
320+
}
321+
297322
if err := rConf.Validate(); err != nil {
298323
return &kafka.Reader{}, fmt.Errorf("while validating reader configuration: %w", err)
299324
}

0 commit comments

Comments
 (0)