Skip to content

Latest commit

 

History

History
191 lines (126 loc) · 17.6 KB

CONTRIBUTING.md

File metadata and controls

191 lines (126 loc) · 17.6 KB

Contributing to FleetMDM

Thank you for your interest in contributing to FleetMDM — Flamingo's fork of the open-source Fleet device management platform, extended for the OpenFrame unified MSP ecosystem. This document explains how to set up a development environment, the branch/commit/PR workflow, code style, testing, and where to report a security issue.

The repository ships a Go backend service (cmd/fleet), the fleetctl CLI, the orbit/fleetd agent, a React/TypeScript web console (frontend/), and an Enterprise Chrome-extension agent (ee/fleetd-chrome). Per the organization's code graph, FleetMDM publishes a wide set of Go modules and npm packages (including github.com/fleetdm/fleet/v4, fleetctl, and fleetd-for-chrome); no downstream consumer is currently recorded, but graph coverage is partial, so that is not proof nothing depends on these artifacts.

Community First

This repository does not use GitHub Issues or GitHub Discussions. Day-to-day coordination, questions, and discussion happen on the OpenMSP Slack community:

Open a pull request directly against flamingo-stack/fleetmdm/pulls rather than filing an issue first.

Setting Up a Development Environment

Full setup instructions live in the development docs rather than being duplicated here:

  • Development Overview — the map of the whole Development section, including how the Go backend, React frontend, and Enterprise subprojects fit together.
  • Environment Configuration — required tooling (Go, Node/Yarn, Docker), IDE recommendations (VS Code configuration, debug targets), environment variables, and pre-commit hooks.
  • Local Development — cloning the repository, bringing up MySQL/Redis/mail-catcher services via Docker Compose, building and running the fleet server and fleetctl, running the frontend/Storybook, hot-reload patterns, and debugging with Delve.

Before any of that, review the Getting Started guides for baseline tooling and an initial run-through:

For how the components relate to each other architecturally, see Architecture.

This Is a Tracked Fork

FleetMDM is synced weekly from upstream fleetdm/fleet (a scheduled workflow merges upstream/main into a sync/upstream-main branch and opens a pull request). Because of this, any edit to a file that originated upstream must be wrapped in sentinel comments so the next upstream sync can locate and re-apply Flamingo-specific logic:

// >>> OPENFRAME(<slug>): <why> — openframe/docs/<doc>.md
... your fork-specific change ...
// <<< OPENFRAME(<slug>)

This is an enforced, active review rule (FLEETMDM-001) covering **/*.go, **/*.yaml, and **/*.tpl. Real examples of the pattern live in cmd/fleet/cron_registration.go, cmd/fleet/openframe_windows_wstep.go, and client/orbit_client.go. Net-new, fork-only code under paths like server/service/openframe/ is exempt — it never existed upstream, so there is nothing to reconcile.

A pull request that edits a shared upstream file without these sentinels will be rejected by the automated reviewer.

Development Workflow

Branches

There is no single enforced branch-naming scheme documented in this repository, but existing conventions are worth following for consistency:

  • Automated upstream sync uses a sync/upstream-main branch.
  • The documentation pipeline uses a code-documentation/ branch prefix for its own generated pull requests — do not hand-author branches under this prefix.
  • Branches whose head repository is a fork (not flamingo-stack/fleetmdm itself) are excluded from several automated workflows (code graph, code review), so contributions from forks should still target main through a normal pull request from your fork.

A descriptive, slash-namespaced branch name that states the area and intent (for example, a fix under the MDM stack, or a change to the vulnerability pipeline) is the most useful convention given the size of this codebase (cmd/, server/, ee/, orbit/, frontend/, android/).

Opening a Pull Request

  1. Fork or branch from main and make your change.
  2. Keep upstream-originated files wrapped in OPENFRAME(...) sentinels as described above; net-new OpenFrame-only code does not need them.
  3. Run the relevant local checks before pushing (see Testing below) — Go lint/tests, frontend lint/tests, or Helm lint, depending on what you touched.
  4. Push and open a pull request against main at flamingo-stack/fleetmdm/pulls.
  5. CI runs automatically:
    • Fleet Test detects which parts of the tree changed and conditionally runs a client test job (Go tests, cross-compiling orbit for macOS/Windows), a server test job (server-side Go tests, a GoReleaser snapshot build, and a Trivy image scan), and a Helm template job. An aggregating job fails the pull request if any of these fail or are cancelled.
    • Flamingo Code Review provides an AI-assisted review. On open/ready-for-review/reopen it posts an invitation comment rather than reviewing automatically; a maintainer (or you, with write access) starts the first pass by checking its checkbox, commenting @flamingo-review, or applying the flamingo-review label. Commenting @flamingo-review full re-reviews the whole cumulative diff instead of only the incremental delta since the last reviewed commit.
  6. Address review feedback by pushing additional commits to the same branch; required reviewers (see CODEOWNERS below) are requested automatically.
  7. Once the aggregated CI check is green and required reviewers have approved, the PR can be merged. A push to main builds and publishes the fleet binary image and the charts/fleet Helm chart automatically — so changes to server/, cmd/, ee/, tools/, the root Dockerfile, or .goreleaser.yml ship on merge.

Required Reviewers (CODEOWNERS)

The root CODEOWNERS file and .github/CODEOWNERS define required reviewers by path, on a last-match-wins basis — for example, Go sources and /server///cmd///orbit/ require the Go team, /frontend/ requires the frontend team, and /infrastructure/, /charts/, /terraform/ require the infra reviewers. If your change touches one of these paths, expect GitHub to request the matching reviewer(s) automatically — do not bypass this by routing the change through an unrelated path.

Commits

No commit-template or commit-lint tooling is enforced in this repository's CI. Write commits that:

  • Use a short, present-tense summary line describing the change.
  • Reference the relevant subsystem when it helps reviewers scope the diff (server/mdm/apple, orbit, frontend, ee/maintained-apps, etc.).
  • Explain why in the body for anything non-obvious — particularly for OPENFRAME(...)-wrapped changes, where the sentinel's own <why> clause should be echoed or expanded on in the commit body so a future upstream-sync author understands the deviation from upstream Fleet.
  • Are scoped to one logical change; prefer several focused commits over one sprawling commit when a change spans both a fork-only file and an upstream-originated file.
  • Avoid committing secrets — gitleaks runs as a pre-commit hook and will also be caught by CI if bypassed locally.

Squashing is a repository/maintainer decision at merge time; keep individual commits reviewable regardless of the final merge strategy.

Code Style and Conventions

Go

  • Formatting and linting are enforced by .golangci.yml (golangci-lint v2 config) at the repository root, covering gofmt, govet, errcheck, staticcheck, revive, gosec, gocritic, ineffassign, unconvert, unused, rowserrcheck, sqlclosecheck, nilnesserr, and depguard.
  • depguard forbids importing github.com/pkg/errors (use ctxerr where a context.Context is available, or stdlib errors.New / fmt.Errorf with %w) and forbids github.com/valyala/fastjson / fasttemplate.
  • forbidigo forbids bare print/println, and forbids context-less slog.Debug/Info/Warn/Error package-level calls — use a specific *slog.Logger instance with the *Context variants instead.
  • Several active, enforced rules govern server-layer Go code specifically:
    • FLEETMDM-002: inside cmd/, server/, and ee/server/, create errors with ctxerr.New(ctx, ...) / ctxerr.Wrap(...) rather than fmt.Errorf or errors.New; plain stdlib errors are acceptable only in leaf utility packages with no context available.
    • FLEETMDM-002-2: every error returned from a called function must be wrapped at the call boundary, e.g. fmt.Errorf("<short lowercase context>: %w", err) — never a bare return err.
    • FLEETMDM-004: server-side logging must use log/slog via InfoContext/ErrorContext/DebugContext with structured key-value pairs (never interpolated into the message string), with the logger threaded through function signatures, not accessed globally.
    • FLEETMDM-006-2: in cron/schedule code (cmd/fleet/cron.go and sibling files), non-fatal errors go through the local errHandler(ctx, logger, msg, err) helper; fatal errors are returned directly with fmt.Errorf wrapping. Never log.Fatal, panic, or bare fmt.Println for error reporting in a cron job.
    • FLEETMDM-007-2: each distinct phase of a long-running cron function should open its own OpenTelemetry span (tracer.Start(ctx, "<subsystem>.<phase>"), defer span.End()), record errors on the span with span.RecordError(err), and log phase timing.
  • Generated code is excluded from formatting checks (server/fleet/agent_options_generated.go).
  • errcheck has an explicit allow-list of close/flush/logging calls whose errors may be ignored; anything not on that list must have its error checked.

JavaScript / TypeScript (Frontend)

  • The root .eslintrc.js extends airbnb, plugin:jest/recommended, plugin:react-hooks/recommended, plugin:@typescript-eslint/recommended, plugin:prettier/recommended, and plugin:storybook/recommended, parsed with @typescript-eslint/parser.
  • Formatting is delegated to Prettier (.prettierrc.json at the root) via eslint-plugin-prettier.
  • Notable overrides: @typescript-eslint/no-shadow replaces the base no-shadow; @typescript-eslint/no-use-before-define replaces the base rule; camelcase is off; react/jsx-filename-extension is a warning limited to .jsx/.tsx; import/no-unresolved is case-insensitive via the webpack resolver.
  • Run npm run lint (eslint frontend --ext .js,.jsx,.ts,.tsx) and npm run prettier:check before opening a pull request that touches frontend/.
  • TypeScript compiles against tsconfig.json, targeting ES2019 with "jsx": "react" and a node-sql-parser path alias pointed at the vendored @sgress454/node-sql-parser fork.

Sails Sub-Applications (website/, ee/fleet-agent-downloader/, ee/vulnerability-dashboard/)

These Sails apps each carry their own .eslintrc (and assets/.eslintrc / views/.eslintrc overrides inside website/) with a stricter, non-airbnb rule set: 2-space indentation, single quotes, mandatory semicolons, eqeqeq, and no-undef against an explicit globals list of Sails models. If you touch one of these apps, lint with its own config, not the root one — globals and quote/semicolon rules differ intentionally between backend Sails code and browser-facing assets/ code.

Android (android/)

Kotlin code is formatted with Spotless + ktlint and linted with Detekt (run via ./gradlew check in CI, not in local builds by default). android/.editorconfig sets 4-space indentation, a 140-character line length, Android Studio's ktlint_code_style, and disables the function-naming/property-naming ktlint rules that would otherwise flag @Composable function names and uppercase TAG constants.

General Formatting

  • .editorconfig files set LF line endings, UTF-8, and trailing-newline/trailing-whitespace trimming — configure your editor to respect them.
  • .pre-commit-config.yaml wires gitleaks (secret scanning), golangci-lint, shellcheck, cpplint, eslint, pylint, RuboCop, and php-lint-all, plus end-of-file/trailing-whitespace fixers. Installing pre-commit locally catches most style and secret issues before they reach CI.

Testing

See the full Testing Guide for details on how each surface is tested and what CI runs. In short:

Surface Location Test Runner
Go server, CLI, agents cmd/, server/, ee/, client/, orbit/ Go's built-in testing package
React/TypeScript web console frontend/ Jest, via frontend/test/jest.config.js
Chrome extension agent ee/fleetd-chrome/ Jest (ESM, its own config)
Android agent android/ JUnit + Robolectric (Gradle/Jacoco)

Typical local commands:

# Run the full Go test suite
go test ./...

# Run tests for a single package, verbose, with coverage
go test -v -race -coverprofile=coverage.out ./client/...

# The orbit agent client, matching the CI client job
go test -race -coverprofile=coverage.out ./orbit/...

# Frontend Jest suite
yarn test

# CI-equivalent frontend run (no watch, with coverage)
yarn test:ci

# Chrome extension (run from inside ee/fleetd-chrome/)
cd ee/fleetd-chrome && yarn install && yarn test

Android tests run from the android/ directory with ./gradlew test (unit, Robolectric), ./gradlew jacocoTestReport (coverage), and ./gradlew connectedAndroidTest (instrumented, requires a device/emulator).

Some integration-style Go suites require a reachable MySQL instance and, for Enterprise suites, Redis — bring these up via docker-compose.yml / docker-compose-redis-cluster.yml as described in Local Development.

Writing New Tests

  • Go: co-locate _test.go files with the code under test, in the same package. Use table-driven tests with t.Run(tt.name, ...) subtests where existing code does, and prefer testify's require/assert packages. Wrap every error returned from a called function with fmt.Errorf("<context>: %w", err) at the call boundary (FLEETMDM-002-2) — this applies to test helper code as much as production code. If you are modifying a test file that originates upstream, wrap your changes in the OPENFRAME(...) sentinel pair, exactly as done in existing files like client/arch_test.go.
  • Frontend: name test files so they match the Jest testMatch pattern — the filename must end in tests.ts, tests.tsx, tests.js, or tests.jsx (not the more common *.test.tsx), or Jest will silently skip the file. Use @testing-library/react and @testing-library/user-event, and prefer msw request handlers over ad hoc fetch/axios mocking.
  • Chrome extension: new table/source modules under ee/fleetd-chrome/src/tables/ that read OS- or Chrome-API state should have a corresponding Jest test using the stubbed chrome global in that package's jest.config.js.
  • Android: unit tests go under the standard Gradle src/test/ tree with Robolectric; instrumented tests go under src/androidTest/ with Espresso/Compose. Tests that depend on a live SCEP server must be gated behind the runIntegrationTests Gradle project property, following the existing fail-fast validation pattern for scep.url/scep.challenge.

Coverage is tracked per-surface (go test -coverprofile, Jest V8 coverage, Jacoco for Android) but no workflow in this repository enforces a numeric coverage floor — treat the configured coverage collection as a reporting and local-feedback mechanism, and run the relevant suite locally before opening a pull request.

Security

See the full Security Guide for the security model, authentication/authorization patterns, and review guidelines that apply to this codebase. Key points for contributors:

  • Every new service method that reads or mutates state should open with an authorization check (svc.authz.Authorize(ctx, &fleet.X{}, fleet.ActionY)) before any datastore access.
  • Secret fields (API tokens, client secrets, SCEP passwords) must be checked against fleet.MaskedPassword on update paths so a round-tripped masked value from the UI is rejected rather than persisted as a literal mask string.
  • New string fields that end up in a query, shell command, or template should be validated with an explicit allow-list regex, not a deny-list.
  • Error strings should name the operation that failed, never echo a secret value.
  • server/service must never import ee/server/service directly, nor type-assert Service to an EE type — enterprise-only behavior is injected via EnterpriseOverrides.

To report a vulnerability, do not open a public pull request, issue, or Slack post. Follow the disclosure process in SECURITY.md, which covers scope, response timelines, and coordinated disclosure.

Where to Find More Documentation

The full documentation set — getting started guides, architecture reference, and how-to guides — is indexed at Documentation Home.


Built with 💛 by the Flamingo team