docs: simplify project guides and add GPLv3

This commit is contained in:
TakuyaYagam1 committed 2026-10-11 22:25:10 +03:00
1 parent e4de6d0f9a
commit 76d32bb79f
59 files changed
+2267 -8843

No files matched your search

+27 -35
View File
@@ -1,62 +1,54 @@
# Security checks
# Security
The repository provides local and CI checks for known dependency vulnerabilities, selected configuration risks, secrets, and selected unsafe source patterns. These checks cover the technical scaffold. They do not establish complete security or verify future authorization and personal-data workflows.
Server-side authorization and service boundaries protect data. Scanners check known vulnerabilities and selected risky patterns; they do not replace business-flow checks or an audit.
## Commands
## Checks
Run from the repository root:
From the repository root:
```sh
make -C security install
make -C security check
make -C security test
make -C security test check
make -C security images
```
Installation requires Python, uv, Go, and network access. The Trivy/Gitleaks binary installer supports Linux amd64 and arm64. Tools stay in `security/.bin/`, `.tools/`, and `.cache/`; installation does not change global tools. The installer selects current stable Trivy and Gitleaks releases and verifies their downloaded archives against upstream SHA256 checksums. govulncheck is installed with `go install ...@latest`. Semgrep uses an isolated uv tool environment with Python 3.13; uv stores its managed Python under `security/.tools/python/`. Tool versions may change on a later installation; inspect installation output when reproducing a finding.
| Target | Scope |
| Tool | Current scope |
| --- | --- |
| `filesystem` | Trivy scans repository dependencies and configuration with `trivy/filesystem.yml` |
| `secrets` | Gitleaks scans tracked and non-ignored untracked files, plus all available Git history with `gitleaks/gitleaks.toml` |
| `go` | govulncheck analyzes the backend's use of known vulnerable Go code |
| `semgrep` | Local rules in `semgrep/frontend.yml` and `semgrep/python.yml` inspect frontend and ML source |
| `rule-test` | Semgrep fixtures check expected matches and non-matches for the local rules |
| `test` | Runs Semgrep rule fixtures and tests for installer integrity, Gitleaks input and report handling, govulncheck failure status, and stale reports |
| `check` | Runs filesystem, secrets, Go, and Semgrep checks; attempts every check and returns failure if any fails |
| `images` | Builds backend, frontend, and ML images, then scans each exact local image ID with Trivy |
| Trivy filesystem | Repository dependencies, lockfiles and configuration |
| Gitleaks | Tracked and non-ignored files, complete available Git history |
| govulncheck | Use of vulnerable code in `backend/` |
| Semgrep | Local rules for `frontend/src/` and `ml/src/` |
| Trivy images | Exact local backend, frontend and ML image IDs |
Gitleaks requires a full Git checkout. A missing repository or shallow history fails the check rather than silently omitting history. Its current-file scan uses tracked files and untracked files that Git does not ignore. Tracked ignored files remain in the scan, while ignored local files such as `.env` stay out of it. Deleted tracked paths and symlinks are omitted from the current scan; symlink targets are never followed or read. The history scan still covers every ref, including values committed before a file was ignored or removed. Gitleaks copies the current input set to an owner-only temporary directory and fails if either scanner fails or its JSON report is missing or invalid. Reports redact detected secret values. Developer tool caches and build output are excluded where configured; application lockfiles remain scan inputs. Trivy also recognizes `requirements-*.txt`, including `backend/requirements-quality.txt` and `scripts/requirements-codegen.txt`.
These checks do not include separate runner/labd Go modules or images. The backend Go linter also runs gosec. Image checks need Docker; installation needs network access, Python, uv and Go. Tools are installed locally, and current versions are recorded with reports.
Image checks require Docker. The backend build context is `backend/`; frontend and ML use the repository root. Images are tagged `lincodex-security-<service>:local` and resolved to image IDs before scanning. This command does not start containers or publish images. Scanning frontend source dependencies remains necessary because the final Nginx image contains compiled assets rather than the development dependency tree.
Trivy `HIGH`/`CRITICAL` findings, including unfixed vulnerabilities, block the check. Other scanner findings and tool errors fail too. Incomplete Git history and missing or corrupt reports are not success. Reports in `security/reports/` are local and redact secret values; review before sharing.
## Findings and exceptions
CI calls the same Make targets. A workflow file does not prove a successful run on the current code; releases need evidence from the actual run. Images must be checked alongside source lockfiles: a static frontend image does not contain every development dependency.
Trivy findings of severity `HIGH` or `CRITICAL` fail the check, including findings without a published fix, unless an active, narrowly scoped exception applies. Gitleaks findings, configured Semgrep findings, govulncheck findings, and scanner errors also fail their targets. The existing Go lint configuration retains gosec; this complements the added checks.
## Exceptions
Review the reported package, installed version, affected path, and available remediation before changing dependencies or configuration. Keep reports local: `security/reports/` is ignored. govulncheck uses text output so its native failure status is preserved. Trivy saves JSON reports and prints their tables in the check log. A scan error, missing report, or report conversion error keeps the check failing.
[Trivy ignore](../../security/trivy/ignore.yml) contains a specific exception for `CVE-2026-93687`, `braces@3.0.3` in the frontend lockfile, until 2026-10-19. It was accepted when no fix was available; maintainers must remove it after updating or review it before expiry. It does not exclude all package versions or images.
One temporary exception in [security/trivy/ignore.yml](../../security/trivy/ignore.yml) was approved by the project owner on 2026-10-05: `CVE-2026-93687` for `pkg:npm/braces@3.0.3` in `frontend/pnpm-lock.yaml`. At approval, no fixed release was available; the exception unblocks dependency CI until its expiry on 2026-10-19. Project maintainers own the exception and must remove it when a fix becomes available or review it before expiry. Trivy enforces the expiry date. Only filesystem scanning uses this exception file; suppressed findings remain visible in its JSON report. Image scanning is unaffected.
The [Gitleaks allowlist](../../security/gitleaks/gitleaks.toml) limits exceptions to exact test examples, paths and rules. Manual review is due on 2026-11-07; Gitleaks does not enforce that date. New exceptions require a specific finding, reason, owner and expiry. Do not disable scanners or hide every unfixed vulnerability to make CI pass.
Eight Gitleaks exceptions cover exact public API examples, test fixtures, a release-manifest fixture, and a fixed Redis rate-limit key prefix. Each requires the matching rule ID, repository path, and complete finding text. Project maintainers own them. Manually review or remove them by 2026-11-07; Gitleaks does not enforce that review date. See the official [Gitleaks configuration reference](https://github.com/gitleaks/gitleaks#configuration) for allowlist behavior.
## Data and network boundaries
For any further exception, scope it to the specific finding and affected input, record the reason, owner, and expiry, and have the change reviewed. The current integration does not enforce expiry uniformly across every tool, so review expiry explicitly where needed. Do not disable an entire scanner or globally suppress unfixed vulnerabilities to obtain a passing result.
- Authorization, company membership, consent, publication and contact grants are checked on the server at each access. A cache, snapshot or hidden button is not authorization.
- Passwords, session tokens, one-time codes, contacts, resume text and request bodies must not enter logs or metric labels. Verification mail sends the code only to its recipient; API errors do not disclose internal error text.
- SeaweedFS stays on a separate internal network; browsers receive neither S3 keys nor direct bucket access. Some internal interfaces do not enforce S3 authentication, so network membership is tightly limited.
- Secrets belong in the local environment or secret files, not Git. Nginx does not publish readiness, metrics or administration interfaces.
## Outbound requests and ML
- GitHub. Project repository checks call only `https://api.github.com`: the profile accepts an address only as `https://github.com/<owner>/<repo>`, the owner and name are checked against the GitHub patterns and escaped into the path, the base origin is fixed in code (tests replace it only inside the package), no proxy from the environment is used, TLS 1.2+, connect and response timeouts, a redirect is followed only to the same origin (at most three), responses are capped at 1 MiB and the README at 64 KiB. User input therefore cannot point the server at another host (SSRF). The checks are off by default (`GITHUB_REPOSITORY_CHECKS_ENABLED`), a repeated check is limited per candidate (`REPOSITORY_CHECK_INTERVAL`), and the GitHub limit is respected from its headers.
- Token. `GITHUB_TOKEN` is optional, needs read access to public data only, and is sent only to `api.github.com`; it never reaches logs, errors, jobs, or the database. The check log carries the job id, attempt, state, and error class, never the repository; the job key and payload carry only a digest of the repository.
- GitHub data. The description, topics, languages, and README text are untrusted data: the README becomes plain text, is stored only for a public repository, is used only for ranking, and is never shown, let alone as HTML. The repository address and owner never reach an organization, neither in the card, nor in the explanation, nor after C4.
- ML. Every route of the service except `/healthz` and `/readyz` requires `Authorization: Bearer <token>`: a shared random token of at least 32 printable characters (`ML_SERVICE_TOKEN` in the backend, `ML_SERVICE_TOKEN` or `ML_SERVICE_TOKEN_FILE` in the service) is compared in constant time and never reaches a log, a response, or an error message; a missing or wrong token answers 401 `unauthenticated`, and the request is refused before its body is read. Without a token the service answers loopback callers only, and the entry point `python -m lincodex_ml.serve` refuses to listen on a non-loopback address; the backend does not enable semantic matching without a token. In Compose the backend reaches the service over the network (`http://ml:8000`) and the host port is loopback; on a GPU host it listens on a private LAN address without TLS, so restrict the port to the app host address with host or network rules. `/metrics` requires the token too. The backend sends ML only the texts of the published card and of the organization's need, with no contact and no private profile. The weights are pinned by lock files with SHA-256, no remote model code is executed, no pickle is loaded, and the service runs offline.
GitHub checking is disabled by default. It accepts only public `https://github.com/<owner>/<repo>` links, calls the fixed `api.github.com` origin, and bounds redirects, time and response size. An arbitrary URL cannot become a network destination. README and metadata remain untrusted data; they are not executed or rendered as user HTML. Tokens stay out of jobs and logs.
## CI and limits
Backend sends ML only the allowed card and hiring-need projections, without contacts or private profiles. Every ML route except `/healthz` and `/readyz` requires a bearer token; without one, the service accepts loopback clients only. `/metrics` uses the same token, but the current Prometheus ML scrape does not yet send it. Restrict ML port access across hosts: a token does not encrypt HTTP traffic.
CI runs `make -C security test check` for source checks and `make -C security images` for images, and includes both jobs in its required aggregate result. Reports are uploaded as artifacts with a 14-day retention period, including when checks fail. Gitleaks redacts secret values, but reports can still reveal repository paths and dependency details; restrict artifact access accordingly.
The local Semgrep rules are a bounded frontend/ML rule set, not a complete application audit. Scanner results depend on the actual checkout, rule versions, vulnerability databases, build inputs, and time of execution. Checked-in workflows do not prove that a GitHub run occurred or that the current tree is free of findings. Record actual results when preparing a release; see [TESTING.md](TESTING.md) for other validation boundaries.
Model files are pinned by SHA-256 and loaded locally; remote model code and pickle are not executed. Model output is data, not an instruction to run a command, use a tool or change permissions.
## Code runner VM
The code runner executes untrusted candidate code, so production runs it only in the LXD VM `lincodex-runner` (see [DEPLOY.md](DEPLOY.md#production-the-runner-vm)). The boundary has three layers: nsjail with seccomp, namespaces, cgroup v2 limits, and no network for the program; a separate guest kernel; and the bridge ACL, which lets only the app network and the host side open TCP 8443 and drops every connection the guest starts. The VM holds only its own TLS pair and API token. The CA key and the database, mail, storage, and identity secrets never enter it, and it has no shared folder, no Docker socket, and no guest API (`security.devlxd=false`).
Production runs the runner in a dedicated VM. Inside it, nsjail restricts programs through namespaces, seccomp, cgroup v2 and no network. The VM receives no database, mail, storage or identity secrets, shared directories or Docker socket. TLS and a token protect the API; network ACLs restrict access and guest-initiated connections.
`make -C deploy check-runner-vm` checks the VM script without LXD. On the app host, `make -C deploy runner-vm-check` checks the running VM and `make -C deploy runner-vm-a16` runs the hostile-program suite in it. These checks do not cover vulnerabilities of the kernel, QEMU, KVM, nsjail, or LXD, side channels, or the host itself: the `lxd` group is equivalent to root on the host, and its members can open a root shell in the guest through the LXD agent. The token is a shared secret without automatic rotation: to replace it, remove `api-token` from the secrets directory, run `runner-vm-secrets` and `runner-vm-install`, and give the backend the new value. The VM has no monitoring yet.
`make -C deploy check-runner-vm` checks configuration without starting a VM. Live VM and isolation checks run separately as described in [DEPLOYMENT.md](DEPLOYMENT.md) and [TESTING.md](TESTING.md). They do not establish that the kernel, hypervisor or nsjail has no vulnerabilities. A privileged development container is not the production boundary; automatic token rotation and VM monitoring are not connected yet.