Skip to content

gitgate v0.1.0

Latest

Choose a tag to compare

@github-actions github-actions released this 29 Nov 18:18
· 2 commits to main since this release
e7e4631

The first release.

  • A git smart-HTTP gateway for GitHub (github.com or GitHub Enterprise Server): info/refs and git-upload-pack /
    git-receive-pack, streamed in both directions, with the upstream credential added by gitgate. Git LFS and (opt-in) a
    GitHub API leg are proxied too; web pages are not.
  • Two modes, chosen by the URL (/managed/<owner>/<repo>.git, /unmanaged/...; a URL that names none takes
    GITGATE_DEFAULT_MODE, unmanaged unless set). Managed does everything the credential may. Unmanaged fetches and pushes
    ordinary branches: its commands are read before a byte goes upstream, and a push that touches the default branch, a protected
    branch (main, master, production, release/*, releases/* by default), a tag or anything outside refs/heads/ is
    refused whole, with git's own per-ref report.
  • Credentials: a personal access token (GITGATE_TOKEN or a file re-read every minute) or a GitHub App, whose installation
    tokens are minted and renewed in memory.
  • Callers are admitted per mode by address (IPs and CIDRs, with X-Forwarded-For honoured only from trusted proxies) or by a
    secret sent as a Basic password or Bearer token. With nothing configured nobody is admitted.
  • /healthz, /readyz and a small Prometheus /metrics.
  • A static musl Docker image on distroless, and release builds (Linux x86_64 and aarch64, macOS arm64 and x86_64) with a
    signed SHA256SUMS and an install.sh.

Added since the pre-release builds

  • Named callers (GITGATE_CALLERS_FILE): one identity per agent or machine, recognised by a SHA-256 of its secret and/or
    its address, with the modes it may use. Revoke one by removing it or setting revoked = true. The mode-wide *_FROM and
    *_SECRET settings keep working as callers named managed and unmanaged. Caller names appear in logs, metrics and the
    audit log.

  • The real push outcome: gitgate reads the upstream's report-status (plain or side-band) from a copy of the response as it
    streams, so a ref GitHub rejects (branch protection, rulesets, push protection) is logged and counted as rejected instead of
    as a 200.

  • Push audit log: one JSON record per push (caller, address, mode, repository, each ref old -> new, gitgate's decision, the
    upstream's per-ref result, bytes, duration, request id), in the log under gitgate::audit and optionally in
    GITGATE_AUDIT_FILE and a signed GITGATE_AUDIT_WEBHOOK. Managed pushes are recorded too.

  • Request ids: X-Request-Id is accepted when plain, generated otherwise, returned, and logged.

  • Refusals say what to do instead, and a push refused because the default branch could not be learned is now refused in
    git's own per-ref report rather than with a bare 503.

  • A ref advertisement refused with 401/404 right after an installation token was minted is asked again (0.5, 1, 2, 4 s,
    minting anew once), because GitHub can take a few seconds to honour a new token.

  • GitHub App settings GITGATE_APP_PERMISSIONS_FETCH, GITGATE_APP_PERMISSIONS_UNMANAGED,
    GITGATE_APP_PERMISSIONS_MANAGED (the permissions of each purpose's token) and GITGATE_APP_TOKEN_SCOPE (repository,
    the default, or installation for organizations that hit GitHub's mint rate limit). gitgate refuses to start if
    GITGATE_APP_PERMISSIONS_UNMANAGED names workflows.

  • Agent branch allowlist (GITGATE_UNMANAGED_BRANCHES, per caller branches): e.g. agent/{caller}/*; fails closed.

  • Repository allowlists per mode (GITGATE_MANAGED_REPOS, GITGATE_UNMANAGED_REPOS) and per caller (repos); a
    repository outside the list answers 404.

  • Shallow pushes are accepted in unmanaged mode (shallow lines before the commands), so --depth 1 clones can push.

  • Branch ownership (GITGATE_UNMANAGED_BRANCH_OWNERSHIP, GITGATE_STATE_DIR): a branch is claimed by the caller whose
    push creates it, atomically and before the push is forwarded; other callers cannot update it. State is an embedded redb file.

  • GITGATE_UNMANAGED_ALLOW_DELETES=own: deletes only of the caller's own branches.

  • Read-only switch for unmanaged pushes (GITGATE_UNMANAGED_READ_ONLY, per caller read_only).

  • Report-only rules (GITGATE_POLICY_EVALUATE): new rules log and count would-be refusals without refusing.

  • Per-caller rate limits (GITGATE_RATE_LIMIT, GITGATE_RATE_BURST, per caller rate_per_minute): 429 with
    Retry-After.

  • The GitHub API leg (GITGATE_API_LEG=true): /api/v3/... and /api/graphql, laid out as GitHub Enterprise Server,
    so stock gh works through gitgate (GH_HOST, GH_ENTERPRISE_TOKEN; verified with gh 2.106.0 gh pr create). Unmanaged
    callers may read their repositories, open draft pull requests from branches they may push, comment, and edit their own
    pull requests, with App tokens pinned to the repository that never write contents or workflows; GraphQL is parsed
    (fragments, variables) and checked operation by operation. Managed callers pass through. Writes are audited
    ("kind":"api"). The token <secret> authorization scheme is accepted for callers.

  • Reload on SIGHUP: .env, the callers file and the TLS files are read again and applied to new requests (revoke a
    caller, switch unmanaged pushes off, change policy) without a restart; caches, metrics, buckets and the ledger carry over.

  • Approve-then-repush holds (GITGATE_HOLDS, GITGATE_HOLD_RULES): an unmanaged push refused by a holdable rule
    (protected branches by default) gets a hold id bound to the exact update; a managed caller approves it with
    POST /holds/<id>/approve and the same push then lands once.

  • Richer metrics: request and upstream latency histograms by mode and service, bytes up and down, upstream status
    classes, token mints and failures, default-branch cache hits, and GitHub's remaining rate limit as a gauge.

  • Fetch cache (GITGATE_CACHE_DIR, GITGATE_CACHE_MAX_BYTES): a bare mirror per repository serves clones and fetches
    (protocol v0/v1 and v2, shallow, gzipped requests) through a local git upload-pack. Ref discovery and ls-refs still go
    upstream; before each fetch gitgate asks the upstream for the branches and tags, updates the mirror when they differ (one
    git fetch --prune at a time per repository), and serves only wants the upstream just advertised. Anything else, and any
    failure, goes upstream as before. Least recently used mirrors are evicted over the size limit. Needs git on PATH
    (a new cache Dockerfile target has it; the default image is unchanged). New counters gitgate_cache_requests_total,
    gitgate_cache_updates_total, gitgate_cache_update_milliseconds_total, gitgate_cache_evictions_total.

  • Built-in TLS (GITGATE_TLS_CERT_FILE, GITGATE_TLS_KEY_FILE): rustls, HTTP/2 by ALPN, certificate reloaded when the
    files change, handshakes in each connection's own task.

  • Git LFS: the batch API (POST .../info/lfs/objects/batch) and the locks API are proxied with gitgate's credential and
    admitted like git, so LFS repositories clone and push through gitgate. A download takes the fetch token, an upload and
    the locks API the mode's push token. In unmanaged mode, GITGATE_UNMANAGED_LFS_UPLOAD=false refuses uploads and
    GITGATE_LFS_MAX_OBJECT_BYTES refuses objects over a size, each with a message git-lfs prints. Each upload batch is an
    audit record (kind: "lfs_batch"); gitgate_lfs_batches_total{mode,operation,decision} counts batches.
    GITGATE_LFS_PROXY_TRANSFERS=true also streams the object transfers through gitgate (/lfs-transfer/<id>), for clients
    that can reach only gitgate.

  • Pack content policy (GITGATE_CONTENT_POLICY, off by default): an unmanaged push is spooled to disk
    (GITGATE_SPOOL_DIR, at most GITGATE_SPOOL_MAX_BYTES), indexed against a bare mirror of the repository, and its new
    commits checked before it goes upstream: no changes to GITGATE_CONTENT_DENY_PATHS (default .github/workflows/*,
    .github/actions/*; a merge counts only what differs from every parent), only GITGATE_CONTENT_ALLOW_PATHS when set, a
    GITGATE_CONTENT_REQUIRE_TRAILER on every commit, no blob over GITGATE_CONTENT_MAX_BLOB_BYTES. Refusals are in git's
    per-ref report and say what to do; a push that cannot be checked is refused; GITGATE_POLICY_EVALUATE=content runs it
    report-only. Needs git on PATH. New metrics gitgate_content_checks_total{result} and
    gitgate_content_check_milliseconds_total.

Breaking, for deployments of the pre-release builds

  • Unmanaged mode refuses branch deletes by default. GITGATE_UNMANAGED_ALLOW_DELETES now defaults to false (it was
    true). Set it to true for the old behaviour, or own to let agents delete only their own branches.

Changed since the pre-release builds

  • .env is no longer copied into the process environment; it is read as an overlay (the environment still wins), so it can
    be read again on SIGHUP. GITGATE_LOG set only in .env now works too.

  • GitHub App tokens are now per repository and per purpose by default. Each token names the one repository it is for and
    only its purpose's permissions: fetches {"contents":"read","metadata":"read"}, unmanaged pushes
    {"contents":"write","metadata":"read"} (no workflows, so GitHub itself refuses an unmanaged push that touches
    .github/workflows/), managed pushes GITGATE_APP_PERMISSIONS_MANAGED, else GITGATE_APP_PERMISSIONS, else everything
    the installation has. GITGATE_APP_PERMISSIONS therefore no longer narrows fetches and unmanaged pushes. Tokens are
    cached per repository and purpose (at most 2,000) and a slow mint no longer holds up other repositories. Check before
    upgrading:
    the App must still have the permissions requested, at least Contents read/write and Metadata read (and
    whatever the managed setting names); expect up to three mints per active repository per hour instead of one per
    installation. A repository the App cannot reach is now a 404 before anything goes upstream. A personal access token is
    unchanged: it cannot be narrowed (a fine-grained token without the Workflows permission gives the same workflows
    guarantee).

  • /metrics: gitgate_requests_total gains a caller label; gitgate_pushes_total gains caller and outcome labels;
    gitgate_refused_callers_total gains mode. New: gitgate_ref_updates_total, gitgate_token_retries_total,
    gitgate_audit_dropped_total. Every counter has # HELP/# TYPE lines.

  • A known caller asking for a mode it may not use gets 403 (not 401).