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
44 changes: 44 additions & 0 deletions docs/architecture/configuration-and-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,47 @@ Agent's last successful revision.
This replaces implicit label selection and the old template/Harness inputs as a
breaking API change. SandboxTemplate hosting configuration is not part of this
change.

## Credential-free package origins

Trusted Harness authors can configure `spec.extraHTTPSOrigins` for Codex and
Claude. This is a bounded list (at most 32 entries) of exact HTTPS DNS origins
on port 443. An omitted port and a root slash are accepted; hostnames are
lowercased and destinations sorted and deduplicated. Wildcards, IP addresses,
userinfo, queries, fragments, other ports and non-root paths are rejected during
compilation, before runtime preparation. Other harness types reject this field.
The schema also bounds entries and rejects unsupported URL shapes.

For npm, PyPI and Go package downloads, an operator may explicitly grant:

```yaml
spec:
extraHTTPSOrigins:
- https://registry.npmjs.org
- https://pypi.org
- https://files.pythonhosted.org
- https://proxy.golang.org
- https://sum.golang.org
- https://storage.googleapis.com
```

These entries join the existing provider, Git, MCP, skills and telemetry egress
destinations in the immutable prepared revision. Changing the destination list
changes revision identity. Existing Sessions retain their pinned policy. An
absent list preserves the default policy. The extra list creates no credential
bindings or runtime environment/configuration effects; a host already carrying
a provider, Git or MCP credential binding is rejected as an extra origin.

Each grant allows the **whole host**, including `storage.googleapis.com`, rather
than a particular bucket, package, HTTP method or path. Audit the union of all
existing grants. Registry access does not enforce package approval or prevent
publishing or exfiltration to an allowed host. Unlisted redirect targets, VCS
sources and binary download hosts fail closed; obtain an explicit reviewed
policy change rather than adding suffix grants or automatic fallback hosts.

Harness policy, including an inline Agent Harness, must remain controlled by
trusted configuration authors. Session requests and AgentTemplates cannot
supply this list. This field does not add actor authority to edit Harnesses or
Agents. Cluster gateway host configuration and live package-installation proof
are separate deployment work; this compiler contract alone does not demonstrate
registry reachability.
16 changes: 16 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 @@ -95,6 +95,19 @@ spec:
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
extraHTTPSOrigins:
description: |-
ExtraHTTPSOrigins grants whole-host HTTPS access without credentials.
Only trusted Harness authors may configure it; each entry is an exact
DNS origin on port 443, with an optional root slash. No suffix grants.
Only the Codex and Claude adapters support it.
items:
maxLength: 273
pattern: ^https://([A-Za-z0-9]([-A-Za-z0-9]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]([-A-Za-z0-9]{0,61}[A-Za-z0-9])?(:443)?/?$
type: string
maxItems: 32
type: array
x-kubernetes-list-type: set
git:
description: |-
Git lets sessions bootstrap a repository checkout into the workspace.
Expand Down Expand Up @@ -338,6 +351,9 @@ spec:
rule: '!has(self.byo) || size(self.workload.command) > 0'
- message: git is supported only by the codex and claude harnesses
rule: '!has(self.git) || has(self.codex) || has(self.claude)'
- message: extraHTTPSOrigins is supported only by the codex and claude
harnesses
rule: '!has(self.extraHTTPSOrigins) || has(self.codex) || has(self.claude)'
harnessRef:
description: |-
LocalObjectReference contains enough information to let you locate the
Expand Down
16 changes: 16 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 @@ -88,6 +88,19 @@ spec:
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
extraHTTPSOrigins:
description: |-
ExtraHTTPSOrigins grants whole-host HTTPS access without credentials.
Only trusted Harness authors may configure it; each entry is an exact
DNS origin on port 443, with an optional root slash. No suffix grants.
Only the Codex and Claude adapters support it.
items:
maxLength: 273
pattern: ^https://([A-Za-z0-9]([-A-Za-z0-9]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]([-A-Za-z0-9]{0,61}[A-Za-z0-9])?(:443)?/?$
type: string
maxItems: 32
type: array
x-kubernetes-list-type: set
git:
description: |-
Git lets sessions bootstrap a repository checkout into the workspace.
Expand Down Expand Up @@ -330,6 +343,9 @@ spec:
rule: '!has(self.byo) || size(self.workload.command) > 0'
- message: git is supported only by the codex and claude harnesses
rule: '!has(self.git) || has(self.codex) || has(self.claude)'
- message: extraHTTPSOrigins is supported only by the codex and claude
harnesses
rule: '!has(self.extraHTTPSOrigins) || has(self.codex) || has(self.claude)'
status:
description: HarnessStatus reports controller-derived capabilities and
current health.
Expand Down
12 changes: 12 additions & 0 deletions go/api/v1alpha3/harness_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type HarnessWorkload struct {
// +kubebuilder:validation:XValidation:rule="(has(self.kagent) ? 1 : 0) + (has(self.codex) ? 1 : 0) + (has(self.claude) ? 1 : 0) + (has(self.byo) ? 1 : 0) == 1",message="exactly one of kagent, codex, claude, or byo must be specified"
// +kubebuilder:validation:XValidation:rule="!has(self.byo) || size(self.workload.command) > 0",message="BYO harnesses must specify workload.command"
// +kubebuilder:validation:XValidation:rule="!has(self.git) || has(self.codex) || has(self.claude)",message="git is supported only by the codex and claude harnesses"
// +kubebuilder:validation:XValidation:rule="!has(self.extraHTTPSOrigins) || has(self.codex) || has(self.claude)",message="extraHTTPSOrigins is supported only by the codex and claude harnesses"
type HarnessSpec struct {
// SessionIdleTTL overrides the controller default for all Sessions of this
// Agent, including existing Sessions. Zero disables idle expiration.
Expand All @@ -187,6 +188,17 @@ type HarnessSpec struct {
// +optional
Git *HarnessGit `json:"git,omitempty"`

// ExtraHTTPSOrigins grants whole-host HTTPS access without credentials.
// Only trusted Harness authors may configure it; each entry is an exact
// DNS origin on port 443, with an optional root slash. No suffix grants.
// Only the Codex and Claude adapters support it.
// +kubebuilder:validation:MaxItems=32
// +kubebuilder:validation:items:MaxLength=273
// +kubebuilder:validation:items:Pattern=`^https://([A-Za-z0-9]([-A-Za-z0-9]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]([-A-Za-z0-9]{0,61}[A-Za-z0-9])?(:443)?/?$`
// +listType=set
// +optional
ExtraHTTPSOrigins []string `json:"extraHTTPSOrigins,omitempty"`

// +required
Workload HarnessWorkload `json:"workload"`

Expand Down
5 changes: 5 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.

5 changes: 2 additions & 3 deletions go/core/internal/controller/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"strings"

atev1alpha1 "github.com/agent-substrate/substrate/pkg/api/v1alpha1"
Expand Down Expand Up @@ -65,9 +66,7 @@ type EnvironmentPreparer struct {

func NewEnvironmentPreparer(collections Collections, store runtimeRevisionStore, templates actorTemplateClient, catalog RuntimePayloadCatalog) *EnvironmentPreparer {
copy := RuntimePayloadCatalog{}
for key, value := range catalog {
copy[key] = value
}
maps.Copy(copy, catalog)
return &EnvironmentPreparer{collections: collections, store: store, templates: templates, catalog: copy}
}

Expand Down
3 changes: 2 additions & 1 deletion go/core/internal/database/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package database

import (
"encoding/json"
"github.com/google/uuid"
"testing"

"github.com/google/uuid"

apiv1alpha1 "github.com/kagent-dev/kagent/go/api/gen/kagent/api/v1alpha1"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
Expand Down
3 changes: 1 addition & 2 deletions go/core/internal/grpcserver/control_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestControlAuthNativeAndWeb(t *testing.T) {
const futurePublic = "/test.Public/Discover"
policies[futurePublic] = pkgauth.AccessPublic
server, err := New(Config{Listener: listener, Authenticator: provider, Reflection: true, MethodPolicies: policies, RegisterServices: func(registrar grpc.ServiceRegistrar) {
registrar.RegisterService(&grpc.ServiceDesc{ServiceName: "test.Public", HandlerType: (*interface{})(nil), Methods: []grpc.MethodDesc{{MethodName: "Discover"}}}, &struct{}{})
registrar.RegisterService(&grpc.ServiceDesc{ServiceName: "test.Public", HandlerType: (*any)(nil), Methods: []grpc.MethodDesc{{MethodName: "Discover"}}}, &struct{}{})
}, SystemService: testSystemService(), SessionService: sessionsvc.NewService(store, policy, credentialTestWorkflow{})})
require.NoError(t, err)
ctx, cancel := context.WithCancel(t.Context())
Expand Down Expand Up @@ -158,7 +158,6 @@ func TestControlAuthNativeAndWeb(t *testing.T) {
require.False(t, called, fullMethod)
}
}

}

// A stream must be refused before its handler receives the first message.
Expand Down
16 changes: 3 additions & 13 deletions go/core/internal/service/controlauth/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func New(config Config) (*Policy, error) {
for _, rule := range config.Credentials {
origin, err := url.Parse(rule.Origin)
_, patternErr := path.Match(rule.SecretNamePattern, "probe")
if rule.Namespace != config.Namespace || rule.SecretNamePattern == "" || patternErr != nil || rule.Key == "" || rule.Purpose != "mcp" || rule.Header != "authorization" || err != nil || (origin.Scheme != "https" && !(origin.Scheme == "http" && slices.Contains(config.CleartextMCPOrigins, rule.Origin))) || origin.Host == "" || origin.User != nil || origin.RawQuery != "" || origin.ForceQuery || origin.Fragment != "" || origin.Path != "" {
if rule.Namespace != config.Namespace || rule.SecretNamePattern == "" || patternErr != nil || rule.Key == "" || rule.Purpose != "mcp" || rule.Header != "authorization" || err != nil || (origin.Scheme != "https" && (origin.Scheme != "http" || !slices.Contains(config.CleartextMCPOrigins, rule.Origin))) || origin.Host == "" || origin.User != nil || origin.RawQuery != "" || origin.ForceQuery || origin.Fragment != "" || origin.Path != "" {
return nil, errors.New("invalid approved credential tuple")
}
}
Expand Down Expand Up @@ -121,12 +121,7 @@ func (p *Policy) approvedDevelopmentImage(image string) bool {
if !qualified {
return false
}
for _, allowed := range p.config.DevelopmentEnvironmentRegistries {
if registry == allowed {
return true
}
}
return false
return slices.Contains(p.config.DevelopmentEnvironmentRegistries, registry)
}

// CheckDevelopmentEnvironment validates all caller selection fields before any
Expand All @@ -144,12 +139,7 @@ func (p *Policy) agent(namespace, name string) bool {
if namespace != p.config.Namespace {
return false
}
for _, allowed := range p.config.Agents {
if name == allowed {
return true
}
}
return false
return slices.Contains(p.config.Agents, name)
}

func internal(ctx context.Context) bool {
Expand Down
8 changes: 8 additions & 0 deletions go/core/internal/translator/claude/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (c *Compiler) Compile(ctx context.Context, input *v2translator.HarnessInput
if input == nil || input.Harness == nil || input.Root == nil || input.Root.Template == nil || input.Root.ResolvedModelConfig == nil || input.Root.ResolvedModelConfig.Config == nil {
return nil, fmt.Errorf("claude compiler requires a resolved Harness, AgentTemplate, and ModelConfig")
}
extraEgress, err := v2translator.CompileExtraHTTPSOrigins(input.Harness.Spec.ExtraHTTPSOrigins)
if err != nil {
return nil, err
}
model := input.Root.ResolvedModelConfig.Config
if strings.TrimSpace(model.Spec.Model) == "" {
return nil, v2translator.NewValidationError("Claude ModelConfig model is required")
Expand Down Expand Up @@ -125,6 +129,10 @@ func (c *Compiler) Compile(ctx context.Context, input *v2translator.HarnessInput
return nil, err
}

if err := v2translator.ValidateExtraHTTPSCredentials(extraEgress, credentials); err != nil {
return nil, err
}
egress = append(egress, extraEgress...)
egress = append(egress, skillEgress...)
egress = append(egress, mcp.egress...)
egress = append(egress, gitEgress...)
Expand Down
8 changes: 8 additions & 0 deletions go/core/internal/translator/codex/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (c *Compiler) Compile(ctx context.Context, input *v2translator.HarnessInput
if input == nil || input.Harness == nil || input.Root == nil || input.Root.Template == nil || input.Root.ResolvedModelConfig == nil || input.Root.ResolvedModelConfig.Config == nil {
return nil, fmt.Errorf("codex compiler requires a resolved Harness, AgentTemplate, and ModelConfig")
}
extraEgress, err := v2translator.CompileExtraHTTPSOrigins(input.Harness.Spec.ExtraHTTPSOrigins)
if err != nil {
return nil, err
}
model := input.Root.ResolvedModelConfig.Config
if strings.TrimSpace(model.Spec.Model) == "" {
return nil, v2translator.NewValidationError("Codex ModelConfig model is required")
Expand Down Expand Up @@ -143,6 +147,10 @@ func (c *Compiler) Compile(ctx context.Context, input *v2translator.HarnessInput
if err != nil {
return nil, err
}
if err := v2translator.ValidateExtraHTTPSCredentials(extraEgress, credentials); err != nil {
return nil, err
}
egress = append(egress, extraEgress...)
egress = append(egress, skillEgress...)
egress = append(egress, mcp.egress...)
egress = append(egress, gitEgress...)
Expand Down
3 changes: 3 additions & 0 deletions go/core/internal/translator/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func (c *Compiler) CompileAgent(ctx context.Context, agent *v1alpha3.Agent) (*Co
// compileConfiguration compiles resolved configuration for the named Agent.
// The Agent name owns runtime identity; template and Harness names are provenance.
func (c *Compiler) compileConfiguration(ctx context.Context, agentName string, harness *HarnessConfiguration, template *TemplateConfiguration) (*CompileResult, error) {
if len(harness.Spec.ExtraHTTPSOrigins) != 0 && harnessType(harness) != HarnessTypeCodex && harnessType(harness) != HarnessTypeClaude {
return nil, NewValidationError("extraHTTPSOrigins is supported only by the codex and claude harnesses")
}
harnessCompiler := c.harnessCompilers[harnessType(harness)]
if harnessCompiler == nil {
return nil, NewValidationError("Harness runtime is not supported by any compiler")
Expand Down
73 changes: 73 additions & 0 deletions go/core/internal/translator/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,76 @@ func TestSessionIdleTTLDoesNotChangeRuntimeRevision(t *testing.T) {
})
}
}

func TestCompileAgentExtraHTTPSOrigins(t *testing.T) {
for _, harnessType := range []v2translator.HarnessType{v2translator.HarnessTypeCodex, v2translator.HarnessTypeClaude} {
t.Run(string(harnessType), func(t *testing.T) {
harness, template, model := runtimeFixture(harnessType)
harness.Spec.Git = &v1alpha3.HarnessGit{
Origins: []string{"github.com"},
CredentialSecretRef: &v1alpha3.SecretKeyReference{Name: "git-auth", Key: "authorization"},
}
server := remoteMCPServer("packages-test-mcp", "https://mcp.example.com/mcp")
server.Spec.HeadersFrom = []v1alpha3.ValueRef{{Name: "Authorization", ValueFrom: &v1alpha3.ValueSource{Type: v1alpha3.SecretValueSource, Name: "mcp-auth", Key: "token"}}}
template.Spec.Tools = []v1alpha3.ToolBinding{{MCP: &v1alpha3.MCPToolBinding{Server: corev1.TypedLocalObjectReference{Kind: "RemoteMCPServer", Name: server.Name}, Tools: []string{"lookup"}}}}
objects := []any{model, server,
&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: "mcp-auth"}, Data: map[string][]byte{"token": []byte("mcp-secret")}},
&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: "model-auth"}, Data: map[string][]byte{"api-key": []byte("secret")}},
&atev1alpha1.WorkerPool{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: "selected"}},
}
compile := func(origins []string) *v2translator.CompileResult {
harness.Spec.ExtraHTTPSOrigins = origins
result, err := compiler(t, objects...).CompileAgent(t.Context(), inlineAgent(harness, template))
require.NoError(t, err)
return result
}
baseline := compile(nil)
origins := []string{"https://registry.npmjs.org", "https://pypi.org", "https://files.pythonhosted.org", "https://proxy.golang.org", "https://sum.golang.org", "https://storage.googleapis.com"}
configured := compile(origins)
for _, origin := range origins {
require.Contains(t, configured.EgressDestinations, origin+":443")
}
for _, origin := range baseline.EgressDestinations {
require.Contains(t, configured.EgressDestinations, origin)
}
require.Equal(t, baseline.Credentials, configured.Credentials)
require.Equal(t, baseline.Environment, configured.Environment)
require.Equal(t, baseline.ConfigJSON, configured.ConfigJSON)
before, err := baseline.Digest()
require.NoError(t, err)
after, err := configured.Digest()
require.NoError(t, err)
require.NotEqual(t, before, after)
require.Equal(t, origins, harness.Spec.ExtraHTTPSOrigins)
reordered := slices.Clone(origins)
slices.Reverse(reordered)
reordered = append(reordered, "https://PYPI.org:443/")
normalized := compile(reordered)
require.Equal(t, configured.EgressDestinations, normalized.EgressDestinations)
// Source provenance retains authored spelling/order, independently of the
// canonical destinations used by the prepared policy.
for _, invalid := range []string{"http://pypi.org", "https://*.pypi.org", "https://pypi.org:8443", "https://127.0.0.1", "https://user@pypi.org", "https://pypi.org/simple", "https://github.com", "https://mcp.example.com", "https://api.openai.com", "https://api.anthropic.com"} {
if (invalid == "https://api.openai.com" && harnessType == v2translator.HarnessTypeClaude) || (invalid == "https://api.anthropic.com" && harnessType == v2translator.HarnessTypeCodex) {
continue
}
harness.Spec.ExtraHTTPSOrigins = []string{invalid}
result, err := compiler(t, objects...).CompileAgent(t.Context(), inlineAgent(harness, template))
require.Error(t, err)
require.Nil(t, result)
require.ErrorAs(t, err, new(*v2translator.ValidationError))
}
})
}
}

func TestCompileAgentRejectsExtraHTTPSOriginsForOtherHarnesses(t *testing.T) {
for _, harnessType := range []v2translator.HarnessType{v2translator.HarnessTypeKagent, v2translator.HarnessTypeBYO} {
t.Run(string(harnessType), func(t *testing.T) {
harness, template, _ := runtimeFixture(harnessType)
harness.Spec.ExtraHTTPSOrigins = []string{"https://pypi.org"}
result, err := compiler(t).CompileAgent(t.Context(), inlineAgent(harness, template))
require.ErrorContains(t, err, "extraHTTPSOrigins is supported only")
require.Nil(t, result)
})
}
}
Loading
Loading