Skip to content

Commit f3816ec

Browse files
Merge pull request #24 from umago/input-output-sanitization
Add input/output sanitization and security improvements
2 parents 903638a + 16c0ec1 commit f3816ec

8 files changed

Lines changed: 26 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ build: manifests generate fmt vet ## Build manager binary.
156156

157157
.PHONY: run
158158
run: manifests generate fmt vet ## Run a controller from your host.
159-
source ./scripts/env.sh && go run ./cmd/main.go
159+
source ./scripts/env.sh && go run ./cmd/main.go $(ARGS)
160160

161161
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
162162
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ If you are making changes to the operator you can run the operator locally
169169
(outside the cluster) using the Operator SDK make targets:
170170

171171
```bash
172-
make install run
172+
make install run ARGS="--zap-devel"
173173
```
174174

175+
Note: `--zap-devel` enable verbose (development) logging locally.
176+
175177
This will:
176178

177179
1. Install the CRDs into your cluster.

api/v1beta1/openstacklightspeed_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type OpenStackLightspeedSpec struct {
116116
type LoggingConfig struct {
117117
// +kubebuilder:validation:Optional
118118
// +kubebuilder:default="all=info"
119+
// +kubebuilder:validation:Pattern=`^\w+(?:=\w+)?(?:,\w+(?:=\w+)?)*$`
119120
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="OGX Log Level"
120121
// Log level configuration for the OGX/llama-stack container. Supports standard levels (INFO, DEBUG) or fine-grained control using format "component=level,component=level" (e.g., "core=debug,providers=info").
121122
OGXLogLevel string `json:"ogxLogLevel,omitempty"`
@@ -138,6 +139,7 @@ type LoggingConfig struct {
138139
// OpenStackLightspeedCore defines the desired state of OpenStackLightspeed
139140
type OpenStackLightspeedCore struct {
140141
// +kubebuilder:validation:Required
142+
// +kubebuilder:validation:Pattern=`^https?://.+`
141143
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="LLM Endpoint"
142144
// URL pointing to the LLM
143145
LLMEndpoint string `json:"llmEndpoint"`
@@ -165,6 +167,7 @@ type OpenStackLightspeedCore struct {
165167
TLSCACertBundle string `json:"tlsCACertBundle"`
166168

167169
// +kubebuilder:validation:Optional
170+
// +kubebuilder:validation:Minimum=1
168171
// MaxTokensForResponse defines the maximum number of tokens to be used for the response generation
169172
MaxTokensForResponse int `json:"maxTokensForResponse,omitempty"`
170173

bundle/manifests/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ spec:
9494
type: string
9595
llmEndpoint:
9696
description: URL pointing to the LLM
97+
pattern: ^https?://.+
9798
type: string
9899
llmEndpointType:
99100
description: Type of the provider serving the LLM
@@ -141,11 +142,13 @@ spec:
141142
description: Log level configuration for the OGX/llama-stack container.
142143
Supports standard levels (INFO, DEBUG) or fine-grained control
143144
using format "component=level,component=level" (e.g., "core=debug,providers=info").
145+
pattern: ^\w+(?:=\w+)?(?:,\w+(?:=\w+)?)*$
144146
type: string
145147
type: object
146148
maxTokensForResponse:
147149
description: MaxTokensForResponse defines the maximum number of tokens
148150
to be used for the response generation
151+
minimum: 1
149152
type: integer
150153
modelName:
151154
description: Name of the model to use at the API endpoint provided

cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ func main() {
9292
flag.StringVar(&keyName, "key-name", "tls.key",
9393
"The name of the TLS key file.")
9494
opts := zap.Options{
95-
Development: true,
95+
// Development: false uses JSON encoding and omits stack traces / DPanic behaviour.
96+
// For local development use: make run ARGS="--zap-devel"
97+
Development: false,
9698
}
9799
opts.BindFlags(flag.CommandLine)
98100
flag.Parse()

config/crd/bases/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ spec:
9494
type: string
9595
llmEndpoint:
9696
description: URL pointing to the LLM
97+
pattern: ^https?://.+
9798
type: string
9899
llmEndpointType:
99100
description: Type of the provider serving the LLM
@@ -141,11 +142,13 @@ spec:
141142
description: Log level configuration for the OGX/llama-stack container.
142143
Supports standard levels (INFO, DEBUG) or fine-grained control
143144
using format "component=level,component=level" (e.g., "core=debug,providers=info").
145+
pattern: ^\w+(?:=\w+)?(?:,\w+(?:=\w+)?)*$
144146
type: string
145147
type: object
146148
maxTokensForResponse:
147149
description: MaxTokensForResponse defines the maximum number of tokens
148150
to be used for the response generation
151+
minimum: 1
149152
type: integer
150153
modelName:
151154
description: Name of the model to use at the API endpoint provided

internal/controller/assets/console_nginx.conf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ http {
1818
ssl_certificate /var/cert/tls.crt;
1919
ssl_certificate_key /var/cert/tls.key;
2020
root /usr/share/nginx/html;
21+
# Prevent this plugin from being embedded in an iframe (clickjacking protection).
22+
add_header X-Frame-Options "DENY" always;
23+
# Prevent browsers from MIME-sniffing JS/CSS assets away from their declared content-type.
24+
add_header X-Content-Type-Options "nosniff" always;
25+
# Only send the origin (no path or query) in the Referer header on cross-origin requests.
26+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
2127
}
2228
}

internal/controller/postgres_deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func buildPostgresPodTemplateSpec() corev1.PodTemplateSpec {
171171
SecurityContext: &corev1.SecurityContext{
172172
AllowPrivilegeEscalation: &[]bool{false}[0],
173173
ReadOnlyRootFilesystem: &[]bool{true}[0],
174+
RunAsNonRoot: &[]bool{true}[0],
175+
Capabilities: &corev1.Capabilities{
176+
Drop: []corev1.Capability{"ALL"},
177+
},
174178
},
175179
StartupProbe: buildPostgresProbe(PostgresStartupProbePeriodSeconds, PostgresStartupProbeTimeoutSeconds, PostgresStartupProbeFailureThreshold, PostgresStartupProbeInitialDelaySeconds),
176180
LivenessProbe: buildPostgresProbe(PostgresLivenessProbePeriodSeconds, PostgresLivenessProbeTimeoutSeconds, PostgresLivenessProbeFailureThreshold, 0),

0 commit comments

Comments
 (0)