Gate public bridge actions on Bifrost identity

This commit is contained in:
Meta Vens 2026-06-22 14:54:14 +01:00
commit 445c27978b
9 changed files with 325 additions and 0 deletions

View file

@ -415,6 +415,11 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
entity.Property(x => x.SourceKind).HasMaxLength(120);
entity.Property(x => x.SourceId).HasMaxLength(240);
entity.Property(x => x.AuthorityReference).HasMaxLength(240);
entity.Property(x => x.BifrostIdentity).HasMaxLength(160);
entity.Property(x => x.HeimdallCapabilityReference).HasMaxLength(240);
entity.Property(x => x.EpiphanyRunId).HasMaxLength(160);
entity.Property(x => x.EpiphanyLaneId).HasMaxLength(120);
entity.Property(x => x.EpiphanyAgentIdentity).HasMaxLength(160);
entity.Property(x => x.PolicyDecision).HasMaxLength(500);
entity.Property(x => x.Title).HasMaxLength(240);
entity.Property(x => x.ReceiptUrl).HasMaxLength(500);
@ -423,6 +428,8 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
entity.HasIndex(x => new { x.TargetSurface, x.ActionKind, x.Status });
entity.HasIndex(x => new { x.ActorKind, x.ActorName });
entity.HasIndex(x => new { x.SourceKind, x.SourceId });
entity.HasIndex(x => x.BifrostIdentity);
entity.HasIndex(x => x.HeimdallCapabilityReference);
entity.HasOne(x => x.ActorUserAccount)
.WithMany(x => x.BridgeActions)
.HasForeignKey(x => x.ActorUserAccountId)

View file

@ -0,0 +1,96 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bifrost.Web.Data.Migrations
{
/// <inheritdoc />
public partial class AddBridgeActionIdentityProvenance : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "BifrostIdentity",
table: "BridgeActions",
type: "character varying(160)",
maxLength: 160,
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "EpiphanyAgentIdentity",
table: "BridgeActions",
type: "character varying(160)",
maxLength: 160,
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "EpiphanyLaneId",
table: "BridgeActions",
type: "character varying(120)",
maxLength: 120,
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "EpiphanyRunId",
table: "BridgeActions",
type: "character varying(160)",
maxLength: 160,
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "HeimdallCapabilityReference",
table: "BridgeActions",
type: "character varying(240)",
maxLength: 240,
nullable: false,
defaultValue: "");
migrationBuilder.CreateIndex(
name: "IX_BridgeActions_BifrostIdentity",
table: "BridgeActions",
column: "BifrostIdentity");
migrationBuilder.CreateIndex(
name: "IX_BridgeActions_HeimdallCapabilityReference",
table: "BridgeActions",
column: "HeimdallCapabilityReference");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_BridgeActions_BifrostIdentity",
table: "BridgeActions");
migrationBuilder.DropIndex(
name: "IX_BridgeActions_HeimdallCapabilityReference",
table: "BridgeActions");
migrationBuilder.DropColumn(
name: "BifrostIdentity",
table: "BridgeActions");
migrationBuilder.DropColumn(
name: "EpiphanyAgentIdentity",
table: "BridgeActions");
migrationBuilder.DropColumn(
name: "EpiphanyLaneId",
table: "BridgeActions");
migrationBuilder.DropColumn(
name: "EpiphanyRunId",
table: "BridgeActions");
migrationBuilder.DropColumn(
name: "HeimdallCapabilityReference",
table: "BridgeActions");
}
}
}

View file

@ -279,9 +279,29 @@ namespace Bifrost.Web.Data.Migrations
.HasMaxLength(240)
.HasColumnType("character varying(240)");
b.Property<string>("BifrostIdentity")
.IsRequired()
.HasMaxLength(160)
.HasColumnType("character varying(160)");
b.Property<DateTimeOffset?>("CompletedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("EpiphanyAgentIdentity")
.IsRequired()
.HasMaxLength(160)
.HasColumnType("character varying(160)");
b.Property<string>("EpiphanyLaneId")
.IsRequired()
.HasMaxLength(120)
.HasColumnType("character varying(120)");
b.Property<string>("EpiphanyRunId")
.IsRequired()
.HasMaxLength(160)
.HasColumnType("character varying(160)");
b.Property<string>("ExternalReceiptId")
.IsRequired()
.HasMaxLength(240)
@ -291,6 +311,11 @@ namespace Bifrost.Web.Data.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("HeimdallCapabilityReference")
.IsRequired()
.HasMaxLength(240)
.HasColumnType("character varying(240)");
b.Property<Guid?>("MotionId")
.HasColumnType("uuid");
@ -361,6 +386,10 @@ namespace Bifrost.Web.Data.Migrations
b.HasIndex("ActorUserAccountId");
b.HasIndex("BifrostIdentity");
b.HasIndex("HeimdallCapabilityReference");
b.HasIndex("MotionId");
b.HasIndex("Status");

View file

@ -926,6 +926,16 @@ public sealed class BridgeAction
public string AuthorityReference { get; set; } = string.Empty;
public string BifrostIdentity { get; set; } = string.Empty;
public string HeimdallCapabilityReference { get; set; } = string.Empty;
public string EpiphanyRunId { get; set; } = string.Empty;
public string EpiphanyLaneId { get; set; } = string.Empty;
public string EpiphanyAgentIdentity { get; set; } = string.Empty;
public string PolicyDecision { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;

View file

@ -38,6 +38,11 @@ public sealed class BridgeActionService(
SourceKind = NormalizeText(normalizedRequest.SourceKind),
SourceId = NormalizeText(normalizedRequest.SourceId),
AuthorityReference = NormalizeText(normalizedRequest.AuthorityReference),
BifrostIdentity = NormalizeText(normalizedRequest.BifrostIdentity),
HeimdallCapabilityReference = NormalizeText(normalizedRequest.HeimdallCapabilityReference),
EpiphanyRunId = NormalizeText(normalizedRequest.EpiphanyRunId),
EpiphanyLaneId = NormalizeText(normalizedRequest.EpiphanyLaneId),
EpiphanyAgentIdentity = NormalizeText(normalizedRequest.EpiphanyAgentIdentity),
PolicyDecision = policy.Decision,
Title = NormalizeText(normalizedRequest.Title),
Summary = NormalizeText(normalizedRequest.Summary),
@ -200,6 +205,19 @@ public sealed class BridgeActionService(
}
}
if (RequiresExternalAccountCapability(request))
{
if (string.IsNullOrWhiteSpace(request.BifrostIdentity))
{
return BridgePolicyDecision.Reject("Persona and agent Discord/Reddit bridge actions must carry a Bifrost identity.");
}
if (string.IsNullOrWhiteSpace(request.HeimdallCapabilityReference))
{
return BridgePolicyDecision.Reject("Persona and agent Discord/Reddit bridge actions must carry a Heimdall-backed capability or account reference.");
}
}
if (request.WorkItemId is not null)
{
var workItem = await dbContext.WorkItems
@ -350,6 +368,10 @@ public sealed class BridgeActionService(
return null;
}
private static bool RequiresExternalAccountCapability(BridgeActionRequest request) =>
request.ActorKind is BridgeActorKind.Agent or BridgeActorKind.Persona &&
request.TargetSurface is BridgeTargetSurface.Discord or BridgeTargetSurface.Reddit;
private static string NormalizeRepository(string value) => NormalizeText(value).ToLowerInvariant();
private static string ShortRepositoryName(string normalizedRepositoryFullName)
@ -391,6 +413,11 @@ public sealed record BridgeActionRequest(
string SourceKind,
string SourceId,
string AuthorityReference,
string BifrostIdentity,
string HeimdallCapabilityReference,
string EpiphanyRunId,
string EpiphanyLaneId,
string EpiphanyAgentIdentity,
string Title,
string Summary,
Guid? WorkItemId = null,
@ -408,6 +435,11 @@ public sealed record BridgeActionRequest(
SourceKind = NormalizeText(SourceKind),
SourceId = NormalizeText(SourceId),
AuthorityReference = NormalizeText(AuthorityReference),
BifrostIdentity = NormalizeText(BifrostIdentity),
HeimdallCapabilityReference = NormalizeText(HeimdallCapabilityReference),
EpiphanyRunId = NormalizeText(EpiphanyRunId),
EpiphanyLaneId = NormalizeText(EpiphanyLaneId),
EpiphanyAgentIdentity = NormalizeText(EpiphanyAgentIdentity),
Title = NormalizeText(Title),
Summary = NormalizeText(Summary)
};
@ -434,6 +466,11 @@ public sealed record BridgeActionResult(
string SourceKind,
string SourceId,
string AuthorityReference,
string BifrostIdentity,
string HeimdallCapabilityReference,
string EpiphanyRunId,
string EpiphanyLaneId,
string EpiphanyAgentIdentity,
string PolicyDecision,
string Title,
string ReceiptUrl,
@ -453,6 +490,11 @@ public sealed record BridgeActionResult(
action.SourceKind,
action.SourceId,
action.AuthorityReference,
action.BifrostIdentity,
action.HeimdallCapabilityReference,
action.EpiphanyRunId,
action.EpiphanyLaneId,
action.EpiphanyAgentIdentity,
action.PolicyDecision,
action.Title,
action.ReceiptUrl,