Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-18516-remote-write-identity-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Settings → Repos → Reference repos: owner-only "Post on other projects as" control (Hive bot, falling back to me / Hive bot only / Me) for `project.remote_write_identity`, a per-repo line saying which identity posts there and why, `PUT /api/config/reference-repos/write-identity`, and the docs (#18516).
103 changes: 103 additions & 0 deletions dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6505,6 +6505,18 @@
"items": {
"type": "string"
}
},
"write_identity": {
"type": "string"
},
"write_identities": {
"type": "array",
"items": {
"type": "string"
}
},
"bot_login": {
"type": "string"
}
}
}
Expand Down Expand Up @@ -6559,6 +6571,18 @@
"items": {
"type": "string"
}
},
"write_identity": {
"type": "string"
},
"write_identities": {
"type": "array",
"items": {
"type": "string"
}
},
"bot_login": {
"type": "string"
}
}
}
Expand All @@ -6577,6 +6601,85 @@
}
}
},
"/api/config/reference-repos/write-identity": {
"put": {
"tags": [
"System"
],
"summary": "Set the remote write identity",
"description": "Sets project.remote_write_identity: whose name the hive's writes to granted reference repos carry (bot: the App bot where the repo's owner installed the App, else the owner's connected account; bot_only: the App bot or read-only; owner: the owner's connected account). Refused when a hand-written write entry would have no credential under the new value. Re-resolves the reference repos before answering. Owner only.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"write_identity"
],
"properties": {
"write_identity": {
"type": "string",
"enum": [
"bot",
"bot_only",
"owner"
]
}
}
}
}
}
},
"responses": {
"200": {
"description": "Current reference repos, resolved under the new value (same body as GET /api/config/reference-repos)",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"reference_repos": {
"type": "array",
"items": {
"type": "object"
}
},
"write_kinds": {
"type": "array",
"items": {
"type": "string"
}
},
"write_identity": {
"type": "string"
},
"write_identities": {
"type": "array",
"items": {
"type": "string"
}
},
"bot_login": {
"type": "string"
}
}
}
}
}
},
"400": {
"description": "Unknown value, or a hand-written write entry would have no credential; nothing was stored"
},
"403": {
"description": "Owner role required"
},
"500": {
"description": "The config file could not be written; the setting is unchanged"
}
}
}
},
"/api/config/stat-sources": {
"get": {
"tags": [
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,9 @@ func (b *boot) wireBootClosures() {
OwnerIdentity: b.ownerIdentityStore(),
OwnerIdentityChanged: b.ownerIdentityChanged,
RepoAgents: b.repoAgents,
LockRemoteWriteIdentity: b.lockRemoteWriteIdentity,
CheckRemoteWriteIdentity: b.checkRemoteWriteIdentity,
RemoteWriteIdentityChanged: b.remoteWriteIdentityChanged,
ReviewConfigApplied: func(rc config.ReviewConfig) {
if b.ghClient == nil {
return
Expand Down
53 changes: 53 additions & 0 deletions src/cmd/hive/reference_repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (b *boot) wireReferenceRepos() {
}
rt := b.newReferenceRepoRuntime()
if len(b.cfg.Project.ReferenceRepos) == 0 && rt.deriver == nil {
b.referenceRepos = rt
return
}
b.wireReferenceReposWith(rt)
Expand Down Expand Up @@ -290,6 +291,19 @@ func (b *boot) applyEditedReferenceRepos(ctx context.Context, refs []config.Refe
return nil
}

// lockRemoteWriteIdentity serializes the dashboard transaction with
// re-resolution and discards any prepared resolution after a failed save.
func (b *boot) lockRemoteWriteIdentity() func() {
if rt := b.referenceRepos; rt != nil {
rt.mu.Lock()
return func() {
rt.pendingIdentity = nil
rt.mu.Unlock()
}
}
return func() {}
}

// ownerIdentityChanged is the dashboard's hook after the owner connects,
// reconnects or disconnects their GitHub account (hivecommons/hive#18197):
// the reference-repo policies are re-resolved so a derived entry flips
Expand All @@ -312,3 +326,42 @@ func (b *boot) ownerIdentityStore() *github.OwnerIdentityStore {
}
return b.ownerIdentity
}

// checkRemoteWriteIdentity prepares a full resolution under the proposed
// identity without publishing it. The dashboard holds rt.mu for this call.
func (b *boot) checkRemoteWriteIdentity(ctx context.Context, setting string) error {
if b.githubProxy == nil || b.cfg == nil {
return nil
}
if err := config.ValidateRemoteWriteIdentity(setting); err != nil {
return err
}
rt := b.referenceRepos
if rt == nil {
rt = b.newReferenceRepoRuntime()
}
rt.pendingIdentity = nil
deps := rt.deps
deps.writeIdentity = func() string { return setting }
handWritten := config.HandWrittenReferenceRepos(b.cfg.Project.ReferenceRepos)
derived := rt.deriver.derive(ctx, b.cfg, b.logger)
merged := mergedReferenceRepos(b.cfg, handWritten, derived, b.logger)
res, err := buildReferenceRepoPolicies(ctx, merged, deps, b.logger)
if err != nil {
return err
}
rt.pendingIdentity = &res
return nil
}

// remoteWriteIdentityChanged publishes the prepared resolution after saving.
// The dashboard still holds rt.mu; notices use the boot context.
func (b *boot) remoteWriteIdentityChanged() {
rt := b.referenceRepos
if rt == nil || rt.pendingIdentity == nil {
return
}
res := *rt.pendingIdentity
rt.pendingIdentity = nil
b.installReferenceRepoResolution(b.ctx, rt, res)
}
9 changes: 8 additions & 1 deletion src/cmd/hive/reference_repos_derive.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ type referenceRepoRuntime struct {
// lastDerived are the derived entries as buildReferenceRepoPolicies
// resolved them on the last successful pass.
lastDerived []config.ReferenceRepo
// pendingIdentity is prepared under mu and published only after saving.
pendingIdentity *referenceRepoResolution
}

// derivedEntries returns the derived entries of a resolved list.
Expand Down Expand Up @@ -379,6 +381,12 @@ func (b *boot) applyReferenceRepos(ctx context.Context, rt *referenceRepoRuntime
if err != nil {
return err
}
b.installReferenceRepoResolution(ctx, rt, res)
return nil
}

// installReferenceRepoResolution publishes a resolution while rt.mu is held.
func (b *boot) installReferenceRepoResolution(ctx context.Context, rt *referenceRepoRuntime, res referenceRepoResolution) {
// The resolved entries replace the list in memory only: a derived entry
// is never written back to any config file (yaml:"-" on its provenance
// and the save test in reference_repos_derive_test.go guard that), and
Expand All @@ -393,7 +401,6 @@ func (b *boot) applyReferenceRepos(ctx context.Context, rt *referenceRepoRuntime
// Likewise the own-item follow-up: reads on the remote repos and resume
// kicks, bounded, never on the boot or reload path.
go b.pollRemoteItems(ctx, rt, res.repos)
return nil
}

// rederiveReferenceRepos is the pass a reload or the poller runs: never
Expand Down
Loading
Loading