Skip to content

Commit 6e458d8

Browse files
authored
feat(agents): configure per-agent GitHub identities (#125199)
* feat(agents): add managed GitHub identities * fix(agents): use opaque GitHub setup handles * style(codex): format managed shell environment call * refactor(agents): own managed GitHub process identity * chore(config): refresh baseline after rebase * fix(ci): satisfy managed GitHub identity gates * fix(ci): repair managed GitHub identity checks * test(agents): align GitHub identity CI coverage * fix(codex): scope login shell isolation * fix(agents): let managed gh profiles authenticate * fix(agents): harden GitHub identity setup * test(gateway): align method suffix counts * fix(ui): serialize GitHub identity mutations * fix(protocol): generate GitHub configure requests * test(ui): restore timers after identity tests * fix(ui): preserve GitHub identity mutation ownership * fix(agents): preserve native GitHub CLI auth
1 parent 2fc85bd commit 6e458d8

74 files changed

Lines changed: 4378 additions & 61 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ enum class GatewayMethod(
589589
SessionsAssignOwner("sessions.assignOwner"),
590590
ProgressCardGet("progressCard.get"),
591591
ProgressCardPut("progressCard.put"),
592+
ToolsGithubStatus("tools.github.status"),
593+
ToolsGithubConfigure("tools.github.configure"),
592594
}
593595

594596
enum class GatewayEvent(

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14682,6 +14682,106 @@ public struct ToolsCatalogParams: Codable, Sendable {
1468214682
}
1468314683
}
1468414684

14685+
public struct ToolsGitHubStatusParams: Codable, Sendable {
14686+
public let agentid: String
14687+
14688+
public init(
14689+
agentid: String)
14690+
{
14691+
self.agentid = agentid
14692+
}
14693+
14694+
private enum CodingKeys: String, CodingKey {
14695+
case agentid = "agentId"
14696+
}
14697+
}
14698+
14699+
public struct ToolsGitHubStatusResult: Codable, Sendable {
14700+
public let agentid: String
14701+
public let source: AnyCodable
14702+
public let credentialstate: AnyCodable
14703+
public let account: AnyCodable
14704+
public let gitauthor: [String: AnyCodable]
14705+
public let evidence: AnyCodable
14706+
14707+
public init(
14708+
agentid: String,
14709+
source: AnyCodable,
14710+
credentialstate: AnyCodable,
14711+
account: AnyCodable,
14712+
gitauthor: [String: AnyCodable],
14713+
evidence: AnyCodable)
14714+
{
14715+
self.agentid = agentid
14716+
self.source = source
14717+
self.credentialstate = credentialstate
14718+
self.account = account
14719+
self.gitauthor = gitauthor
14720+
self.evidence = evidence
14721+
}
14722+
14723+
private enum CodingKeys: String, CodingKey {
14724+
case agentid = "agentId"
14725+
case source
14726+
case credentialstate = "credentialState"
14727+
case account
14728+
case gitauthor = "gitAuthor"
14729+
case evidence
14730+
}
14731+
}
14732+
14733+
public struct ToolsGitHubManagedConfigureParams: Codable, Sendable {
14734+
public let scope: AnyCodable
14735+
public let agentid: String
14736+
public let mode: String
14737+
public let secretname: String
14738+
public let gitauthor: [String: AnyCodable]?
14739+
14740+
public init(
14741+
scope: AnyCodable,
14742+
agentid: String,
14743+
mode: String,
14744+
secretname: String,
14745+
gitauthor: [String: AnyCodable]? = nil)
14746+
{
14747+
self.scope = scope
14748+
self.agentid = agentid
14749+
self.mode = mode
14750+
self.secretname = secretname
14751+
self.gitauthor = gitauthor
14752+
}
14753+
14754+
private enum CodingKeys: String, CodingKey {
14755+
case scope
14756+
case agentid = "agentId"
14757+
case mode
14758+
case secretname = "secretName"
14759+
case gitauthor = "gitAuthor"
14760+
}
14761+
}
14762+
14763+
public struct ToolsGitHubInheritConfigureParams: Codable, Sendable {
14764+
public let scope: AnyCodable
14765+
public let agentid: String
14766+
public let mode: String
14767+
14768+
public init(
14769+
scope: AnyCodable,
14770+
agentid: String,
14771+
mode: String)
14772+
{
14773+
self.scope = scope
14774+
self.agentid = agentid
14775+
self.mode = mode
14776+
}
14777+
14778+
private enum CodingKeys: String, CodingKey {
14779+
case scope
14780+
case agentid = "agentId"
14781+
case mode
14782+
}
14783+
}
14784+
1468514785
public struct ToolCatalogProfile: Codable, Sendable {
1468614786
public let id: AnyCodable
1468714787
public let label: String
@@ -21020,6 +21120,37 @@ public enum AuditRunIdentityV1: Codable, Sendable {
2102021120
}
2102121121
}
2102221122

21123+
public enum ToolsGitHubConfigureParams: Codable, Sendable {
21124+
case managed(ToolsGitHubManagedConfigureParams)
21125+
case inherit(ToolsGitHubInheritConfigureParams)
21126+
21127+
private enum CodingKeys: String, CodingKey {
21128+
case discriminator = "mode"
21129+
}
21130+
21131+
public init(from decoder: Decoder) throws {
21132+
let container = try decoder.container(keyedBy: CodingKeys.self)
21133+
let discriminator = try container.decode(String.self, forKey: .discriminator)
21134+
switch discriminator {
21135+
case "managed": self = try .managed(ToolsGitHubManagedConfigureParams(from: decoder))
21136+
case "inherit": self = try .inherit(ToolsGitHubInheritConfigureParams(from: decoder))
21137+
default:
21138+
throw DecodingError.dataCorruptedError(
21139+
forKey: .discriminator,
21140+
in: container,
21141+
debugDescription: "Unknown ToolsGitHubConfigureParams discriminator value"
21142+
)
21143+
}
21144+
}
21145+
21146+
public func encode(to encoder: Encoder) throws {
21147+
switch self {
21148+
case .managed(let value): try value.encode(to: encoder)
21149+
case .inherit(let value): try value.encode(to: encoder)
21150+
}
21151+
}
21152+
}
21153+
2102321154
public enum ApprovalPresentation: Codable, Sendable {
2102421155
case exec(ExecApprovalPresentation)
2102521156
case plugin(PluginApprovalPresentation)

‎apps/shared/OpenClawKit/Tests/OpenClawKitTests/GatewayProtocolGeneratedModelsTests.swift‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ struct GatewayProtocolGeneratedModelsTests {
8484
let params = try JSONDecoder().decode(
8585
SessionsMoveParams.self,
8686
from: Data(
87-
#"{"key":"agent:main:move","expected":{"generation":4,"environmentId":"environment-1","ownerEpoch":7},"target":{"kind":"profile","profileId":"development"}}"#.utf8))
87+
#"{"key":"agent:main:move","expected":{"generation":4,"environmentId":"environment-1","ownerEpoch":7},"target":{"kind":"profile","profileId":"development"}}"#
88+
.utf8))
8889

8990
#expect(params.expected.generation == 4)
9091
#expect(params.expected.environmentid == "environment-1")
@@ -118,4 +119,43 @@ struct GatewayProtocolGeneratedModelsTests {
118119
from: Data(#"{"kind":"gateway","profileId":"development"}"#.utf8))
119120
}
120121
}
122+
123+
@Test(arguments: [
124+
(
125+
#"{"scope":"system","agentId":"main","mode":"managed","secretName":"github-setup-11111111111111111111111111111111"}"#,
126+
"system",
127+
true),
128+
(
129+
#"{"scope":"agent","agentId":"main","mode":"managed","secretName":"github-setup-22222222222222222222222222222222","gitAuthor":{"name":"Agent"}}"#,
130+
"agent",
131+
true),
132+
(#"{"scope":"system","agentId":"main","mode":"inherit"}"#, "system", false),
133+
(#"{"scope":"agent","agentId":"main","mode":"inherit"}"#, "agent", false),
134+
])
135+
func `GitHub configure requests round trip every scope and mode`(
136+
json: String,
137+
expectedScope: String,
138+
expectedManaged: Bool) throws
139+
{
140+
let params = try JSONDecoder().decode(
141+
ToolsGitHubConfigureParams.self,
142+
from: Data(json.utf8))
143+
144+
switch params {
145+
case let .managed(payload):
146+
#expect(expectedManaged)
147+
#expect(payload.scope.value as? String == expectedScope)
148+
#expect(payload.agentid == "main")
149+
#expect(payload.secretname.hasPrefix("github-setup-"))
150+
case let .inherit(payload):
151+
#expect(!expectedManaged)
152+
#expect(payload.scope.value as? String == expectedScope)
153+
#expect(payload.agentid == "main")
154+
}
155+
156+
let encoded = try #require(
157+
JSONSerialization.jsonObject(with: JSONEncoder().encode(params)) as? [String: Any])
158+
#expect(encoded["scope"] as? String == expectedScope)
159+
#expect(encoded["mode"] as? String == (expectedManaged ? "managed" : "inherit"))
160+
}
121161
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2314,
2+
"core": 2324,
33
"channel": 3580,
44
"plugin": 4001
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
d5b76a09b7448092d297d419c288a0198de48190e08459330e07c2399a861f6c config-baseline.json
2-
3735c1bd2835ad9bf9e13f5614ac1b0461892e014da67f0f0f104af061c96dff config-baseline.core.json
1+
0d91d21741500806ea40424189b85f5598b002eab529bf2ea96c19794e70ec46 config-baseline.json
2+
ed8e9cbb2244820f3aad15f206f870de127a37e9532289c29c1aca972c039a28 config-baseline.core.json
33
1a18ca1f2c5970a1af9b3b6748fc62fdb2e83a4ec524b8de84f7ccd019159e9c config-baseline.channel.json
44
b0baf1635dad2e7ade52597fc21e11982bd89bcf68bb46d943e4b550c165ea01 config-baseline.plugin.json

‎docs/gateway/config-tools.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,47 @@ Controls elevated exec access outside the sandbox:
211211
- `/elevated on|off|ask|full` stores state per session; inline directives apply to single message.
212212
- Elevated `exec` bypasses sandboxing and uses the configured escape path (`gateway` by default, or `node` when the exec target is `node`).
213213

214+
### `tools.github`
215+
216+
GitHub CLI identity is native by default. When `tools.github` is omitted, local agent tools, the Codex harness, and Agent Settings follow normal `gh` resolution: `GH_TOKEN` or `GITHUB_TOKEN` from the Gateway process takes precedence, followed by the runtime user's `gh` keyring/config. The Git author comes from the selected agent's workspace.
217+
218+
Use **Agents → Tools → GitHub CLI Identity** to configure a managed fine-grained personal access token. The browser places the pasted token in the secret store as a one-use handoff. The Gateway hard-deletes that handoff before passing its value to `gh auth login` on stdin, verifies the account, publishes an account-owned managed `gh` profile, and stores only this secret-free config:
219+
220+
```json5
221+
{
222+
tools: {
223+
github: {
224+
profileId: "ghp_0123456789abcdef0123456789abcdef",
225+
gitAuthor: { name: "Automation User", email: "[email protected]" },
226+
},
227+
},
228+
agents: {
229+
entries: {
230+
reviewer: {
231+
tools: {
232+
github: {
233+
profileId: "ghp_fedcba9876543210fedcba9876543210",
234+
gitAuthor: { name: "Review Agent" },
235+
},
236+
},
237+
},
238+
},
239+
},
240+
}
241+
```
242+
243+
Omitting `agents.entries.<id>.tools.github` inherits the system identity. An agent object is a complete managed override. If a configured managed profile is missing or unusable, GitHub status reports `configured_unavailable`; it never falls back to the native profile.
244+
245+
Managed identity applies to the `gh` CLI/API account and optional Git author/committer metadata in local OpenClaw exec and the local Codex harness. OpenClaw supplies a private `GH_CONFIG_DIR`, clears ambient `GH_TOKEN` and `GITHUB_TOKEN` precedence, and applies configured author fields through process-local environment and Git config overlays. It does not install a credential helper, rewrite SSH remotes, add HTTP authorization headers, or otherwise override an existing repository's Git network credentials. New runs switch to a replacement or inherited identity immediately. Existing local processes keep their immutable profile generation until they close; retired profile files are cleaned on the next Gateway restart, so changing this setting is not immediate credential revocation.
246+
247+
Managed profiles provide execution and coordination identity; they are not an OS-user security sandbox. A process with unrestricted host execution under the same OS account can access account-owned files, including managed `gh` profiles. Use an OpenClaw sandbox, a dedicated host, or a dedicated OS user when adversarial isolation is required.
248+
249+
The profile is not forwarded to node hosts, OpenClaw sandboxes, remote-exec placements, or cloud workers; cloud workers remain credential-free. Direct branch or pull request publication is not part of this identity foundation and belongs to PR3 in this stacked series. Until that separate Gateway broker lands, repository remotes continue to use their existing credentials and publication workflow.
250+
251+
Verification proves which account answered the GitHub API request. Status distinguishes missing or invalid managed credentials, unverified transport failures, and GitHub rate limiting without returning `gh` diagnostics. It does not claim that fine-grained write permissions or Git transport access were remotely verified. GitHub App and brokered publication support remain future work.
252+
253+
Control UI repository previews and project discovery use the separate optional `gateway.controlUi.github.token` service credential. They never consume an agent tool identity. When this SecretRef is explicit, OpenClaw excludes its exact environment or store name from agent execution. A custom name does not clear unrelated `GH_TOKEN` or `GITHUB_TOKEN` values used by native identity; a ref named `GH_TOKEN` or `GITHUB_TOKEN` excludes that exact variable.
254+
214255
### `tools.exec`
215256

216257
```json5

‎docs/gateway/configuration-reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ Gateway or node host and check `openclaw nodes pending` again.
824824
run `openclaw config set gateway.tailscale.mode funnel`, followed by
825825
`openclaw config unset gateway.tailscale.preserveFunnel`. Default `false`.
826826
- `controlUi.allowedOrigins`: explicit browser-origin allowlist for Gateway WebSocket connects. Required for public non-loopback browser origins. Private same-origin LAN/Tailnet UI loads from loopback, RFC1918/link-local, `.local`, `.ts.net`, or Tailscale CGNAT hosts are accepted without enabling Host-header fallback.
827-
- `controlUi.github.token`: optional SecretRef-backed service credential for Control UI GitHub previews and project discovery. Prefer this explicit setting when the Gateway should own GitHub service access independently of its shared process environment. When omitted, the shipped `GH_TOKEN` then `GITHUB_TOKEN` process-environment fallback remains active. An explicitly configured but unavailable credential fails closed instead of using that fallback. SecretRef ownership does not create an OS-user security boundary.
827+
- `controlUi.github.token`: optional SecretRef-backed service credential for Control UI GitHub previews and project discovery. Prefer this explicit setting when the Gateway should own GitHub service access independently of its shared process environment. When omitted, the shipped `GH_TOKEN` then `GITHUB_TOKEN` process-environment fallback remains active. An explicitly configured but unavailable credential fails closed instead of using that fallback. Its exact environment or store name is excluded from agent execution; a custom name does not clear unrelated native `GH_TOKEN` or `GITHUB_TOKEN` values. This credential is separate from `tools.github` agent identities and does not create an OS-user security boundary.
828828
- `controlUi.toolTitles`: opt in to AI-generated purpose titles for tool calls in Control UI chat. Default: `false` (tool rendering stays fully deterministic with no background model calls). When enabled, the `chat.toolTitles` method labels complex calls through standard utility-model routing — the agent's `utilityModel` (an operator decision that may send bounded tool arguments to the chosen provider, like every utility task), or the session provider's declared small-model default (OpenAI → `gpt-5.6-luna`, Anthropic → `claude-haiku-4-5`) — and caches results in the per-agent state database so repeat views never re-bill. `utilityModel: \"\"` disables titles like every other utility task; titles never fall back to the primary model.
829829
- `controlUi.dangerouslyAllowHostHeaderOriginFallback`: dangerous mode that enables Host-header origin fallback for deployments that intentionally rely on Host-header origin policy.
830830
- `cliAgents.enabled`: opt in to the experimental **CLI agents** group in the Control UI new-session model picker. Default: `false`. The group appears only when the Gateway advertises `sessions.catalog.list`, and it includes only catalog providers that support creating sessions. Selecting one opens the same catalog-target new-session flow used by the sidebar catalog action.

0 commit comments

Comments
 (0)