GitHub source connections (server contract)
The server connection feature is disabled by default. It provides private repository selectors and checks the current person's authorization. It does not import archives, publish repositories, run builds, add a frontend, or enable automatic deployment. Those consumers must pass their own acceptance and review gates before operators enable them.
Separate App and keys
Use a GitHub App separate from the OAuth application used for Rapadura sign-in. Configure access to selected repositories only. Grant repository Contents read and Metadata read. Enable expiring user access tokens. An installation cannot authorize a source connection if it covers all repositories, is suspended, or awaits organization approval. The current user must also have access. The user's immutable GitHub account ID must match their admitted Rapadura account. A matching login alone is insufficient.
The settings in deploy/gateway.env.example remain off/empty:
| Setting | Meaning |
|---|---|
RAPADURA_SOURCE_PUBLISH |
Off by default; gates the server connection feature, not a publication engine |
RAPADURA_SOURCE_APP_ID |
Separate GitHub App's numeric ID |
RAPADURA_SOURCE_CLIENT_ID |
That App's OAuth client ID, different from sign-in |
RAPADURA_SOURCE_CLIENT_SECRET |
That App's client secret |
RAPADURA_SOURCE_PRIVATE_KEY_FILE |
Readable PEM App key file, at most 32 KiB; protect its filesystem permissions |
RAPADURA_SOURCE_WEBHOOK_SECRET |
Dedicated lifecycle HMAC secret, at least 32 bytes |
RAPADURA_APPS_ENV_KEY |
Existing shared sealing keyring's active key, required even if the apps lane is off |
RAPADURA_APPS_ENV_KEY_PREV |
Existing previous-key ring, retained until inventory/reseal/recovery permit retirement |
Register the exact HTTPS callback RAPADURA_PUBLIC_URL/auth/github-source/callback.
The optional setup URL is RAPADURA_PUBLIC_URL/auth/github-source/setup. Its
installation query parameters are hints only and grant nothing. Neither endpoint
accepts a tenant hostname or infers authority from forwarded headers. Ordinary
Rapadura browser sign-in must already work. Incomplete source configuration fails
startup; the service never substitutes sign-in credentials.
Configure the App webhook at RAPADURA_PUBLIC_URL/hooks/github-source/lifecycle
with the dedicated secret. Supported revocations are
github_app_authorization/revoked, installation/deleted, installation/suspend,
and installation_repositories/removed. These are lifecycle notifications, not
auto-deploy hooks. The endpoint verifies X-Hub-Signature-256 against the exact
body, limits the body to 1 MiB, validates IDs and installation App ID, and dedups
the signed body's SHA-256 per App transactionally. Unsigned delivery IDs are not
used as authority. Unknown/non-revoking events do not grant or restore access.
GitHub does not authenticate a delivery timestamp in this contract: a delayed
first delivery can conservatively revoke newer consent. Fresh provider checks
still run on every use, so deduplication never substitutes for authorization.
Consent and credential lifetime
Start and consent require the current browser session, same platform origin, and
X-CSRF-Token. OAuth returns by a top-level cross-site navigation, which may omit
Origin; the fixed callback instead validates its host, current session, one-use
state, and immutable identity. State and PKCE verifier are random 32-byte values,
bound to the user and session, expire in ten minutes, and live only in bounded
server memory. Only the challenge is sent in the authorization URL. Consuming
state precedes exchange; restart loses pending state rather than resurrecting it.
There is exactly one renewable authorization per Rapadura user and source App. Its encrypted pair is shared across that person's installation/repository bindings. A binding stores immutable installation/account/repository/owner IDs; repository names are private display data. Same-ID renames can update names; transfers require explicit new human consent. Public readability is never an alternative to the selected user-and-installation intersection.
Refresh takes a durable 30-second lease before calling GitHub. Concurrent callers and other gateway instances cannot rotate copies of the same pair. Both new tokens replace the old pair in one generation/revision CAS. An expired lease, uncertain refresh result, identity mismatch, or failed persistence erases/fences the old pair and requires human reauthorization; it is never blindly retried. Expired exchange/refresh/consent leases recover the same way after restart.
Disconnect first atomically disables all of that person's bindings for the App and erases their pair. Remote grant revocation is bounded and best effort. Other people using the same installation keep their own grants. Installation removal, suspension or repository removal invalidates all bindings of that installation and advances a durable installation epoch; other installations retain their shared renewable authorization. The whole-installation removal policy is deliberately conservative.
A crash during remote disconnect leaves disconnecting. In this state, reconnect
is refused because the server cannot prove that a remote revoke has ended. There
is no automatic timeout unlock or public reconciliation API in this packet.
Operators must reconcile the provider-side revocation and stopped gateway process
before a reviewed recovery action. Do not clear or advance the row merely to
unblock the UI. All local source use fails closed in this state.
Private wire API
All routes return Cache-Control: no-store, Referrer-Policy: no-referrer, and
X-Content-Type-Options: nosniff, including authentication failures. Errors are
closed application messages: source_access_denied (403),
source_reauthorization_required (403 for expired or uncertain credentials),
source_rate_limited (429), source_provider_unavailable (503, including
disabled, timed-out or invalid provider responses), or the existing
authentication/grant/invalid-request refusal. Rate-limit delays are rounded up
to whole seconds and bounded to one day; a positive delay appears identically
in retry_after and Retry-After. An absent delay supplies neither. Raw provider
errors are not returned.
| Method and path | Body or result |
|---|---|
POST /auth/github-source/start |
{"authorization_url":"..."}; navigate to this URL, never save it |
GET /auth/github-source/callback |
One-use code/state exchange, then 303 /me |
GET /auth/github-source/setup |
Hint-only, then 303 /me |
GET /web/api/source-installations |
SourceInstallationsResponse with authorization_generation and installation id, account_id, account_login |
GET /web/api/source-installations/{installation}/repositories |
SourceRepositoriesResponse: generation, installation/account IDs, repository collection |
POST /web/api/source-connections |
SourceConsentRequest; 201 SourceConnectionView |
DELETE /web/api/source-connections |
Disconnect own App authorization, even before any repository is selected; {"authorization":"disconnected"} |
DELETE /web/api/source-connections/{connection} |
Same whole-App disconnect after checking ownership of that binding |
GET /web/api/source-connections |
SourceConnectionsResponse |
GET /web/api/source-connections/{connection}/repositories |
SourceRepositoriesResponse, restricted to the bound repository after fresh authorization |
GET /web/api/source-connections/{connection}/refs?repository_id=42&kind=branch |
SourceRefsResponse; kind is branch or tag |
GET /web/api/source-connections/{connection}/resolve?repository_id=42&kind=branch&name=main |
SourceResolution with immutable full normalized commit_sha |
Bearer GET parity exists for the last four connection reads under
/v1/source-connections. They use the normal authenticated API wrapper and require
explicit source.read for agents. There is no bearer start, consent, discovery,
or disconnect. Even an owner cannot use or disconnect another person's binding.
Consent has exactly five required, positive JS-safe integers; unknown, duplicated, null or incorrectly typed fields are refused:
{"authorization_generation":1,"installation_id":22,"installation_account_id":303,"repository_id":42,"repository_owner_id":303}
SourceConnectionsResponse contains enabled, authorization, connections.
Authorization is connected, awaiting_consent, disconnected, or
reauthorization_required. Each SourceConnectionView has id, state,
installation_id, installation_account_id, repository_id,
repository_owner_id, full_name; its state is active, disconnected, or
reauthorization_required. These are local status snapshots, not proof of current
provider access. A refreshing/exchanging row may require retrying the read after
the pending request, rather than initiating a concurrent authorization.
SourceRepositoryView contains id, owner_id, full_name, private,
default_branch. SourceRefsResponse contains connection_id, repository_id,
refs; each ref has kind, name, commit_sha. SourceResolution contains the
same connection/repository IDs plus kind, name, commit_sha.
URL-encode ref names once, including legal UTF-8, % and #.
Executable Go JSON fixtures live in internal/api/source_connections_test.go;
HTTP tests exercise these real routes. No frontend decoder ships here.
Provider enumerations are bounded complete lists (up to ten pages of 100, 2 MiB per response, 15 seconds per request, 60 seconds per list). Partial, inconsistent, over-limit or malformed enumeration fails; there is no partial-success selector. Local connection listing refuses more than 1,000 rows. An installation enumeration containing even one well-formed but ineligible installation currently fails as a whole. P3-08 must show an actionable selection/reauthorization error, not an empty complete list or a filtered success. Changing that conservative provider policy needs separate review.
Storage, keys and recovery
Schema floor 5 adds source_authorizations, source_connections,
source_installation_fences, and source_lifecycle_deliveries. Opening a floor-4
database upgrades it idempotently without granting source access. Older binaries
must refuse floor 5 before migrations; downgrade requires the pre-upgrade backup,
not deleting the schema stamp.
Only source_authorizations.nonce/blob/key_id holds sealed values. Its version-1
JSON payload explicitly serializes access token, refresh token and both expiries
at the encryption boundary. AAD is
rapadura:source:v1:<user_id>:<app_id>:<github_id>:<generation>:<revision>.
Refresh changes the credential revision; reconnect/revoke changes the authority
generation. Reseal preserves both and CASes the old ciphertext, nonce and key ID,
so it cannot overwrite a concurrently replaced pair. Installation tokens never
persist. State/verifier are not stored in SQLite, URLs, browser storage or logs.
The existing inventory, resumable reseal with --verify, backup manifest, restore
drill and retirement checks include these rows. Retained credentials still require
their readable keys at startup with sources off. Keep previous keys until
reseal and backup retention permit retirement. Feature disablement does not erase
credentials and does not make keys safe to retire. Do not put any source secrets,
connection IDs or repository metadata in public site/version/profile models,
analytics, audit receipts, or operational logs.
P3-07 integration gate
SourceService.Authorize(context.Context, *Principal, string, int64) preserves the
existing SourceAuthorizer interface. It reloads the exact current actor/token or
browser session, verifies immutable provider identity and complete selected
repository intersection, mints a narrow read-only one-repository token, and checks
durable authority/binding/installation generations before returning a server-only
AuthorizedRepository. Credentials are inaccessible in wire serialization.
CheckPublishTarget(ctx, principal, *store.Site) reloads the target and actor and
checks source.read, source.publish, and site.publish together against the
actual host, tenant, site owner, token scopes and mutation kill switch. Deleted or
changed targets fail. Default/legacy grants never gain either source action.
Token minting rejects a source.publish opt-in unless both other actions are
explicitly present; it does not silently expand a grant.
WithFinalUse(ctx, principal, proof, accept) rechecks durable generations,
credential revision, current actor, token expiry and proof age (at most 15 seconds),
then holds a process-local lifecycle read lock over the short acceptance
callback. Do not perform network, build or archive work in this callback. Reacquire
authorization after delays. This is not cross-process transaction serialization:
P3-07 must bind durable source generations to its actual Core.Publish operation
acceptance, staging reconciliation and approval execution, recheck target authority
at those points, and handle token disposal. No such integration exists yet. A
successful selector, connection, or proof is not a published version or approval.