Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
289 lines (254 loc) · 11.9 KB
/
Copy pathMakefile
File metadata and controls
289 lines (254 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
.PHONY: help server server-pkcs11 agent frontend proto proto-go proto-ts clean test lint lint-server lint-agent lint-frontend check-frontend-tokens install-deps dev \
packages packages-agent packages-server
# Versioning — override with: make packages VERSION=1.2.3
# Defaults to 0.0.0.git<sha> so local builds produce a dpkg/rpm/apk-valid version.
# dpkg requires the version to start with a digit; plain "dev" is rejected.
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
VERSION ?= 0.0.0.git$(GIT_SHA)
# Target architecture — override with: make packages ARCH=arm64
ARCH ?= amd64
# APK version — Alpine requires strictly numeric dot-components (e.g. 1.2.3).
# Strip the git suffix for local dev builds; release builds set VERSION to a
# plain semver so this falls through to VERSION unchanged.
APK_VERSION ?= $(shell echo "$(VERSION)" | sed 's/\.git.*//')
# Default target
help:
@echo "Bor Policy Management System - Makefile"
@echo ""
@echo "Available targets:"
@echo " help - Show this help message"
@echo " server - Build the Go server"
@echo " agent - Build the Go agent"
@echo " frontend - Build the React frontend"
@echo " proto - Generate code from Protocol Buffers"
@echo " test - Run all tests"
@echo " test-server - Run server tests"
@echo " test-agent - Run agent tests"
@echo " lint - Run linters"
@echo " lint-server - Lint Go server code"
@echo " lint-agent - Lint Go agent code"
@echo " lint-frontend - Lint frontend accessibility (jsx-a11y)"
@echo " check-frontend-tokens - Ban --pf-v5-* vars and ratchet raw hex in frontend src"
@echo " clean - Clean build artifacts"
@echo " install-deps - Install development dependencies"
@echo " dev - Start development environment"
@echo " docker - Build Docker images"
@echo " packages - Build all packages (deb/rpm/apk/archlinux)"
@echo " packages-agent - Build agent packages only"
@echo " packages-server - Build server packages only"
@echo ""
@echo "Package versioning: make packages VERSION=1.2.3 ARCH=amd64"
@echo "All builds use GOFIPS140=v1.0.0 (FIPS 140-3 validated crypto module)."
@echo "FIPS enforcement: GODEBUG=fips140=on ./server (restricts to FIPS-approved algorithms at runtime)"
@echo ""
@echo "HSM / PKCS#11 build (requires CGO and a C compiler):"
@echo " make server-pkcs11"
# All Go builds use GOFIPS140=v1.0.0 to pin the FIPS 140-3 validated crypto
# module snapshot (CAVP certificate A6650). This ensures the binary contains
# only the validated implementation regardless of the host Go toolchain.
# To enforce FIPS-only algorithms at runtime: GODEBUG=fips140=on ./server
# Build server
server:
@echo "Building server (FIPS 140-3, version=$(VERSION), arch=$(ARCH))..."
cd server && GOFIPS140=v1.0.0 GOARCH=$(ARCH) go build \
-ldflags "-X main.Version=$(VERSION)" \
-o server ./cmd/server
# Build server with PKCS#11 HSM support (requires CGO and a C compiler)
server-pkcs11:
@echo "Building server (FIPS 140-3 + PKCS#11 HSM support, version=$(VERSION), arch=$(ARCH))..."
cd server && GOFIPS140=v1.0.0 GOARCH=$(ARCH) CGO_ENABLED=1 go build \
-tags pkcs11 \
-ldflags "-X main.Version=$(VERSION)" \
-o server ./cmd/server
# Build frontend
frontend:
@echo "Building frontend..."
cd server/web/frontend && npm install && npm run build
# Build agent
agent:
@echo "Building agent (FIPS 140-3, version=$(VERSION), arch=$(ARCH))..."
cd agent && GOFIPS140=v1.0.0 GOARCH=$(ARCH) go build \
-ldflags "-X main.Version=$(VERSION)" \
-o bor-agent ./cmd/agent
# Regenerate dconf built-in schema catalogue from the local system's GSettings schemas.
# Run this on a reference GNOME installation to refresh server/assets/dconf_builtin_schemas.json.
# Use SCHEMAS_DIR to point at a directory with copied .gschema.xml files from another system.
update-dconf-schemas:
@echo "Generating dconf built-in schema catalogue..."
cd agent && go run ./cmd/gen-dconf-schemas \
--schemas-dir $${SCHEMAS_DIR:-/usr/share/glib-2.0/schemas} \
--out ../server/assets/dconf_builtin_schemas.json
@echo "Done. Commit server/assets/dconf_builtin_schemas.json."
# Regenerate polkit built-in action catalogue from the local system's polkit actions.
# Run this on a reference Linux installation with polkit installed to refresh
# server/assets/polkit_builtin_actions.json.
update-polkit-actions:
@echo "Generating polkit built-in action catalogue..."
cd agent && go run ./cmd/gen-polkit-actions \
--out ../server/assets/polkit_builtin_actions.json
@echo "Done. Commit server/assets/polkit_builtin_actions.json."
# Regenerate the TypeScript copy of the built-in KDE settings catalogue
# (server/assets/kconfig_builtin_catalogue.json) that the web UI bundles.
kconfig-catalogue:
@echo "Generating KDE settings catalogue (TypeScript)..."
cd server/web/frontend && node scripts/gen-kconfig-catalogue.mjs
@echo "Done. Commit server/web/frontend/src/generated/kconfig_catalogue.ts."
# Generate Protocol Buffers (Go + TypeScript)
proto: proto-go proto-ts proto-ui
proto-go:
@echo "Generating Go protobuf code..."
mkdir -p server/pkg/grpc/borui
protoc --go_out=server/pkg/grpc/borui --go_opt=paths=source_relative \
-I proto/bor \
proto/bor/ui.proto
mkdir -p server/pkg/grpc/policy
protoc --go_out=server/pkg/grpc/policy --go_opt=paths=source_relative \
--go-grpc_out=server/pkg/grpc/policy --go-grpc_opt=paths=source_relative \
-I proto/policy -I proto/bor \
proto/policy/*.proto
mkdir -p server/pkg/grpc/audit
protoc --go_out=server/pkg/grpc/audit --go_opt=paths=source_relative \
-I proto/audit proto/audit/audit.proto
mkdir -p server/pkg/grpc/export
protoc --go_out=server/pkg/grpc/export --go_opt=paths=source_relative \
-I proto/export proto/export/export.proto
proto-ts:
@echo "Generating TypeScript protobuf types..."
mkdir -p server/web/frontend/src/generated/proto
cd server/web/frontend && \
protoc \
--plugin=node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=src/generated/proto \
--ts_proto_opt=onlyTypes=true,snakeToCamel=false,outputServices=false \
-I ../../../proto/policy -I ../../../proto/bor \
../../../proto/policy/*.proto
proto-ui:
@echo "Generating policy UI metadata (TypeScript)..."
mkdir -p server/web/frontend/src/generated/proto
cd server/web/frontend && \
protoc \
--plugin=$(shell which protoc-gen-bor-ui) \
--bor-ui_out=src/generated/proto \
-I ../../../proto/policy -I ../../../proto/bor \
../../../proto/policy/*.proto
# Run all tests
test: test-server test-agent
# Run server tests
test-server:
@echo "Running server tests..."
cd server && go test -v ./...
# Run agent tests
test-agent:
@echo "Running agent tests..."
cd agent && go test -v ./...
# Run all linters
lint: lint-server lint-agent lint-frontend check-frontend-tokens
# Lint server code
lint-server:
@echo "Linting server code..."
cd server && golangci-lint run ./...
# Lint agent code
lint-agent:
@echo "Linting agent code..."
cd agent && golangci-lint run ./...
# Lint frontend accessibility (eslint-plugin-jsx-a11y). Requires deps: npm install.
lint-frontend:
@echo "Linting frontend accessibility..."
cd server/web/frontend && npm run lint
# Frontend design-token guardrail: ban legacy --pf-v5-* variables and ratchet
# raw hex colour literals in component code. Pure grep, no npm deps needed.
check-frontend-tokens:
@echo "Checking frontend design tokens..."
./scripts/check-frontend-tokens.sh
# Build packages (deb, rpm, apk, archlinux) using nfpm
packages: packages-agent packages-server
packages-agent: agent
@echo "Building bor-agent packages (version=$(VERSION) apk=$(APK_VERSION) arch=$(ARCH))..."
@mkdir -p builds
VERSION=$(VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-agent.yaml --packager deb --target builds/
VERSION=$(VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-agent.yaml --packager rpm --target builds/
VERSION=$(APK_VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-agent.yaml --packager apk --target builds/
VERSION=$(VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-agent.yaml --packager archlinux --target builds/
@echo "Agent packages written to builds/"
packages-server: server frontend
@echo "Building bor-server packages (version=$(VERSION) apk=$(APK_VERSION) arch=$(ARCH))..."
@mkdir -p builds
VERSION=$(VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-server.yaml --packager deb --target builds/
VERSION=$(VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-server.yaml --packager rpm --target builds/
VERSION=$(APK_VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-server.yaml --packager apk --target builds/
VERSION=$(VERSION) ARCH=$(ARCH) nfpm package --config packaging/nfpm-server.yaml --packager archlinux --target builds/
@echo "Server packages written to builds/"
# Assemble the static agent package repository (apt/dnf metadata + manifest)
# from the bor-agent packages already present in builds/. The tree ships
# inside the bor-server package and the container image at
# /usr/share/bor/agent-repo — run this BEFORE packages-server so the server
# package carries the repo (CI does; without it the server package contains
# only the placeholder and the feature stays off).
# Set SIGN_KEY_ID to a GPG key id to sign (CI does; unsigned = dev only).
# Requires apt-ftparchive, createrepo_c and jq — Debian-family tooling; on
# other distros run scripts/assemble-agent-repo.sh inside a debian container.
agent-repo:
@echo "Assembling agent package repository (version=$(VERSION))..."
VERSION=$(VERSION) APK_VERSION=$(APK_VERSION) PACKAGES_DIR=builds \
OUT_DIR=builds/agent-repo SIGN_KEY_ID=$(SIGN_KEY_ID) \
scripts/assemble-agent-repo.sh
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf server/server
rm -rf agent/bor-agent
rm -rf server/pkg/grpc/policy/*.pb.go
rm -rf server/pkg/grpc/borui/*.pb.go
rm -rf server/web/frontend/src/generated/proto/
rm -rf builds/
# Install development dependencies
install-deps:
@echo "Installing development dependencies..."
@echo "Installing Go tools..."
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.46.3 # same release as CI, so local and CI packages match
@echo "Installing protoc-gen-bor-ui plugin..."
cd server && go install ./cmd/protoc-gen-bor-ui
@echo "Installing TypeScript proto plugin..."
cd server/web/frontend && npm install
@echo ""
@echo "Note: Please ensure you have installed:"
@echo " - Protocol Buffers compiler (protoc)"
# Start development environment
dev:
@echo "Starting development environment..."
podman-compose up -d postgres
@echo "Database started on localhost:5432"
@echo ""
@echo "To run server: make server && cd server && ./server"
@echo "To run agent: make agent && cd agent && ./bor-agent"
# Build Docker images
docker:
@echo "Building Docker images..."
@mkdir -p builds/agent-repo
podman build -t bor-server:latest -f server/Containerfile .
# Format code
fmt:
@echo "Formatting code..."
cd server && go fmt ./...
cd agent && go fmt ./...
# Run server in development mode
run-server:
cd server && GOFIPS140=v1.0.0 go run ./cmd/server
# Database migrations
migrate-up:
@echo "Running database migrations..."
cd server && go run ./cmd/migrate up
migrate-down:
@echo "Rolling back database migrations..."
cd server && go run ./cmd/migrate down
# Coverage
coverage:
@echo "Generating coverage report..."
cd server && go test -coverprofile=coverage.out ./...
cd server && go tool cover -html=coverage.out -o coverage.html
cd agent && go test -coverprofile=coverage.out ./...
cd agent && go tool cover -html=coverage.out -o coverage.html
@echo "Coverage reports generated"