internal_resolve

package
v1.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package internal_resolve exposes octo-server's identity graph over an authenticated internal HTTP surface for consumers that lack a user token (e.g. octo-drive's docs-auto-mount polling loop).

Only endpoints strictly needed by internal services live here. Each endpoint is gated by a distinct X-Internal-Token so credentials never span services; see internalAuthMiddleware for the fail-closed + constant-time compare check.

Index

Constants

View Source
const (
	// DriveInternalTokenEnv gates the drive-facing resolve endpoints. The
	// docs-auto-mount polling loop in octo-drive presents this token in the
	// X-Internal-Token header on every call.
	//
	// Exported so main.go can feed the value into
	// cardactiondispatch.Registry.ValidateNotifyTokenExclusions alongside the
	// other three fixed internal-token envs, without a second literal string
	// drifting out of sync with this constant.
	DriveInternalTokenEnv = "OCTO_DRIVE_INTERNAL_TOKEN"
)

Environment variable names and shared constants.

A distinct token per internal consumer is deliberate: it lets us revoke / rotate one consumer without disturbing the rest, and shrinks the blast radius if any single token leaks. See modules/notify/api.go:96-98 and modules/bot_mention/config.go:142-145 for the same "must differ from sibling tokens" hardening.

The strongest cross-capability guard lives in main.go's cardactiondispatch.Registry.ValidateNotifyTokenExclusions call, which is the single place that also sees the *dynamic* per-route notify tokens and callback secrets loaded from OCTO_CARD_ACTION_ROUTES. This module contributes OCTO_DRIVE_INTERNAL_TOKEN to that global check so a route-scoped token can never accidentally inherit the resolve-bot-owner capability, and vice versa. Locally we only guard the four fixed internal-token envs against intra-set collision (drive vs notify / docs-notify / bot-mention).

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	log.Log
	// contains filtered or unexported fields
}

Module is the module handle registered with the wkhttp router. Field names match the octo-server convention (see modules/bot_mention/api.go:32).

func New

func New(ctx *config.Context) *Module

New wires the module against the repository-wide botidentity.Resolver. The token is loaded from the environment at construction time; if it is unset, too short, or collides with a sibling internal token, the module logs the reason and refuses all requests (fail-closed via internalAuthMiddleware).

ctx is retained so Route can construct the rate-limit Redis client the same way modules/user/api.go:196 does — deferring that construction to Route matches the convention across the repository and gives us access to the runtime config without threading extra plumbing.

func (*Module) Route

func (m *Module) Route(r *wkhttp.WKHttp)

Route mounts internal endpoints under /v1/internal, gated by X-Internal-Token. Route mounts internal endpoints under /v1/internal, gated by X-Internal-Token. The path shape (`/v1/internal/user/resolve-bot-owner`) matches issue #710.

Middleware **execution order** on this route (matters):

  1. per-endpoint IP strict rate limit — MUST run FIRST so IP-abusive traffic never reaches the token-compare (Redis Lua) or the DB path. Aligns with `.octospec/rules/rate-limit.md` (load_bearing:true) and with the repository convention for un-user-authed sensitive routes (login / register / sms / bot_register / bot_heartbeat).
  2. internalAuthMiddleware — X-Internal-Token constant-time compare + fail-closed on unset.

Both middlewares are mounted on the **concrete POST route**, NOT the group. Gin combines group handlers ahead of route handlers, so putting auth on the group and ipLimit on the route would give an execution order of `auth → ipLimit → handler` — a missing / invalid token would then abort before ever consuming the strict-IP bucket, and token-probing traffic would fall back to the wider global bucket. This exact ordering trap was flagged by PR #711 review round 4 (yujiawei P1 middleware order).

The concrete POST also anchors both middlewares to a single route: a future second endpoint added under the same /v1/internal group makes an explicit choice about its own auth + limiter rather than silently inheriting this one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址