Skip to content
Merged
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
47 changes: 46 additions & 1 deletion docs/architecture/credential-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ bindings, each containing `origin`, `header`, and `secret_ref { name, key }`.
The Secret belongs to the Agent's namespace and contains the complete header
value, including `Bearer ` for bearer authorization. Session bindings use no
additional prefix. The controller never reads the Secret value, and the runtime
receives only a placeholder header configured on its RemoteMCPServer.
receives only placeholder headers configured for its MCP server or Git transport.

The HTTP(S) origin must already be in the Session's pinned revision egress list.
Paths, user information, queries, and fragments are rejected. Injection is
Expand All @@ -317,3 +317,48 @@ the placeholder. The provider must also grant the actor's atespace access to
the Agent namespace. The Envoy dataplane skips cleartext credential injection
in stock Substrate v0.4.0-alpha1. Restrict the destination listener with NetworkPolicy.
Secret lookup failures surface at the gateway; creation does not read or verify keys.

### Trusted Git transports

Native Claude and Codex Harnesses can select a trusted Git proxy profile:

```yaml
git:
origins: [github.com]
readProxyOrigin: http://mainloop-git-read.mainloop.svc.cluster.local
pushProxyOrigin: http://mainloop-git-push.mainloop.svc.cluster.local
```

These are the only accepted proxy origins. Push requires read, and this profile
excludes `credentialSecretRef`. The canonical repository identity remains HTTPS
GitHub; the Actor receives only the read and optional push HTTP destinations at
port 80. Their distinct hostnames separate the gateway's host-wide credential
effects. Git read and push capabilities are per-Session references containing
the complete Authorization value. Neither value enters runtime configuration,
Git config, markers, environments or revision provenance.

The Mainloop service policy admits `git-read` only with Secret name pattern
`mainloop-git-read-*`, key/header `authorization`, and the exact read origin above.
`git-push` requires `mainloop-git-push-*` and the exact push origin. Both use the
configured Agent namespace. Git hosts cannot be classified as MCP or added to
`cleartextMCPOrigins`. Purpose belongs to the trusted policy and listener; the
Session credential wire type has no purpose field. Max four bindings, frozen
creation identity, collision rejection and fork separation still apply.

Both native compilers check the complete origin and credential union, including
provider, shared MCP, package, skill and telemetry inputs. Proxy and no-Git
revisions reject direct GitHub host families, legacy `mainloop-git-auth` references
and revision credentials on either Git proxy host. The six package origins
remain credential-free. A no-Git coordinator acquires neither Git listener.
Both proxy fields absent retain the existing standalone/development direct Git
configuration. Production activation must select the proxy profile on every
Git-enabled Harness and retire direct revisions deliberately.

Creation and runtime startup need only frozen references, so Git Secrets may be
unpublished. Logical READY creation leaves the Actor suspended; READY Resume
alone does not wake it. Existing owned Suspend then Resume provides a non-turn
warmup, after which GetSession must report the exact active RUNNING association
before capabilities are published. Failed warmup retains the operation and
does not justify an early capability or model turn. Local controlled-Actor
fixtures qualify orchestration; installed Actor startup, provider/cache behavior,
listener authorization and network isolation require runtime evidence.
25 changes: 25 additions & 0 deletions docs/architecture/runtime-and-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,31 @@ creates nothing. Sessions without a workspace behave as before. A Harness with
`spec.git` requires a harness image built with this bootstrap: the adapter
configuration rejects unknown fields, so an older image fails at startup.

With `readProxyOrigin` configured, the shared Git policy accepts only HTTPS
GitHub owner/repository identity. It derives a normalized `/owner/repository.git`
path under the exact trusted read listener and optional distinct push listener.
Escaped separators, traversal, extra components and alternate authorities are
rejected. Session and TaskStore workspace identity and durable marker `repo`
remain the caller's canonical HTTPS repository. Proxy origins are never accepted
as workspace identity.

The checkout sets `remote.origin.url` to the derived read URL and
`remote.origin.pushurl` to the push URL, or the same read URL when push is absent.
It writes the inert Authorization placeholder for each exact listener in local
Git config before fetching and disables redirects. Missing capabilities leave
only that placeholder; the listener must deny the request. A read-only profile
routes push attempts to the read listener, which must refuse receive-pack. No
failure selects direct GitHub. Existing direct standalone/development checkout
is selected only when both compiled proxy fields are absent.

Executor construction validates config and the native CLI version without
reading the workspace or fetching Git. Reference-only Session creation can
therefore finish READY before Git values exist. Creation leaves the Actor
SUSPENDED, and READY Resume alone is a no-op. An owned Suspend/Resume sequence
can warm compute without a turn; GetSession's current RUNNING association is
the subsequent identity observation. Capability publication and installed
runtime qualification remain the caller's responsibility.

The Codex and Claude adapters wrap their runner with a bootstrapper. Before each turn it
checks for the done marker `/data/.kagent/workspace-bootstrap.done`. When it is absent
it reads the workspace through the runtime-authenticated `TaskStoreService.GetWorkspace`
Expand Down
24 changes: 24 additions & 0 deletions go/api/config/crd/bases/api.kagent.dev_agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ spec:
minItems: 1
type: array
x-kubernetes-list-type: set
pushProxyOrigin:
description: |-
PushProxyOrigin routes publication through the separate trusted push
listener. Omitted leaves receive-pack on the read listener, which denies it.
A transport origin does not grant publication authority.
enum:
- http://mainloop-git-push.mainloop.svc.cluster.local
type: string
readProxyOrigin:
description: |-
ReadProxyOrigin routes canonical GitHub checkouts through the trusted read
listener. Authorization comes from per-Session references, never a GitHub
credential. Omitted retains standalone direct Git behavior.
enum:
- http://mainloop-git-read.mainloop.svc.cluster.local
type: string
required:
- origins
type: object
Expand All @@ -149,6 +165,14 @@ spec:
the gateway holds one credential per host and header
rule: '!has(self.credentialSecretRef) || self.origins.size()
== 1'
- message: pushProxyOrigin requires readProxyOrigin
rule: '!has(self.pushProxyOrigin) || has(self.readProxyOrigin)'
- message: Git proxies require the single canonical github.com
origin
rule: '!has(self.readProxyOrigin) || (self.origins.size() ==
1 && self.origins[0] == ''github.com'')'
- message: Git proxies cannot use credentialSecretRef
rule: '!has(self.readProxyOrigin) || !has(self.credentialSecretRef)'
kagent:
description: KagentHarness configures the kagent runtime adapter.
properties:
Expand Down
23 changes: 23 additions & 0 deletions go/api/config/crd/bases/api.kagent.dev_harnesses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ spec:
minItems: 1
type: array
x-kubernetes-list-type: set
pushProxyOrigin:
description: |-
PushProxyOrigin routes publication through the separate trusted push
listener. Omitted leaves receive-pack on the read listener, which denies it.
A transport origin does not grant publication authority.
enum:
- http://mainloop-git-push.mainloop.svc.cluster.local
type: string
readProxyOrigin:
description: |-
ReadProxyOrigin routes canonical GitHub checkouts through the trusted read
listener. Authorization comes from per-Session references, never a GitHub
credential. Omitted retains standalone direct Git behavior.
enum:
- http://mainloop-git-read.mainloop.svc.cluster.local
type: string
required:
- origins
type: object
Expand All @@ -142,6 +158,13 @@ spec:
the gateway holds one credential per host and header
rule: '!has(self.credentialSecretRef) || self.origins.size() ==
1'
- message: pushProxyOrigin requires readProxyOrigin
rule: '!has(self.pushProxyOrigin) || has(self.readProxyOrigin)'
- message: Git proxies require the single canonical github.com origin
rule: '!has(self.readProxyOrigin) || (self.origins.size() == 1 &&
self.origins[0] == ''github.com'')'
- message: Git proxies cannot use credentialSecretRef
rule: '!has(self.readProxyOrigin) || !has(self.credentialSecretRef)'
kagent:
description: KagentHarness configures the kagent runtime adapter.
properties:
Expand Down
17 changes: 17 additions & 0 deletions go/api/v1alpha3/harness_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ type ClaudeHarness struct{}
// credential; the runtime never sees it.
//
// +kubebuilder:validation:XValidation:rule="!has(self.credentialSecretRef) || self.origins.size() == 1",message="credentialSecretRef requires exactly one origin because the gateway holds one credential per host and header"
// +kubebuilder:validation:XValidation:rule="!has(self.pushProxyOrigin) || has(self.readProxyOrigin)",message="pushProxyOrigin requires readProxyOrigin"
// +kubebuilder:validation:XValidation:rule="!has(self.readProxyOrigin) || (self.origins.size() == 1 && self.origins[0] == 'github.com')",message="Git proxies require the single canonical github.com origin"
// +kubebuilder:validation:XValidation:rule="!has(self.readProxyOrigin) || !has(self.credentialSecretRef)",message="Git proxies cannot use credentialSecretRef"
type HarnessGit struct {
// Origins lists the HTTPS Git hosts sessions may clone from, for example
// github.com. Each is an exact DNS name without scheme, port, or path.
Expand All @@ -130,6 +133,20 @@ type HarnessGit struct {
// +required
Origins []string `json:"origins"`

// ReadProxyOrigin routes canonical GitHub checkouts through the trusted read
// listener. Authorization comes from per-Session references, never a GitHub
// credential. Omitted retains standalone direct Git behavior.
// +kubebuilder:validation:Enum="http://mainloop-git-read.mainloop.svc.cluster.local"
// +optional
ReadProxyOrigin *string `json:"readProxyOrigin,omitempty"`

// PushProxyOrigin routes publication through the separate trusted push
// listener. Omitted leaves receive-pack on the read listener, which denies it.
// A transport origin does not grant publication authority.
// +kubebuilder:validation:Enum="http://mainloop-git-push.mainloop.svc.cluster.local"
// +optional
PushProxyOrigin *string `json:"pushProxyOrigin,omitempty"`

// CredentialSecretRef names a key in a same-namespace Secret holding the
// complete Authorization header value for the origin, for example
// "Basic <base64 of x-access-token:TOKEN>". Omitted clones anonymously.
Expand Down
10 changes: 10 additions & 0 deletions go/api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 57 additions & 1 deletion go/api/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/netip"
"net/url"
"regexp"
"strings"

"k8s.io/apimachinery/pkg/util/validation"
Expand All @@ -17,6 +18,10 @@ const (
DefaultDepth = 1
// MaxDepth bounds shallow clones so a typo cannot request unbounded history.
MaxDepth = 1000
// ReadProxyOrigin and PushProxyOrigin are the exact trusted Git listeners.
// Their method, repository and capability checks belong to Mainloop.
ReadProxyOrigin = "http://mainloop-git-read.mainloop.svc.cluster.local"
PushProxyOrigin = "http://mainloop-git-push.mainloop.svc.cluster.local"
)

// Git is the compiled, non-secret Git policy of a Harness revision. The runtime
Expand All @@ -27,7 +32,9 @@ type Git struct {
// Credential reports that the egress gateway injects an Authorization header
// for the single origin. The runtime then sends a placeholder header so the
// gateway has something to overwrite; without it the clone is anonymous.
Credential bool `json:"credential,omitempty"`
Credential bool `json:"credential,omitempty"`
ReadProxyOrigin *string `json:"readProxyOrigin,omitempty"`
PushProxyOrigin *string `json:"pushProxyOrigin,omitempty"`
}

// Validate rejects a policy the runtime cannot enforce.
Expand All @@ -43,9 +50,58 @@ func (g Git) Validate() error {
if g.Credential && len(g.Origins) != 1 {
return fmt.Errorf("a git credential requires exactly one origin")
}
if g.PushProxyOrigin != nil && g.ReadProxyOrigin == nil {
return fmt.Errorf("push proxy requires a read proxy")
}
if g.ReadProxyOrigin != nil {
if *g.ReadProxyOrigin != ReadProxyOrigin || (g.PushProxyOrigin != nil && *g.PushProxyOrigin != PushProxyOrigin) {
return fmt.Errorf("git proxy origins must be the exact trusted listeners")
}
if len(g.Origins) != 1 || g.Origins[0] != "github.com" || g.Credential {
return fmt.Errorf("git proxies require canonical github.com identity and no legacy credential")
}
}
return nil
}

var repositoryComponent = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]*$`)

// Transport returns fetch and push URLs without changing the canonical Session
// identity. In proxy mode only a GitHub owner/repository can select a path.
func (g Git) Transport(repo string) (readURL, pushURL string, err error) {
if err := g.Validate(); err != nil {
return "", "", err
}
host, err := RepoHost(repo)
if err != nil || !g.Allows(host) {
return "", "", fmt.Errorf("repository is outside the Git identity policy")
}
if g.ReadProxyOrigin == nil {
return repo, "", nil
}
u, err := url.Parse(repo)
if err != nil || !strings.EqualFold(u.Host, "github.com") || u.RawPath != "" || strings.ContainsAny(repo, "#%\\") {
return "", "", fmt.Errorf("proxy repository must be canonical HTTPS GitHub owner/repository")
}
parts := strings.Split(strings.TrimPrefix(u.Path, "/"), "/")
if len(parts) != 2 {
return "", "", fmt.Errorf("proxy repository requires exactly owner/repository")
}
parts[1] = strings.TrimSuffix(parts[1], ".git")
for _, part := range parts {
if !repositoryComponent.MatchString(part) {
return "", "", fmt.Errorf("proxy repository has an invalid component")
}
}
path := "/" + strings.ToLower(parts[0]) + "/" + strings.ToLower(parts[1]) + ".git"
readURL = *g.ReadProxyOrigin + path
pushURL = readURL
if g.PushProxyOrigin != nil {
pushURL = *g.PushProxyOrigin + path
}
return readURL, pushURL, nil
}

// Allows reports whether host is one of the origins.
func (g Git) Allows(host string) bool {
host = NormalizeHost(host)
Expand Down
55 changes: 55 additions & 0 deletions go/api/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,58 @@ func TestGitCredentialRequiresOneOrigin(t *testing.T) {
t.Fatal(err)
}
}

func TestProxyPolicyAndTransport(t *testing.T) {
good := Git{Origins: []string{"github.com"}, ReadProxyOrigin: new(ReadProxyOrigin), PushProxyOrigin: new(PushProxyOrigin)}
for _, repo := range []string{"https://github.com/Owner/Repo", "https://GitHub.com/Owner/Repo.git"} {
read, push, err := good.Transport(repo)
if err != nil || read != ReadProxyOrigin+"/owner/repo.git" || push != PushProxyOrigin+"/owner/repo.git" {
t.Fatalf("transport = %q, %q, %v", read, push, err)
}
}
readonly := good
readonly.PushProxyOrigin = nil
read, push, err := readonly.Transport("https://github.com/o/r")
if err != nil || read != push {
t.Fatalf("readonly transport = %q, %q, %v", read, push, err)
}
for _, repo := range []string{
"https://github.com/o", "https://github.com/o/r/extra", "https://github.com/o/r/", "https://github.com//r", "https://github.com/o/..",
"https://github.com/o/%2fr", "https://github.com/o/%72", "https://github.com/o/r%2e%2e", "https://github.com/o/r?x", "https://github.com/o/r#",
"https://github.com./o/r", "https://github.com:443/o/r", "http://github.com/o/r", "https://user@github.com/o/r",
"https://mainloop-git-read.mainloop.svc.cluster.local/o/r", "https://github.com/o/r\\extra",
} {
t.Run(repo, func(t *testing.T) {
if _, _, err := good.Transport(repo); err == nil {
t.Fatal("accepted invalid proxy identity")
}
})
}
for name, mutate := range map[string]func(*Git){
"push without read": func(g *Git) { g.ReadProxyOrigin = nil },
"legacy credential": func(g *Git) { g.Credential = true },
"other identity": func(g *Git) { g.Origins = []string{"gitlab.com"} },
"multiple identities": func(g *Git) { g.Origins = []string{"github.com", "gitlab.com"} },
"empty read": func(g *Git) { g.ReadProxyOrigin = new("") },
} {
t.Run(name, func(t *testing.T) {
g := good
mutate(&g)
if err := g.Validate(); err == nil {
t.Fatal("accepted invalid policy")
}
})
}
for _, bad := range []string{ReadProxyOrigin + "/", ReadProxyOrigin + ":80", ReadProxyOrigin + ".", ReadProxyOrigin + "?", ReadProxyOrigin + "#", "http://MAINLOOP-git-read.mainloop.svc.cluster.local", "http://127.0.0.1"} {
g := good
g.ReadProxyOrigin = new(bad)
if err := g.Validate(); err == nil {
t.Fatalf("accepted %q", bad)
}
}
legacy := Git{Origins: []string{"gitlab.com"}, Credential: true}
read, push, err = legacy.Transport("https://gitlab.com/group/subgroup/repo.git")
if err != nil || read != "https://gitlab.com/group/subgroup/repo.git" || push != "" {
t.Fatalf("legacy = %q %q %v", read, push, err)
}
}
Loading
Loading