196 lines
6.5 KiB
Makefile
196 lines
6.5 KiB
Makefile
PYTHON ?= python3
|
|
GO ?= go
|
|
VERSION ?= $(shell git describe --always --dirty 2>/dev/null || echo dev)
|
|
BASE_URL ?= https://localhost:8443
|
|
LAB7_SECRETS_DIR ?= secrets/lab7
|
|
CA_FILE ?= $(LAB7_SECRETS_DIR)/pki/operator/current/ca.crt
|
|
ACTION_SCRIPT ?=
|
|
PIPELINE ?= 2
|
|
ROLE ?= api
|
|
CERT_TTL ?= 1h
|
|
TLS_ARGS = --ca-file "$(CA_FILE)"
|
|
COMPOSE_BIN ?= docker compose
|
|
COMPOSE_FILE ?= compose.yaml
|
|
ENV_FILE ?= .env
|
|
COMPOSE = $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE)
|
|
PYTHON_LOCAL = env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 $(PYTHON)
|
|
LOCAL_BIN := $(CURDIR)/bin
|
|
GOLANGCI_LINT_VERSION ?= v2.15.0
|
|
GOLANGCI_LINT := $(LOCAL_BIN)/golangci-lint
|
|
OPENAPI_SPEC := contracts/openapi.json
|
|
OGEN_CONFIG := .ogen.yml
|
|
OAS_DIR := internal/transport/rest/internal/oas
|
|
|
|
-include .env
|
|
export
|
|
ENV_KEYS := $(shell sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p' .env 2>/dev/null)
|
|
CLEAN_ENV = env $(addprefix -u ,$(ENV_KEYS))
|
|
|
|
.DEFAULT_GOAL := help
|
|
.PHONY: help check validate prepare build bootstrap up down ps logs test test-security test-lab7 test-pki auth-budget pki-issue pki-renew renew-watch bao-unseal test-attachments test-presign test-queue test-faults test-track2 test-observability test-slo test-idempotency test-lb-readiness load test-persistence test-failover jobs-failed replay reprocess unit-test integration-test test-db-up test-db-down dev-up dev-down dev-reload migrate generate generate-api generate-mocks sqlc cover lint
|
|
|
|
help:
|
|
@echo "prepare/build/up: local PKI, image, operator Bao init/unseal and full verified-TLS stand"
|
|
@echo "test/test-security/test-lab7: public HTTPS, external trust, complete internal security probes"
|
|
@echo "test-pki: 3 isolated lifecycle experiments; auth-budget: measured Argon2/login budget"
|
|
@echo "pki-issue/pki-renew/renew-watch ROLE=api CERT_TTL=1h; bao-unseal: operator recovery"
|
|
|
|
check:
|
|
$(PYTHON) scripts/check_contract.py
|
|
|
|
validate:
|
|
$(PYTHON) scripts/validate_openapi.py
|
|
|
|
prepare:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py prepare
|
|
|
|
build: prepare
|
|
$(COMPOSE) build api
|
|
|
|
bootstrap:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py bootstrap
|
|
|
|
up: build
|
|
$(PYTHON_LOCAL) scripts/securityctl.py up
|
|
|
|
down:
|
|
$(COMPOSE) down
|
|
|
|
ps:
|
|
$(COMPOSE) ps
|
|
|
|
logs:
|
|
$(COMPOSE) logs -f --tail 100
|
|
|
|
bao-unseal:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py unseal
|
|
|
|
pki-issue:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py issue "$(ROLE)" --ttl "$(CERT_TTL)"
|
|
|
|
pki-renew:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py renew "$(ROLE)" --ttl "$(CERT_TTL)"
|
|
|
|
renew-watch:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py renew "$(ROLE)" --ttl "$(CERT_TTL)" --watch --interval 1
|
|
|
|
renewer:
|
|
$(PYTHON_LOCAL) scripts/lab7_renewer.py --interval 1800 --ttl "$(CERT_TTL)"
|
|
|
|
renew-once:
|
|
$(PYTHON_LOCAL) scripts/lab7_renewer.py --once --ttl "$(CERT_TTL)" --output evidence/lab7/renewer.json
|
|
|
|
test:
|
|
$(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-security:
|
|
$(PYTHON_LOCAL) tests/security.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-lab7:
|
|
$(PYTHON_LOCAL) student-tests/lab7_security.py --base-url "$(BASE_URL)" $(TLS_ARGS) --output evidence/lab7/security.json
|
|
|
|
test-pki:
|
|
$(PYTHON_LOCAL) scripts/lab7_track2.py --reps 3 --duration 30 --output evidence/lab7/track2.json
|
|
|
|
auth-budget:
|
|
$(PYTHON_LOCAL) scripts/lab7_auth_benchmark.py --api $(TLS_ARGS) --output evidence/lab7/auth.json
|
|
|
|
test-attachments:
|
|
$(PYTHON_LOCAL) student-tests/attachments_negative.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-presign:
|
|
$(PYTHON_LOCAL) student-tests/presign_flow.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-queue:
|
|
$(PYTHON_LOCAL) student-tests/lab5_async.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-faults:
|
|
$(PYTHON_LOCAL) student-tests/lab5_faults.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-track2:
|
|
$(PYTHON_LOCAL) scripts/lab5_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-observability:
|
|
$(PYTHON_LOCAL) scripts/check_evidence.py
|
|
$(PYTHON_LOCAL) scripts/lab6_verify.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-slo:
|
|
$(PYTHON_LOCAL) scripts/lab6_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-idempotency:
|
|
$(PYTHON_LOCAL) student-tests/idempotency_parallel.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-lb-readiness:
|
|
scripts/lb_readiness_check.sh
|
|
|
|
load:
|
|
$(PYTHON_LOCAL) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-persistence:
|
|
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT=scripts/restart.sh"; exit 2)
|
|
$(PYTHON_LOCAL) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-failover:
|
|
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT=scripts/stop-one.sh"; exit 2)
|
|
$(PYTHON_LOCAL) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
jobs-failed:
|
|
$(PYTHON_LOCAL) scripts/securityctl.py jobctl failed
|
|
|
|
replay:
|
|
@test -n "$(JOB)" || (echo "Set JOB=<job_id>"; exit 2)
|
|
$(PYTHON_LOCAL) scripts/securityctl.py jobctl replay -job "$(JOB)"
|
|
|
|
reprocess:
|
|
@test -n "$(ATTACHMENT)" || (echo "Set ATTACHMENT=<attachment_id>"; exit 2)
|
|
$(PYTHON_LOCAL) scripts/securityctl.py jobctl reprocess -attachment "$(ATTACHMENT)" -pipeline "$(PIPELINE)"
|
|
|
|
unit-test:
|
|
$(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m ./...
|
|
|
|
integration-test:
|
|
$(PYTHON_LOCAL) scripts/lab7_integration.py
|
|
|
|
test-db-up:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f docker-compose.local.yaml up -d --no-build postgres redis
|
|
|
|
test-db-down:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f docker-compose.local.yaml down
|
|
|
|
dev-up: build
|
|
COMPOSE_FILE=docker-compose.local.yaml $(PYTHON_LOCAL) scripts/securityctl.py up
|
|
|
|
dev-down:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f docker-compose.local.yaml down
|
|
|
|
dev-reload:
|
|
COMPOSE_FILE=docker-compose.local.yaml $(PYTHON_LOCAL) scripts/securityctl.py restart
|
|
|
|
migrate:
|
|
$(COMPOSE) run --rm --no-deps migrate
|
|
|
|
generate: generate-api generate-mocks sqlc
|
|
|
|
generate-api:
|
|
$(GO) run ./tools/specgen
|
|
$(GO) tool ogen --config $(OGEN_CONFIG) --target $(OAS_DIR) --package oas --clean .cache/openapi.codegen.json
|
|
|
|
generate-mocks:
|
|
$(GO) tool mockery
|
|
|
|
sqlc:
|
|
$(GO) tool sqlc generate
|
|
|
|
COVER_EXCLUDE ?= /(mocks|oas)/|/cmd/
|
|
cover:
|
|
$(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m -covermode=atomic -coverprofile=coverage.out.tmp ./...
|
|
@grep -Ev '$(COVER_EXCLUDE)' coverage.out.tmp > coverage.out
|
|
@rm coverage.out.tmp
|
|
$(GO) tool cover -func=coverage.out
|
|
|
|
$(GOLANGCI_LINT): go.mod Makefile
|
|
GOBIN=$(LOCAL_BIN) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
|
|
|
|
lint: $(GOLANGCI_LINT)
|
|
$(GOLANGCI_LINT) run -v
|