Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
81c207a
initial commit
sabban Nov 21, 2025
eaab200
initial commit
sabban Nov 21, 2025
d69e426
first commit for kubernetes acquisition
sabban Jan 22, 2026
ba0fb67
Merge branch 'k8s/acquisition' of github.com:crowdsecurity/crowdsec i…
sabban Jan 22, 2026
9f1234d
Merge branch 'master' into k8s/acquisition
sabban Jan 22, 2026
d1bdf53
clean up
sabban Jan 22, 2026
fdf7550
Merge branch 'k8s/acquisition' of github.com:crowdsecurity/crowdsec i…
sabban Jan 22, 2026
e829498
rename the prod branch to main
sabban Jan 30, 2026
0935531
Merge branch 'master' of github.com:crowdsecurity/crowdsec
sabban Jan 30, 2026
4beb0ab
Merge branch 'master' of github.com:crowdsecurity/crowdsec
sabban Jan 30, 2026
b615f70
remove unused file
sabban Feb 1, 2026
02d5dd0
update
sabban Feb 1, 2026
0059628
don't flush local machines
sabban Feb 2, 2026
478ef4d
Merge branch 'master' into k8s/acquisition
sabban Feb 4, 2026
9e83636
Merge branch 'master' into k8s/acquisition
sabban Feb 6, 2026
d33e2ac
naming update
sabban Feb 6, 2026
2cf2776
Merge branch 'k8s/acquisition' of github.com:crowdsecurity/crowdsec i…
sabban Feb 6, 2026
b205135
clean up
sabban Feb 6, 2026
ae4d983
clean up
sabban Feb 9, 2026
bd8f759
cleanup
sabban Feb 9, 2026
1467445
typo
sabban Feb 9, 2026
7edf1e3
clean up
sabban Feb 9, 2026
c1285f9
remove unused .keep file
sabban Feb 9, 2026
28b59dc
add import of the new datasource
sabban Feb 9, 2026
a1a5a8e
change module name
sabban Feb 9, 2026
19eca66
clean up, naming
sabban Feb 10, 2026
5317e70
cleanup
sabban Feb 10, 2026
0c940f5
more lint cleanup
sabban Feb 10, 2026
133f6b7
hop
sabban Feb 10, 2026
2874a91
no one shot
sabban Feb 10, 2026
e5bd9b4
update schema path and content
sabban Feb 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ require (
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/apiserver v0.28.4
k8s.io/client-go v0.28.4
modernc.org/sqlite v1.42.2
)

Expand Down Expand Up @@ -134,6 +137,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.8.4 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gin-contrib/sse v1.0.0 // indirect
Expand All @@ -153,6 +157,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.5 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gotnospirit/makeplural v0.0.0-20180622080156-a5f48d94d976 // indirect
Expand Down Expand Up @@ -236,22 +241,23 @@ require (
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/arch v0.15.0 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/term v0.35.0 // indirect
golang.org/x/tools v0.37.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/apimachinery v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
modernc.org/libc v1.66.10 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
rsc.io/binaryregexp v0.2.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace golang.org/x/time => github.com/crowdsecurity/time v0.13.0-crowdsec.20250912
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw=
github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE=
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/expr-lang/expr v1.17.7 h1:Q0xY/e/2aCIp8g9s/LGvMDCC5PxYlvHgDZRQ4y16JX8=
github.com/expr-lang/expr v1.17.7/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down Expand Up @@ -243,6 +245,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -688,6 +692,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -811,8 +817,12 @@ k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8=
k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg=
k8s.io/apiserver v0.28.4 h1:BJXlaQbAU/RXYX2lRz+E1oPe3G3TKlozMMCZWu5GMgg=
k8s.io/apiserver v0.28.4/go.mod h1:Idq71oXugKZoVGUUL2wgBCTHbUR+FYTWa4rq9j4n23w=
k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY=
k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
modernc.org/cc/v4 v4.26.5 h1:xM3bX7Mve6G8K8b+T11ReenJOT+BmVqQj0FY5T4+5Y4=
Expand Down
4 changes: 1 addition & 3 deletions pkg/acquisition/modules/journalctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Configuration struct {
configuration.DataSourceCommonCfg `yaml:",inline"`

Filters []string `yaml:"journalctl_filter"`
since string // set only by DSN
since string // set only by DSN
}

func ConfigurationFromYAML(y []byte) (Configuration, error) {
Expand Down Expand Up @@ -70,9 +70,7 @@ func (s *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Ent
}

s.setLogger(logger, 0, s.src)

s.metricsLevel = metricsLevel

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/acquisition/modules/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !no_datasource_kubernetes

package modules

import _ "github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/kubernetes" // register the datasource
84 changes: 84 additions & 0 deletions pkg/acquisition/modules/kubernetes/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package kubernetes

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"

yaml "github.com/goccy/go-yaml"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd/api"

"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
"github.com/crowdsecurity/crowdsec/pkg/metrics"
)

type Configuration struct {
configuration.DataSourceCommonCfg `yaml:",inline"`

Selector string `yaml:"selector"`
Namespace string `yaml:"namespace"`
Auth *Auth `yaml:"auth,omitempty"`
KubeConfigFile string `yaml:"kube_config,omitempty"`
}

type Auth struct {
Cluster api.Cluster `yaml:"cluster,omitempty"`
User api.AuthInfo `yaml:"user,omitempty"`
}

func (s *Source) UnmarshalConfig(yamlConfig []byte) error {
s.Config = Configuration{
Selector: "",
Namespace: "default",
}

if err := yaml.UnmarshalWithOptions(yamlConfig, &s.Config, yaml.Strict()); err != nil {
return fmt.Errorf("while parsing KubernetesAcquisition configuration: %s", yaml.FormatError(err, false, false))
}

if s.logger != nil {
s.logger.Tracef("Kubernetes configuration: %+v", s.Config)
}

return nil
}

func (s *Source) Configure(ctx context.Context, yamlConfig []byte, logger *log.Entry, metricsLevel metrics.AcquisitionMetricsLevel) error {
s.logger = logger
s.metricsLevel = metricsLevel

err := s.UnmarshalConfig(yamlConfig)
if err != nil {
return err
}

return nil
}

func (c *Configuration) SetDefaults() {
if c.Namespace == "" {
c.Namespace = "default"
}

if c.Mode == "" {
c.Mode = configuration.TAIL_MODE
}
if c.Auth == nil && c.KubeConfigFile == "" {
home, _ := os.UserHomeDir()
c.KubeConfigFile = filepath.Join(home, ".kube", "config")
}
}

func (s *Source) Validate() error {
if s.Config.Selector == "" {
return errors.New("label must be set in kubernetes acquisition")
}
if s.Config.Auth != nil && s.Config.KubeConfigFile != "" {
return errors.New("cannot use both auth and kube_config options")

}
return nil
}
20 changes: 20 additions & 0 deletions pkg/acquisition/modules/kubernetes/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kubernetes

import (
"github.com/crowdsecurity/crowdsec/pkg/acquisition/registry"
"github.com/crowdsecurity/crowdsec/pkg/acquisition/types"
)

var (
// verify interface compliance
_ types.DataSource = (*Source)(nil)
_ types.Tailer = (*Source)(nil)
_ types.MetricsProvider = (*Source)(nil)
)

const ModuleName = "kubernetes"

//nolint:gochecknoinits
func init() {
registry.RegisterFactory(ModuleName, func() types.DataSource { return &Source{} })
}
19 changes: 19 additions & 0 deletions pkg/acquisition/modules/kubernetes/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kubernetes

import (
"github.com/prometheus/client_golang/prometheus"

"github.com/crowdsecurity/crowdsec/pkg/metrics"
)

func (*Source) GetMetrics() []prometheus.Collector {
return []prometheus.Collector{
metrics.KubernetesDataSourceLinesRead,
}
}

func (*Source) GetAggregMetrics() []prometheus.Collector {
return []prometheus.Collector{
metrics.KubernetesDataSourceLinesRead,
}
}
Loading
Loading