Skip to content

Commit 6e7fc85

Browse files
authored
docker datasource schema (#4206)
* docker datasource schema * wip datasource schema * clarify deprecation
1 parent b77ad89 commit 6e7fc85

File tree

3 files changed

+203
-2
lines changed

3 files changed

+203
-2
lines changed

pkg/acquisition/modules/docker/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (d *Source) UnmarshalConfig(yamlConfig []byte) error {
7878
}
7979

8080
if d.Config.CheckInterval != "" && d.logger != nil {
81-
d.logger.Warn("check_interval is deprecated, it will be removed in a future version")
81+
d.logger.Warn("check_interval is ignored: this datasource now uses events instead of polling (will be removed in a future version)")
8282
}
8383

8484
if d.Config.Mode == "" {
@@ -210,7 +210,6 @@ func (d *Source) ConfigureByDSN(_ context.Context, dsn string, labels map[string
210210
d.Config = Configuration{
211211
FollowStdout: true,
212212
FollowStdErr: true,
213-
CheckInterval: "1s",
214213
}
215214
d.Config.UniqueId = uuid
216215
d.Config.ContainerName = make([]string, 0)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$schema: https://json-schema.org/draft/2020-12/schema
2+
title: CrowdSec Docker datasource
3+
description: >
4+
Schema for acquisition entries consumed by CrowdSec. Every field
5+
mirrors the configuration of at least one acquisition module and the embedded
6+
configuration DataSourceCommonCfg.
7+
anyOf:
8+
- $ref: docker.yaml
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
$schema: https://json-schema.org/draft/2020-12/schema
2+
title: CrowdSec Docker datasource
3+
description: >
4+
Schema for docker acquisition entries consumed by CrowdSec. Every field
5+
mirrors pkg/acquisition/modules/docker.DockerConfiguration and the embedded
6+
configuration.DataSourceCommonCfg.
7+
type: object
8+
additionalProperties: false
9+
properties:
10+
source:
11+
type: string
12+
const: docker
13+
description: >
14+
Must be docker to bind this acquisition entry to the Docker datasource.
15+
mode:
16+
type: string
17+
enum: [tail, cat]
18+
default: tail
19+
description: >
20+
Acquisition mode (tail streams logs, cat performs a finite read).
21+
labels:
22+
type: object
23+
minProperties: 1
24+
description: >
25+
Labels attached to emitted events (for example type: nginx).
26+
additionalProperties:
27+
type: string
28+
properties:
29+
type:
30+
type: string
31+
description: Parser/collection selector; strongly recommended.
32+
log_level:
33+
type: string
34+
enum: [panic, fatal, error, warn, warning, info, debug, trace]
35+
description: >
36+
Overrides the module logger level for this datasource.
37+
name:
38+
type: string
39+
description: Friendly identifier for the datasource entry.
40+
use_time_machine:
41+
type: boolean
42+
default: false
43+
description: >
44+
Replays past events when supported by the acquisition module.
45+
unique_id:
46+
type: string
47+
description: >
48+
Stable identifier injected by cscli/crowdsec autop-run (usually not user set).
49+
transform:
50+
type: string
51+
description: >
52+
expr program applied to events before they enter the pipeline.
53+
check_interval:
54+
type: string
55+
pattern: "^[0-9]+(ns|us|ms|s|m|h)$"
56+
description: >
57+
Poll interval used by DSN-driven oneshot mode (deprecated in streaming configs).
58+
follow_stdout:
59+
type: boolean
60+
default: true
61+
description: >
62+
Stream stdout logs from matching containers/services.
63+
follow_stderr:
64+
type: boolean
65+
default: true
66+
description: >
67+
Stream stderr logs from matching containers/services.
68+
since:
69+
type: string
70+
format: date-time
71+
description: >
72+
RFC3339 lower-bound timestamp; defaults to the current UTC time if omitted.
73+
until:
74+
type: string
75+
format: date-time
76+
description: >
77+
RFC3339 upper-bound timestamp for finite reads.
78+
docker_host:
79+
type: string
80+
description: >
81+
Optional Docker API endpoint (unix://, tcp:// or npipe://). Defaults to client.FromEnv.
82+
container_name:
83+
$ref: "#/$defs/identifierList"
84+
description: Exact container names to follow.
85+
container_id:
86+
$ref: "#/$defs/identifierList"
87+
description: Exact container IDs to follow.
88+
container_name_regexp:
89+
$ref: "#/$defs/regexpList"
90+
description: Go regular expressions to match container names.
91+
container_id_regexp:
92+
$ref: "#/$defs/regexpList"
93+
description: Go regular expressions to match container IDs.
94+
service_name:
95+
$ref: "#/$defs/identifierList"
96+
description: Exact Swarm service names to follow.
97+
service_id:
98+
$ref: "#/$defs/identifierList"
99+
description: Exact Swarm service IDs to follow.
100+
service_name_regexp:
101+
$ref: "#/$defs/regexpList"
102+
description: Go regular expressions to match service names.
103+
service_id_regexp:
104+
$ref: "#/$defs/regexpList"
105+
description: Go regular expressions to match service IDs.
106+
use_container_labels:
107+
type: boolean
108+
default: false
109+
description: >
110+
Populate CrowdSec labels from Docker container labels. Mutually exclusive
111+
with explicit container selectors.
112+
use_service_labels:
113+
type: boolean
114+
default: false
115+
description: >
116+
Populate CrowdSec labels from Docker service labels. Mutually exclusive
117+
with explicit service selectors.
118+
required:
119+
- source
120+
allOf:
121+
- description: >
122+
At least one explicit selector or label-driven selector is required,
123+
matching hasContainerConfig/hasServiceConfig.
124+
anyOf:
125+
- required: [container_name]
126+
- required: [container_id]
127+
- required: [container_name_regexp]
128+
- required: [container_id_regexp]
129+
- required: [service_name]
130+
- required: [service_id]
131+
- required: [service_name_regexp]
132+
- required: [service_id_regexp]
133+
- properties:
134+
use_container_labels:
135+
const: true
136+
required: [use_container_labels]
137+
- properties:
138+
use_service_labels:
139+
const: true
140+
required: [use_service_labels]
141+
- if:
142+
properties:
143+
use_container_labels:
144+
const: true
145+
required: [use_container_labels]
146+
then:
147+
not:
148+
anyOf:
149+
- required: [container_name]
150+
- required: [container_id]
151+
- required: [container_name_regexp]
152+
- required: [container_id_regexp]
153+
- if:
154+
properties:
155+
use_service_labels:
156+
const: true
157+
required: [use_service_labels]
158+
then:
159+
not:
160+
anyOf:
161+
- required: [service_name]
162+
- required: [service_id]
163+
- required: [service_name_regexp]
164+
- required: [service_id_regexp]
165+
examples:
166+
- source: docker
167+
mode: tail
168+
labels:
169+
type: nginx
170+
container_name:
171+
- web
172+
follow_stderr: false
173+
- source: docker
174+
mode: cat
175+
labels:
176+
type: traefik
177+
use_service_labels: true
178+
follow_stdout: true
179+
$defs:
180+
identifierList:
181+
type: array
182+
minItems: 1
183+
uniqueItems: true
184+
items:
185+
type: string
186+
minLength: 1
187+
regexpList:
188+
type: array
189+
minItems: 1
190+
uniqueItems: true
191+
items:
192+
type: string
193+
minLength: 1
194+
format: regex

0 commit comments

Comments
 (0)