Skip to content

✨ feature: choose remote repository write identity - #18536

Closed
Karibhou wants to merge 3 commits into
hivecommons:v5from
Karibhou:feat/remote-write-identity-18516
Closed

Karibhou wants to merge 3 commits into
hivecommons:v5from
Karibhou:feat/remote-write-identity-18516

Conversation

@Karibhou

@Karibhou Karibhou commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Scope

Settings, API and documentation for the second part of #18516, based on the backend merged in #18521. Reuses the Settings implementation offered in feat/remote-write-identity-ui; the existing resolver, grant semantics, proxy and remote-item poller remain unchanged.

  • Add the owner-only, audited three-way identity control, dry-run hand-written grants, persist the setting and re-resolve policies.
  • Expose resolved identity/provenance in Settings and status; document the control and add a separate changelog fragment.
  • Serialize setting transitions with periodic reference-repo resolution.

Verification

  • Focused go test ./pkg/dashboard ./cmd/hive -run 'ReferenceRepo|RemoteWriteIdentity'
  • node --test pkg/dashboard/reference_repos_editor.test.js
  • python3 src/scripts/check-docs-links.py src/docs
  • bash src/scripts/check-changelog-fragment.sh v5
  • The static dashboard opened in a browser, but without a live authenticated API the Settings control could not be exercised visually.

Refs #18516

@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#18576 ✨ Owner-only Send to on model-owned stage-tracker rows same files dashboard/openapi.json
src/cmd/hive/main.go
src/docs/api-reference/configuration.md
src/pkg/dashboard/deps.go
src/pkg/dashboard/static/index.html
#18603 ✨ Settings: "Post on other projects as" control for remote write identity CONFLICT changelog.d/added-18516-remote-write-identity-settings.md
dashboard/openapi.json
src/cmd/hive/main.go (conflict)
src/cmd/hive/reference_repos.go (conflict)
src/docs/agent-configuration.md
src/docs/api-reference/auth.md
src/docs/api-reference/configuration.md (conflict)
src/docs/api-reference/dashboard-misc.md
src/docs/api-reference/health-status-events.md
src/docs/api-reference/snapshots-and-style.md
src/docs/operator-reference/README.md
src/pkg/dashboard/api.go
src/pkg/dashboard/api_config_reference_repos.go
src/pkg/dashboard/api_config_remote_write_identity.go (conflict)
src/pkg/dashboard/api_config_remote_write_identity_test.go
src/pkg/dashboard/audit.go
src/pkg/dashboard/deps.go (conflict)
src/pkg/dashboard/reference_repos_derived_18161_test.go
src/pkg/dashboard/reference_repos_editor.test.js (conflict)
src/pkg/dashboard/server.go
src/pkg/dashboard/settings_parity_allowlist.txt
src/pkg/dashboard/static-src/css/config-dialog.css
src/pkg/dashboard/static-src/js/config-governor.js (conflict)
src/pkg/dashboard/static-src/js/repos-render.js
src/pkg/dashboard/static/index.html (conflict)
src/pkg/dashboard/status_builder.go
#18593 ✨ Betty answers questions about the hive from its live state same files src/cmd/hive/main.go
#18592 🐛 Betty closes the loop on deep dives; research agents survive config reloads same files src/cmd/hive/main.go
src/pkg/dashboard/static/index.html
#18594 🐛 Meetings: consent posted only on a confirmed delivery; speak it or leave same files src/pkg/dashboard/static/index.html
#18600 🐛 meetings: log every failed meetings call and keep a failed approval's reason same files src/pkg/dashboard/static/index.html
#18610 ✨ Remote items: follow up on issues and PRs the hive opened as its App bot same files src/docs/agent-configuration.md
#18611 ✨ meetings: desktop companion meetings (/api/companion/*) same files dashboard/openapi.json
src/pkg/dashboard/api.go
#18586 ✨ Sandboxed agents open issues and keep topic claims through the request spool same files src/cmd/hive/main.go
#18584 ✨ Show why a calendar-email proof failed on its Settings row same files dashboard/openapi.json
src/pkg/dashboard/static/index.html
#18601 🐛 dashboard: a hosted spoke's JSON 502 reaches the owner instead of the ingress page same files src/pkg/dashboard/server.go

@hivecommons-hive

hivecommons-hive Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

@Karibhou this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Review asks:

  • the review swarm requested changes

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Your relay session received this as a fix-pr task; your current task is parked (claim kept alive) until this PR is green.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

CI report: golangci-lint fails with const botOnlyCure is unused (unused). Suggested fix: either remove the botOnlyCure constant or reference it where the bot-only cure text is emitted. The PR branch also has merge conflicts with v5; please rebase. (Fork branch — not pushing from the hive.)


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=claude model=claude-sonnet-5-5 claude=2.1.325

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou the hive has adopted this PR (stage/074-adopted-by-hive): your hive has been offline since the nudge. The hive will rebase this branch on v5 and fix CI here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs-currency review at head 4bcf4dc. The PR updates agent-configuration.md, github-write-surface.md, api-reference, openapi.json, hive.yaml.example and the changelog well, but two operator-facing pages still describe the old behaviour.

  1. Stale operator reference — src/docs/operator-reference/README.md:257 (project.reference_repos[].write) still says the credential is the App installation on the target org, that "the hive owner cannot install it", and "For a hand-written entry on an org without one, set write_token_file". Line 259 (derived entries) says "the credential is the App installation on the requesting org". Neither mentions the owner's connected account or bot/bot_only/owner (the code and agent-configuration.md now do), and there is no row for project.remote_write_identity. This is the page the repo's config docs point to for field defaults, so operators will not learn the new key or the default change from it.
  2. GET row not updated — src/docs/api-reference/configuration.md:~104 (GET /api/config/reference-repos) does not list the new response fields remote_write_identity, remote_write_identities, bot_login (these are in openapi.json in this diff).

Suggested fix (README.md, after line 258) — add a row, and replace the credential sentences in 257/259:

+| `project.remote_write_identity` | `bot` | Who write-tier reference repos are written as ([#18516](https://github.com/hivecommons/hive/issues/18516)): `bot` = the hive's App bot where the repo's owner already installed it, else the owner's connected account, else read-only; `bot_only` = App bot or read-only, never the owner's token; `owner` = the owner's connected account. Set in Settings → Repos → Reference repos (`PUT /api/config/remote-write-identity`). See [agent-configuration](../agent-configuration.md#reference-repos). |

and in the GET row add: plus remote_write_identity, remote_write_identities and bot_login.

— hive: agent=adjudicator-5 backend=claude model=claude-sonnet-5-5 claude=2.1.325

@hivecommons-hive

hivecommons-hive Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from adjudicator-2 (folded here because this head already carries its hive review):

Security review (head 4bcf4dc) — one in-scope finding; the rest of the credential path looked sound.

1. Bot push is bounded only by "not the default branch" — src/crux/proxy/reference_repos.go:293-298 (medium, in-scope)

This PR gives the bot a real contents:write token on the upstream repo itself (pol.Bot skips the fork path, reference_repo_bot.go referenceRepoPermissions). Before, the owner token usually could not push to a third-party repo. Now the referencePush check (unchanged by this PR) rejects only a ref equal to refs/heads/<default>. With that token an agent could still:

  • force-push or delete any other existing branch (release-*, other people's PR branches),
  • create or delete tags (refs/tags/*).

Issue #18516 says every proxy restriction stays and that the setting must not widen a grant. In practice this widens it for bot identity. Whether it is exploitable depends on the upstream's own branch protection, which the hive cannot assume.

Suggested fix: when pol.Bot is set, in the referencePush case allow only refs under a hive-owned prefix and reject deletes. For example, use refs/heads/hive/ or any prefix you choose:

 		for _, ref := range refs {
 			if ref == "refs/heads/"+def {
 				return referenceRepoRefusal(pol, "pushing to its default branch ("+def+") is never allowed — push a topic branch and open a PR"), true
 			}
+			if pol.Bot && !strings.HasPrefix(ref, "refs/heads/hive/") {
+				return referenceRepoRefusal(pol, "as the App bot the hive may only push new topic branches under hive/ — not "+ref), true
+			}
 		}

The update also needs to reject a zero new-SHA (branch delete) and a non-fast-forward of an existing hive/ branch. That needs peekReceivePackRefs to return the old and new SHAs. Update the agent instructions in the docs to tell agents to use the hive/ prefix.

Checked, no finding

  • Token mint: scoped to one repo and the tier's permissions (reference_repo_bot.go MintRepositoryToken). The installation's account is checked against the repo owner.
  • bot_only never falls back to the owner token (reference_repo_token.go, ResolveReferenceRepoCredential). A failed mint returns ok=false rather than another credential.
  • The settings endpoint is owner-only, validated and audit-logged (api_config_reference_repos.go, handleRemoteWriteIdentityPut).

Not verified: UI behavior (the PR says it was not exercised against a live API).

Review findings from adjudicator (folded here because this head already carries its hive review):

Correctness review at head 4bcf4dc (read the full diff plus reference_repos_derive.go at head). The resolution logic reads well: transient App lookup failures keep the cached answer (reference_repo_bot.go installation, NoFallback on lookup failure), bot_only never reaches the owner token, and lastGrants correctly restores a derived grant that an earlier downgrade cleared. Two findings:

1. (low, in-scope) The identity change can be reverted by a concurrent re-resolve.
handleRemoteWriteIdentityPut (src/pkg/dashboard/api_config_reference_repos.go) calls ApplyRemoteWriteIdentity(next), then sets cfg.Project.RemoteWriteIdentity = next only after that hook returns, so after rt.mu has been released.
applyReferenceRepos (src/cmd/hive/reference_repos_derive.go, the buildReferenceRepoPolicies(... EffectiveRemoteWriteIdentity() ...) call) reads the config value under rt.mu. A reload or poller pass that lands in that gap re-resolves under the old identity and reinstalls the old policies. The config and the saved file then say next while the proxy enforces prev, which is the divergence the code's own rollback comment says it prevents.
The window is widened because Probe does network lookups while rt.mu is held.
The unsynchronized write to cfg.Project.RemoteWriteIdentity also races with those readers.
I did not verify what locking the dashboard side has around cfg.
Suggested fix: have the ApplyRemoteWriteIdentity hook set b.cfg.Project.RemoteWriteIdentity = identity inside its rt.mu critical section. The handler's rollback then restores prevRaw through the same hook.

2. (info, out-of-scope) Items opened under the old identity are silently dropped on a switch.
remoteitems.go Run lists each repo by the new login and prunes tracked items that listing no longer shows. The proxy's own-item check also compares against pol.Login. Open owner-authored issues and PRs therefore stop receiving follow-up the moment a hive upgrades to the bot default, with no notice to the agent that opened them.
#18516 calls the identity switch intended, so I'm not blocking. The upgrade guidance should say that in-flight items on a switched repo stop being followed.

hive/awaiting-ci: pushed 39129d4 removing the unused botOnlyCure const (golangci-lint unused). PR is still CONFLICTING with base; rebase deferred to next kick. CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=claude model=claude-sonnet-5-5 claude=2.1.325

@kubestellar-prow kubestellar-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 16, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

The hive adopted this PR (stage/074-adopted-by-hive) but its head 39129d4bf82f has not moved for 1m and the hive has nothing it can push: adoption-stalled:supersede-failed:signoff-rehome.

Blocker: the hive tried to re-home this PR onto hive/adopt-18536 (signoff-rehome) and could not open the superseding PR.

Moving to stage/085-needs-decision so a person sees it. This is not a merge-approval wait: the lane has not admitted this head.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Supersede failed: the hive could not open a fresh PR with these commits. Merging v5 into the copy branch hive/adopt-18536 (at 39129d4bf82f) stopped on a git conflict, so no superseding PR was opened and this PR stays open.

Files changed on both sides:

  • changelog.d/added-18516-remote-write-identity.md
  • dashboard/openapi.json
  • src/cmd/hive/main.go
  • src/cmd/hive/reference_repos.go
  • src/cmd/hive/reference_repos_identity_test.go
  • src/cmd/hive/remote_items.go
  • src/crux/proxy/reference_repos.go
  • src/docs/agent-configuration.md
  • src/docs/api-reference/auth.md
  • src/docs/api-reference/configuration.md
  • src/hive.yaml.example
  • src/pkg/config/config.go
  • src/pkg/config/reference_repos.go
  • src/pkg/config/validate.go
  • src/pkg/dashboard/api.go
  • src/pkg/dashboard/static/index.html
  • src/pkg/github/reference_repo_request.go
  • src/pkg/github/reference_repo_token.go
  • src/pkg/scheduler/kickmessage.go

Rebase this branch onto v5 (or push a merge of it) and the lane re-evaluates the new head; a new adoption/supersede label then retries the supersede. Reason: supersede-conflict.

- Build on the merged hivecommons#18521 backend and expose identity and provenance in Settings.
- Serialize setting changes with reference-repo re-resolution.

Co-authored-by: Andy Anderson <andy@clubanderson.com>
Signed-off-by: Andy Anderson <andy@clubanderson.com>
Signed-off-by: Karibhou <157208370+Karibhou@users.noreply.github.com>
@Karibhou
Karibhou force-pushed the feat/remote-write-identity-18516 branch from 22fbee6 to 15f4b10 Compare November 17, 2026 01:04
@Karibhou

Copy link
Copy Markdown
Contributor Author

hive-base-moved: rebased the scoped Settings change onto v5 at 2c785d7; the replacement commit is authored and signed off as Karibhou rather than the hive App. The existing #18521 backend remains intact.

@kubestellar-prow kubestellar-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 17, 2026
…hanges

Signed-off-by: Karibhou <157208370+Karibhou@users.noreply.github.com>
Signed-off-by: Karibhou <157208370+Karibhou@users.noreply.github.com>
@Karibhou

Copy link
Copy Markdown
Contributor Author

Follow-up on the return notice: changelog-fragment-guard was red on the superseded head 15f4b10 and passes on 744c257. The only remaining red was test (agent 2/5) → TestRestart_CancelsPendingAsyncKick (tmux session hive-worker not found, 3/3 on that runner, which also made the downstream test/coverage checks red). This PR does not touch src/crux, the test passes 3/3 locally on 744c257, and v5 at 2c785d7 is green. I pushed an empty signed-off commit, 56ea101, to re-run CI because a fork contributor cannot re-run upstream jobs.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Scanner CI triage (fork PR, so comment only). Fixes for the failing checks:

  • golangci-lint: referenceRepoDeps.writeIdentitySetting is unused. Wire it up or remove it.
  • test (dashboard 2/4) and test-dashboard-shuffle: TestSettingsDialogReferencesEveryHiveYAMLLeaf fails. The new write-identity YAML key needs a Settings dialog entry, or an entry in src/pkg/dashboard/settings_parity_allowlist.txt if it is YAML-only.
  • changelog-fragment-guard: docs citation drift. Run python3 src/scripts/check-docs-citations.py --fix and commit the result. AGENTS.md says to use this script rather than the older check-api-reference-citations.sh named in the check output.
  • Sign-off survives the squash: make sure every commit has a Signed-off-by trailer (git commit -s, or git rebase --signoff).
  • coverage, test and native-queue-policy follow from the failures above.

🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=claude model=claude-sonnet-5-5 claude=2.1.325

@Karibhou

Copy link
Copy Markdown
Contributor Author

Follow-up on the return notice and the scanner triage: both refer to superseded heads (15f4b10 / 744c257). On the current head 56ea101, changelog-fragment-guard, golangci-lint, every test shard (including dashboard 2/4 and the shuffle shards), coverage, dco and Sign-off survives the squash all pass. Only docker, runtime, mutation and overlayfs jobs are still pending, plus tide, which waits on approval. No new commit is needed.

@Karibhou

Copy link
Copy Markdown
Contributor Author

@clubanderson your change request is addressed at head 56ea101 (based on v5 at 2c785d7). The PR now only contains the Settings, API and docs part of #18516, as you asked. Could you take another look?

  • The ✨ Reference repos: per-hive write identity, bot / bot only / owner (backend) (#18516) #18521 resolver (reference_repo_identity.go) and its invariant tests are unchanged. WritesIssues/WritesPRs/ReadOnly still use only the grant, and the remoteitems poller is not changed.
  • PUT /api/config/reference-repos/write-identity is owner-only and audited as sensitive (config_remote_write_identity). It dry-runs the hand-written entries and returns 400 instead of saving a value that would make boot exit 22. After saving, it re-resolves through buildReferenceRepoPolicies.
  • GET /api/config/reference-repos returns write_identity, write_identities and bot_login. The status payload returns credential_identity and credential_note.
  • UI: the three-way choice "Post on other projects as:" (Hive bot, falling back to me / Hive bot only / Me), a provenance line, and a line on each write entry. Adapted from feat/remote-write-identity-ui.
  • Docs: agent-configuration, operator-reference (new project.remote_write_identity row), api-reference and openapi. Removed the allowlist line from settings_parity_allowlist.txt.
  • The new changelog fragment is added-18516-remote-write-identity-settings.md. The existing fragment is unchanged.
  • Every commit is signed off. changelog-fragment-guard, dco, relative links, golangci-lint and all test shards are green on this head.

The 'returned to contributor' notice refers to the superseded head 15f4b10. On 56ea101, check-changelog-fragment.sh v5 and check-docs-citations.py pass locally.

Not verified: the Settings control against a live authenticated API.

@clubanderson

Copy link
Copy Markdown
Member

Thank you for the work here, Karibhou, and for picking up #18516 so quickly. The owner chose to land the Settings layer as #18603. It sits on top of the backend already merged in #18521 and adds only the control, the API route and the docs, with the agreed three-way text. A review of #18603 would be very welcome, especially anything your branch handles better. I'm leaving it to you whether to close this PR or carry a specific improvement over as a follow-up.

@Karibhou

Copy link
Copy Markdown
Contributor Author

Thanks @clubanderson, understood. #18603 carries the Settings layer on top of #18521, so I am closing this PR rather than keeping a competing version open. Anything specific from this branch can go in as a separate follow-up.

@Karibhou Karibhou closed this Nov 17, 2026
@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts-with-open-pr Open PR has a merge conflict with another open PR dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants