Restrict runtime receipts to bridge token
This commit is contained in:
parent
4468591d6c
commit
f702a708d9
5 changed files with 106 additions and 20 deletions
|
|
@ -74,6 +74,7 @@ For the full staged roadmap, including contribution points, revenue share, patro
|
|||
- set `Bridge:LocalBridgeToken` to allow the transitional local bridge actuator to register and receipt governed actions through `/bridge/actions/*`
|
||||
- set `BIFROST_BRIDGE_BASE_URL` and `BIFROST_BRIDGE_TOKEN` when `tools/bifrost-bridge.mjs` should round-trip every action through the app ledger before mutating GitHub, Discord, or Reddit
|
||||
- the same bridge URL/token pair lets `tools/dispatch-agent-requests.mjs` record `/dispatch/runs/*` receipts for launched Codex work, so Bifrost keeps a live run trail even when a turn fails
|
||||
- those hosted runtime receipt lanes are local-bridge-owned writes, not ordinary member-session writes: `/dispatch/runs/*`, `/transport/receipts`, and `/governance/receipts` now require the configured bridge token and do not inherit browser-user identity into agent activity rows
|
||||
- Bifrost-dispatched Codex turns also inject Bifrost-owned GitHub gates through environment config: `git` and `gh` wrappers are prepended in `PATH`, a `pre-push` hook backs up raw Git pushes, raw `git push` stays blocked, and direct `gh` usage is limited to explicit read-only commands unless `tools/bifrost-bridge.mjs` authorizes the bridge-owned GitHub write path
|
||||
- dispatched Codex turns now default to `workspace-write` instead of full machine access, and the app-server sandbox policy disables network access unless the operator explicitly chooses a broader sandbox
|
||||
- `tools/agent-transport.mjs` also uses that bridge configuration to record `/transport/receipts` entries for queue, claim, release, and close events on the request lane
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ node .\tools\agent-transport.mjs apply-snapshot --in E:\tmp\bifrost-agent-transp
|
|||
|
||||
Dispatch receipts should use Bifrost's own public persona in the Bifrost governance channel. `tools/dispatch-agent-requests.mjs` reads `BIFROST_DISCORD_CHANNEL_ID` or `DISCORD_BIFROST_CHANNEL_ID` for the receipt target, uses persona name `Bifrost`, and defaults the persona avatar to the public `src/Bifrost.Web/wwwroot/img/bifrost-profile.png` raw GitHub URL unless `BIFROST_DISCORD_PERSONA_AVATAR_URL` or `DISCORD_PERSONA_AVATAR_URL_BIFROST` overrides it. Receipt text must lead with the concrete repo and work title, not a generic "recent consensus" summary, and must not expose request ids, workspace paths, log paths, or other debugging debris in Discord.
|
||||
The dispatcher now tags those Discord receipts with the Bifrost request id as bridge provenance, and dispatched Codex turns inherit default bridge provenance environment variables so any explicit `tools/bifrost-bridge.mjs` crossing inside the turn can land on the same request trail without hand-carried flags. When `BIFROST_BRIDGE_BASE_URL` and `BIFROST_BRIDGE_TOKEN` are configured, the dispatcher also records `/dispatch/runs/*` receipts in the hosted app so Bifrost keeps a first-class run ledger for launch, completion, cancellation, and failure.
|
||||
Those hosted runtime receipt endpoints are owned by the local bridge token, not by ordinary member sessions. A signed-in member can govern work and request crossings, but they cannot POST `/dispatch/runs/*`, `/transport/receipts`, or `/governance/receipts` without the configured bridge token and pretend to be the worker runtime.
|
||||
Those dispatched turns also inherit Bifrost-owned GitHub gates through environment config. `git` and `gh` wrappers are prepended in `PATH`, a `pre-push` hook backs up raw Git pushes, raw `git push` stays blocked inside dispatched work even with `--no-verify`, and direct `gh` usage is limited to explicit read-only commands unless the bridge explicitly authorizes the GitHub mutation it owns.
|
||||
Those dispatched turns also lock the local-only recovery hatches. `--allow-ungated-github`, `BIFROST_ALLOW_UNGATED_GITHUB`, `--allow-unreceipted-activity`, and `BIFROST_ALLOW_UNRECEIPTED_ACTIVITY` are refused inside dispatched work so an agent cannot quietly downgrade itself out of Bifrost's gate or receipt trail.
|
||||
Those dispatched turns also scrub ambient GitHub auth state from the child environment before the worker starts. `GH_TOKEN` and `GITHUB_TOKEN` are cleared, `gh` gets an isolated config directory, `git` gets an isolated global config plus non-interactive credential settings, and terminal prompts are disabled. That does not prove every imaginable direct-HTTP escape is impossible, but it removes the normal ambient credential path from dispatched work.
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ The hosted app also exposes a governance activity receipt ledger:
|
|||
|
||||
This covers the other side of the swarm's work: topic opens, comments, approvals, and promotions to dispatch. The topic and comment documents are still the governance substrate. The hosted receipt row is the Bifrost-side witness that an agent or operator performed the governance action.
|
||||
|
||||
These runtime receipt lanes are not generic member write surfaces. In the current machine, `/dispatch/runs/*`, `/transport/receipts`, and `/governance/receipts` are owned by the configured local bridge token. Active members may govern and request bridge actions through the app, but they may not mint worker-history rows directly through a browser session and impersonate runtime activity.
|
||||
|
||||
Current gate behavior:
|
||||
|
||||
- active Bifrost members may request bridge actions from an authenticated app session
|
||||
|
|
|
|||
|
|
@ -481,18 +481,16 @@ var dispatchRuns = app.MapGroup("/dispatch/runs");
|
|||
dispatchRuns.MapPost("/start", async (
|
||||
HttpRequest request,
|
||||
AgentDispatchRunStartRequest command,
|
||||
ICurrentBifrostActorAccessor actorAccessor,
|
||||
AgentDispatchRunService agentDispatchRunService,
|
||||
IOptions<BridgeOptions> bridgeOptions,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var actor = await actorAccessor.GetAsync(cancellationToken);
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value) && !actor.IsActiveMember)
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value))
|
||||
{
|
||||
return Results.Unauthorized();
|
||||
}
|
||||
|
||||
var result = await agentDispatchRunService.StartAsync(command, actor.UserAccount?.Id, cancellationToken);
|
||||
var result = await agentDispatchRunService.StartAsync(command, null, cancellationToken);
|
||||
return JsonResult(result, appJsonSerializerOptions, StatusCodes.Status202Accepted);
|
||||
});
|
||||
|
||||
|
|
@ -500,18 +498,16 @@ dispatchRuns.MapPost("/{id:guid}/complete", async (
|
|||
Guid id,
|
||||
HttpRequest request,
|
||||
AgentDispatchRunCompletionRequest command,
|
||||
ICurrentBifrostActorAccessor actorAccessor,
|
||||
AgentDispatchRunService agentDispatchRunService,
|
||||
IOptions<BridgeOptions> bridgeOptions,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var actor = await actorAccessor.GetAsync(cancellationToken);
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value) && !actor.IsActiveMember)
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value))
|
||||
{
|
||||
return Results.Unauthorized();
|
||||
}
|
||||
|
||||
var result = await agentDispatchRunService.CompleteAsync(id, command, actor.UserAccount?.Id, cancellationToken);
|
||||
var result = await agentDispatchRunService.CompleteAsync(id, command, null, cancellationToken);
|
||||
return result is null
|
||||
? Results.NotFound()
|
||||
: JsonResult(result, appJsonSerializerOptions);
|
||||
|
|
@ -521,18 +517,16 @@ dispatchRuns.MapPost("/{id:guid}/fail", async (
|
|||
Guid id,
|
||||
HttpRequest request,
|
||||
AgentDispatchRunFailureRequest command,
|
||||
ICurrentBifrostActorAccessor actorAccessor,
|
||||
AgentDispatchRunService agentDispatchRunService,
|
||||
IOptions<BridgeOptions> bridgeOptions,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var actor = await actorAccessor.GetAsync(cancellationToken);
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value) && !actor.IsActiveMember)
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value))
|
||||
{
|
||||
return Results.Unauthorized();
|
||||
}
|
||||
|
||||
var result = await agentDispatchRunService.FailAsync(id, command, actor.UserAccount?.Id, cancellationToken);
|
||||
var result = await agentDispatchRunService.FailAsync(id, command, null, cancellationToken);
|
||||
return result is null
|
||||
? Results.NotFound()
|
||||
: JsonResult(result, appJsonSerializerOptions);
|
||||
|
|
@ -543,18 +537,16 @@ var transportReceipts = app.MapGroup("/transport/receipts");
|
|||
transportReceipts.MapPost("", async (
|
||||
HttpRequest request,
|
||||
AgentTransportReceiptRequest command,
|
||||
ICurrentBifrostActorAccessor actorAccessor,
|
||||
AgentTransportReceiptService agentTransportReceiptService,
|
||||
IOptions<BridgeOptions> bridgeOptions,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var actor = await actorAccessor.GetAsync(cancellationToken);
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value) && !actor.IsActiveMember)
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value))
|
||||
{
|
||||
return Results.Unauthorized();
|
||||
}
|
||||
|
||||
var result = await agentTransportReceiptService.RecordAsync(command, actor.UserAccount?.Id, cancellationToken);
|
||||
var result = await agentTransportReceiptService.RecordAsync(command, null, cancellationToken);
|
||||
return JsonResult(result, appJsonSerializerOptions, StatusCodes.Status202Accepted);
|
||||
});
|
||||
|
||||
|
|
@ -563,18 +555,16 @@ var governanceReceipts = app.MapGroup("/governance/receipts");
|
|||
governanceReceipts.MapPost("", async (
|
||||
HttpRequest request,
|
||||
GovernanceActivityReceiptRequest command,
|
||||
ICurrentBifrostActorAccessor actorAccessor,
|
||||
GovernanceActivityReceiptService governanceActivityReceiptService,
|
||||
IOptions<BridgeOptions> bridgeOptions,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var actor = await actorAccessor.GetAsync(cancellationToken);
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value) && !actor.IsActiveMember)
|
||||
if (!HasValidLocalBridgeToken(request, bridgeOptions.Value))
|
||||
{
|
||||
return Results.Unauthorized();
|
||||
}
|
||||
|
||||
var result = await governanceActivityReceiptService.RecordAsync(command, actor.UserAccount?.Id, cancellationToken);
|
||||
var result = await governanceActivityReceiptService.RecordAsync(command, null, cancellationToken);
|
||||
return JsonResult(result, appJsonSerializerOptions, StatusCodes.Status202Accepted);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -396,6 +396,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
public async Task Local_bridge_token_can_record_dispatch_run_lifecycle()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var startPayload = JsonSerializer.Serialize(new
|
||||
{
|
||||
|
|
@ -447,6 +448,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
Assert.Equal(AgentDispatchRunStatus.Completed, savedRun.Status);
|
||||
Assert.Equal("req_dispatch_123", savedRun.RequestId);
|
||||
Assert.Equal("turn_1", savedRun.TurnId);
|
||||
Assert.Null(savedRun.StartedByUserAccountId);
|
||||
Assert.Contains(dbContext.AuditEvents, x => x.EntityType == nameof(AgentDispatchRun) && x.Action == "agent-dispatch.completed");
|
||||
}
|
||||
|
||||
|
|
@ -454,6 +456,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
public async Task Local_bridge_token_can_record_dispatch_run_failure()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var startPayload = JsonSerializer.Serialize(new
|
||||
{
|
||||
|
|
@ -503,6 +506,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
|
||||
Assert.Equal(AgentDispatchRunStatus.Failed, savedRun.Status);
|
||||
Assert.Equal("Codex app-server thread/start returned no thread id.", savedRun.Error);
|
||||
Assert.Null(savedRun.StartedByUserAccountId);
|
||||
Assert.Contains(dbContext.AuditEvents, x => x.EntityType == nameof(AgentDispatchRun) && x.Action == "agent-dispatch.failed");
|
||||
}
|
||||
|
||||
|
|
@ -510,6 +514,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
public async Task Local_bridge_token_can_record_transport_receipt()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
|
|
@ -542,6 +547,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
|
||||
Assert.Equal("Claimed", savedReceipt.ActivityKind.ToString());
|
||||
Assert.Equal("bifrost-dispatcher", savedReceipt.ActorName);
|
||||
Assert.Null(savedReceipt.ActorUserAccountId);
|
||||
Assert.Contains(dbContext.AuditEvents, x => x.EntityType == nameof(AgentTransportReceipt) && x.Action == "agent-transport.claimed");
|
||||
}
|
||||
|
||||
|
|
@ -549,6 +555,7 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
public async Task Local_bridge_token_can_record_governance_receipt()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
|
|
@ -582,9 +589,94 @@ public sealed class PlatformEndpointsTests : IClassFixture<TestWebApplicationFac
|
|||
|
||||
Assert.Equal("TopicPromoted", savedReceipt.ActivityKind.ToString());
|
||||
Assert.Equal("nibu", savedReceipt.ActorName);
|
||||
Assert.Null(savedReceipt.ActorUserAccountId);
|
||||
Assert.Contains(dbContext.AuditEvents, x => x.EntityType == nameof(GovernanceActivityReceipt) && x.Action == "governance.topic-promoted");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Active_member_session_cannot_record_dispatch_run_without_local_bridge_token()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
requestId = "req_dispatch_member_123",
|
||||
targetRepoName = "Bifrost",
|
||||
targetRepositoryFullName = "GameCult/Bifrost",
|
||||
targetAgentIdentity = "nibu",
|
||||
launchMode = "app-server",
|
||||
workerProcessId = 4242,
|
||||
threadId = "thread_member",
|
||||
turnId = "turn_member",
|
||||
logPath = "E:/Projects/Bifrost/.bifrost/agent-dispatch/req_dispatch_member_123/codex.log",
|
||||
resultPath = "E:/Projects/Bifrost/.bifrost/agent-dispatch/req_dispatch_member_123/result.json",
|
||||
note = "Should be rejected without the local bridge token."
|
||||
});
|
||||
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, "/dispatch/runs/start");
|
||||
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
|
||||
|
||||
using var response = await client.SendAsync(request);
|
||||
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Active_member_session_cannot_record_transport_receipt_without_local_bridge_token()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
requestId = "req_transport_member_123",
|
||||
title = "Member should not mint runtime receipts",
|
||||
targetRepoName = "Bifrost",
|
||||
targetRepositoryFullName = "GameCult/Bifrost",
|
||||
targetAgentIdentity = "nibu",
|
||||
activityKind = "Claimed",
|
||||
status = "claimed",
|
||||
actorName = "test-admin",
|
||||
note = "Should be rejected without the local bridge token."
|
||||
});
|
||||
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, "/transport/receipts");
|
||||
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
|
||||
|
||||
using var response = await client.SendAsync(request);
|
||||
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Active_member_session_cannot_record_governance_receipt_without_local_bridge_token()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
_ = await client.GetAsync("/App");
|
||||
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
topicId = "topic_member_123",
|
||||
commentId = "comment_member_123",
|
||||
dispatchRequestId = "req_transport_member_123",
|
||||
title = "Member should not mint governance runtime receipts",
|
||||
jurisdictionRepoName = "Bifrost",
|
||||
jurisdictionAgentIdentity = "nibu",
|
||||
activityKind = "TopicPromoted",
|
||||
actorKind = "member",
|
||||
actorName = "test-admin",
|
||||
note = "Should be rejected without the local bridge token."
|
||||
});
|
||||
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, "/governance/receipts");
|
||||
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
|
||||
|
||||
using var response = await client.SendAsync(request);
|
||||
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
}
|
||||
|
||||
private static string ComputeSignature(string secret, string payload)
|
||||
{
|
||||
using var hasher = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
|
||||
|
|
|
|||
Loading…
Reference in a new issue