Skip to content

Commit b1ed4a3

Browse files
authored
fix(config): align audit device options with OpenBao (#423)
Signed-off-by: Roel de Cort <roel.decort@adfinis.com>
1 parent 945b4a4 commit b1ed4a3

8 files changed

Lines changed: 617 additions & 97 deletions

File tree

api/v1alpha1/openbaocluster_types.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,12 @@ type SelfInitRequest struct {
10501050
// SelfInitAuditDevice provides structured configuration for enabling audit devices
10511051
// via self-init requests. This replaces the need for raw JSON in the Data field.
10521052
// See: https://openbao.org/api-docs/system/audit/
1053+
// +kubebuilder:validation:XValidation:rule="self.type == 'file' || !has(self.fileOptions)",message="fileOptions is only supported when type is file"
1054+
// +kubebuilder:validation:XValidation:rule="self.type != 'file' || has(self.fileOptions)",message="fileOptions is required when type is file"
1055+
// +kubebuilder:validation:XValidation:rule="self.type == 'http' || !has(self.httpOptions)",message="httpOptions is only supported when type is http"
1056+
// +kubebuilder:validation:XValidation:rule="self.type != 'http' || has(self.httpOptions)",message="httpOptions is required when type is http"
1057+
// +kubebuilder:validation:XValidation:rule="self.type == 'syslog' || !has(self.syslogOptions)",message="syslogOptions is only supported when type is syslog"
1058+
// +kubebuilder:validation:XValidation:rule="self.type == 'socket' || !has(self.socketOptions)",message="socketOptions is only supported when type is socket"
10531059
type SelfInitAuditDevice struct {
10541060
// Type is the type of audit device (e.g., "file", "syslog", "socket", "http").
10551061
// +kubebuilder:validation:Enum=file;syslog;socket;http
@@ -2006,6 +2012,8 @@ type OpenBaoClusterSpec struct {
20062012
// Audit configures declarative audit devices for the OpenBao cluster.
20072013
// See: https://openbao.org/docs/configuration/audit/
20082014
// +optional
2015+
// +listType=map
2016+
// +listMapKey=path
20092017
Audit []AuditDevice `json:"audit,omitempty"`
20102018
// Plugins configures declarative plugins for the OpenBao cluster.
20112019
// See: https://openbao.org/docs/configuration/plugins/
@@ -2481,6 +2489,10 @@ type OpenBaoClusterList struct {
24812489

24822490
// AuditDevice defines a declarative audit device configuration.
24832491
// See: https://openbao.org/docs/configuration/audit/
2492+
// +kubebuilder:validation:XValidation:rule="self.type == 'file' || !has(self.fileOptions)",message="fileOptions is only supported when type is file"
2493+
// +kubebuilder:validation:XValidation:rule="self.type == 'http' || !has(self.httpOptions)",message="httpOptions is only supported when type is http"
2494+
// +kubebuilder:validation:XValidation:rule="self.type == 'syslog' || !has(self.syslogOptions)",message="syslogOptions is only supported when type is syslog"
2495+
// +kubebuilder:validation:XValidation:rule="self.type == 'socket' || !has(self.socketOptions)",message="socketOptions is only supported when type is socket"
24842496
type AuditDevice struct {
24852497
// Type is the type of audit device (e.g., "file", "syslog", "socket", "http").
24862498
// +kubebuilder:validation:Enum=file;syslog;socket;http
@@ -2508,10 +2520,11 @@ type AuditDevice struct {
25082520
// Only used when Type is "socket".
25092521
// +optional
25102522
SocketOptions *SocketAuditOptions `json:"socketOptions,omitempty"`
2511-
// Options contains device-specific configuration options as a map.
2523+
// Options contains device-specific configuration options as a string map.
25122524
// This is a fallback for backward compatibility and advanced use cases.
25132525
// If structured options (FileOptions, HTTPOptions, etc.) are provided, they take precedence.
2514-
// The structure depends on the audit device type.
2526+
// OpenBao audit options are string-to-string; scalar JSON values are rendered as strings,
2527+
// while nested objects and arrays are rejected. For HTTP headers, prefer httpOptions.headers.
25152528
// +optional
25162529
Options *apiextensionsv1.JSON `json:"options,omitempty"`
25172530
}
@@ -2537,7 +2550,8 @@ type HTTPAuditOptions struct {
25372550
URI string `json:"uri"`
25382551
// Headers is a JSON object describing headers. Must take the shape map[string][]string,
25392552
// i.e., an object of headers, with each having one or more values.
2540-
// Headers without values will be ignored.
2553+
// Headers without values will be ignored. The operator renders this object as OpenBao's
2554+
// expected JSON-encoded options.headers string.
25412555
// +optional
25422556
Headers *apiextensionsv1.JSON `json:"headers,omitempty"`
25432557
}

charts/openbao-operator/crds/openbao.org_openbaoclusters.yaml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ spec:
9797
description: |-
9898
Headers is a JSON object describing headers. Must take the shape map[string][]string,
9999
i.e., an object of headers, with each having one or more values.
100-
Headers without values will be ignored.
100+
Headers without values will be ignored. The operator renders this object as OpenBao's
101+
expected JSON-encoded options.headers string.
101102
x-kubernetes-preserve-unknown-fields: true
102103
uri:
103104
description: URI is the URI of the remote server where the
@@ -109,10 +110,11 @@ spec:
109110
type: object
110111
options:
111112
description: |-
112-
Options contains device-specific configuration options as a map.
113+
Options contains device-specific configuration options as a string map.
113114
This is a fallback for backward compatibility and advanced use cases.
114115
If structured options (FileOptions, HTTPOptions, etc.) are provided, they take precedence.
115-
The structure depends on the audit device type.
116+
OpenBao audit options are string-to-string; scalar JSON values are rendered as strings,
117+
while nested objects and arrays are rejected. For HTTP headers, prefer httpOptions.headers.
116118
x-kubernetes-preserve-unknown-fields: true
117119
path:
118120
description: Path is the path of the audit device in the root
@@ -171,7 +173,19 @@ spec:
171173
- path
172174
- type
173175
type: object
176+
x-kubernetes-validations:
177+
- message: fileOptions is only supported when type is file
178+
rule: self.type == 'file' || !has(self.fileOptions)
179+
- message: httpOptions is only supported when type is http
180+
rule: self.type == 'http' || !has(self.httpOptions)
181+
- message: syslogOptions is only supported when type is syslog
182+
rule: self.type == 'syslog' || !has(self.syslogOptions)
183+
- message: socketOptions is only supported when type is socket
184+
rule: self.type == 'socket' || !has(self.socketOptions)
174185
type: array
186+
x-kubernetes-list-map-keys:
187+
- path
188+
x-kubernetes-list-type: map
175189
backup:
176190
description: Backup configures scheduled backups for the cluster.
177191
properties:
@@ -3428,7 +3442,8 @@ spec:
34283442
description: |-
34293443
Headers is a JSON object describing headers. Must take the shape map[string][]string,
34303444
i.e., an object of headers, with each having one or more values.
3431-
Headers without values will be ignored.
3445+
Headers without values will be ignored. The operator renders this object as OpenBao's
3446+
expected JSON-encoded options.headers string.
34323447
x-kubernetes-preserve-unknown-fields: true
34333448
uri:
34343449
description: URI is the URI of the remote server
@@ -3489,6 +3504,21 @@ spec:
34893504
required:
34903505
- type
34913506
type: object
3507+
x-kubernetes-validations:
3508+
- message: fileOptions is only supported when type is file
3509+
rule: self.type == 'file' || !has(self.fileOptions)
3510+
- message: fileOptions is required when type is file
3511+
rule: self.type != 'file' || has(self.fileOptions)
3512+
- message: httpOptions is only supported when type is http
3513+
rule: self.type == 'http' || !has(self.httpOptions)
3514+
- message: httpOptions is required when type is http
3515+
rule: self.type != 'http' || has(self.httpOptions)
3516+
- message: syslogOptions is only supported when type is
3517+
syslog
3518+
rule: self.type == 'syslog' || !has(self.syslogOptions)
3519+
- message: socketOptions is only supported when type is
3520+
socket
3521+
rule: self.type == 'socket' || !has(self.socketOptions)
34923522
authMethod:
34933523
description: |-
34943524
AuthMethod configures an auth method when Path starts with "sys/auth/".

config/crd/bases/openbao.org_openbaoclusters.yaml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ spec:
9696
description: |-
9797
Headers is a JSON object describing headers. Must take the shape map[string][]string,
9898
i.e., an object of headers, with each having one or more values.
99-
Headers without values will be ignored.
99+
Headers without values will be ignored. The operator renders this object as OpenBao's
100+
expected JSON-encoded options.headers string.
100101
x-kubernetes-preserve-unknown-fields: true
101102
uri:
102103
description: URI is the URI of the remote server where the
@@ -108,10 +109,11 @@ spec:
108109
type: object
109110
options:
110111
description: |-
111-
Options contains device-specific configuration options as a map.
112+
Options contains device-specific configuration options as a string map.
112113
This is a fallback for backward compatibility and advanced use cases.
113114
If structured options (FileOptions, HTTPOptions, etc.) are provided, they take precedence.
114-
The structure depends on the audit device type.
115+
OpenBao audit options are string-to-string; scalar JSON values are rendered as strings,
116+
while nested objects and arrays are rejected. For HTTP headers, prefer httpOptions.headers.
115117
x-kubernetes-preserve-unknown-fields: true
116118
path:
117119
description: Path is the path of the audit device in the root
@@ -170,7 +172,19 @@ spec:
170172
- path
171173
- type
172174
type: object
175+
x-kubernetes-validations:
176+
- message: fileOptions is only supported when type is file
177+
rule: self.type == 'file' || !has(self.fileOptions)
178+
- message: httpOptions is only supported when type is http
179+
rule: self.type == 'http' || !has(self.httpOptions)
180+
- message: syslogOptions is only supported when type is syslog
181+
rule: self.type == 'syslog' || !has(self.syslogOptions)
182+
- message: socketOptions is only supported when type is socket
183+
rule: self.type == 'socket' || !has(self.socketOptions)
173184
type: array
185+
x-kubernetes-list-map-keys:
186+
- path
187+
x-kubernetes-list-type: map
174188
backup:
175189
description: Backup configures scheduled backups for the cluster.
176190
properties:
@@ -3427,7 +3441,8 @@ spec:
34273441
description: |-
34283442
Headers is a JSON object describing headers. Must take the shape map[string][]string,
34293443
i.e., an object of headers, with each having one or more values.
3430-
Headers without values will be ignored.
3444+
Headers without values will be ignored. The operator renders this object as OpenBao's
3445+
expected JSON-encoded options.headers string.
34313446
x-kubernetes-preserve-unknown-fields: true
34323447
uri:
34333448
description: URI is the URI of the remote server
@@ -3488,6 +3503,21 @@ spec:
34883503
required:
34893504
- type
34903505
type: object
3506+
x-kubernetes-validations:
3507+
- message: fileOptions is only supported when type is file
3508+
rule: self.type == 'file' || !has(self.fileOptions)
3509+
- message: fileOptions is required when type is file
3510+
rule: self.type != 'file' || has(self.fileOptions)
3511+
- message: httpOptions is only supported when type is http
3512+
rule: self.type == 'http' || !has(self.httpOptions)
3513+
- message: httpOptions is required when type is http
3514+
rule: self.type != 'http' || has(self.httpOptions)
3515+
- message: syslogOptions is only supported when type is
3516+
syslog
3517+
rule: self.type == 'syslog' || !has(self.syslogOptions)
3518+
- message: socketOptions is only supported when type is
3519+
socket
3520+
rule: self.type == 'socket' || !has(self.socketOptions)
34913521
authMethod:
34923522
description: |-
34933523
AuthMethod configures an auth method when Path starts with "sys/auth/".

docs/reference/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ _Appears in:_
160160
| `httpOptions` _[HTTPAuditOptions](#httpauditoptions)_ | HTTPOptions configures options for HTTP audit devices.<br />Only used when Type is "http". | | Optional: \{\} <br /> |
161161
| `syslogOptions` _[SyslogAuditOptions](#syslogauditoptions)_ | SyslogOptions configures options for syslog audit devices.<br />Only used when Type is "syslog". | | Optional: \{\} <br /> |
162162
| `socketOptions` _[SocketAuditOptions](#socketauditoptions)_ | SocketOptions configures options for socket audit devices.<br />Only used when Type is "socket". | | Optional: \{\} <br /> |
163-
| `options` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#json-v1-apiextensions-k8s-io)_ | Options contains device-specific configuration options as a map.<br />This is a fallback for backward compatibility and advanced use cases.<br />If structured options (FileOptions, HTTPOptions, etc.) are provided, they take precedence.<br />The structure depends on the audit device type. | | Optional: \{\} <br /> |
163+
| `options` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#json-v1-apiextensions-k8s-io)_ | Options contains device-specific configuration options as a string map.<br />This is a fallback for backward compatibility and advanced use cases.<br />If structured options (FileOptions, HTTPOptions, etc.) are provided, they take precedence.<br />OpenBao audit options are string-to-string; scalar JSON values are rendered as strings,<br />while nested objects and arrays are rejected. For HTTP headers, prefer httpOptions.headers. | | Optional: \{\} <br /> |
164164

165165

166166
#### AutoRollbackConfig
@@ -642,7 +642,7 @@ _Appears in:_
642642
| Field | Description | Default | Validation |
643643
| --- | --- | --- | --- |
644644
| `uri` _string_ | URI is the URI of the remote server where the audit logs will be written. | | MinLength: 1 <br /> |
645-
| `headers` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#json-v1-apiextensions-k8s-io)_ | Headers is a JSON object describing headers. Must take the shape map[string][]string,<br />i.e., an object of headers, with each having one or more values.<br />Headers without values will be ignored. | | Optional: \{\} <br /> |
645+
| `headers` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#json-v1-apiextensions-k8s-io)_ | Headers is a JSON object describing headers. Must take the shape map[string][]string,<br />i.e., an object of headers, with each having one or more values.<br />Headers without values will be ignored. The operator renders this object as OpenBao's<br />expected JSON-encoded options.headers string. | | Optional: \{\} <br /> |
646646

647647

648648
#### ImageVerificationConfig

0 commit comments

Comments
 (0)