@@ -16,10 +16,13 @@ import (
1616 corev1 "k8s.io/api/core/v1"
1717 "k8s.io/apimachinery/pkg/api/resource"
1818 "k8s.io/apimachinery/pkg/types"
19+ "k8s.io/apimachinery/pkg/util/validation"
1920
2021 apia2a "github.com/kagent-dev/kagent/go/api/a2a"
22+ "github.com/kagent-dev/kagent/go/core/internal/image"
2123 "github.com/kagent-dev/kagent/go/core/internal/translator"
2224 "github.com/kagent-dev/kagent/go/core/pkg/env"
25+ "github.com/kagent-dev/kagent/go/pkg/toolpath"
2326 "github.com/kagent-dev/kagent/go/pkg/tracing"
2427)
2528
@@ -39,6 +42,10 @@ const egressTrustMount = "/run/kagent/egress"
3942const actorIdentityVolume = "actor-identity"
4043const actorIdentityMount = "/run/kagent/identity"
4144
45+ // Tool image volumes carry a prefix so a tool named like a built-in volume
46+ // cannot collide with it.
47+ const toolImageVolumePrefix = "tool-"
48+
4249var egressTrustEnvironment = map [string ]struct {}{
4350 "SSL_CERT_FILE" : {}, "SSL_CERT_DIR" : {}, "REQUESTS_CA_BUNDLE" : {}, "AWS_CA_BUNDLE" : {},
4451 "NODE_EXTRA_CA_CERTS" : {}, "CURL_CA_BUNDLE" : {}, "GIT_SSL_CAINFO" : {},
@@ -71,11 +78,21 @@ func ActorTemplateForRevision(spec *translator.Revision, revisionID translator.R
7178 if _ , owned := egressTrustEnvironment [variable .Name ]; owned {
7279 return nil , fmt .Errorf ("runtime environment %q conflicts with gateway trust" , variable .Name )
7380 }
81+ if variable .Name == toolpath .EnvName {
82+ return nil , fmt .Errorf ("runtime environment %q is reserved for tool images" , variable .Name )
83+ }
7484 }
7585 for _ , name := range []string {"SSL_CERT_FILE" , "REQUESTS_CA_BUNDLE" , "AWS_CA_BUNDLE" , "NODE_EXTRA_CA_CERTS" , "CURL_CA_BUNDLE" , "GIT_SSL_CAINFO" } {
7686 environment = append (environment , corev1.EnvVar {Name : name , Value : egressTrustMount + "/trust-bundle.pem" })
7787 }
7888 environment = append (environment , corev1.EnvVar {Name : "SSL_CERT_DIR" , Value : egressTrustMount })
89+ toolVolumes , toolMounts , toolNames , err := toolImageVolumes (spec .ToolImages )
90+ if err != nil {
91+ return nil , err
92+ }
93+ if len (toolNames ) > 0 {
94+ environment = append (environment , corev1.EnvVar {Name : toolpath .EnvName , Value : toolpath .JoinBinDirs (toolNames )})
95+ }
7996 environment = append (environment ,
8097 corev1.EnvVar {Name : "KAGENT_CONFIG_JSON" , Value : string (spec .ConfigJSON )},
8198 corev1.EnvVar {Name : "KAGENT_AGENT_CARD_JSON" , Value : string (cardJSON )},
@@ -105,11 +122,11 @@ func ActorTemplateForRevision(spec *translator.Revision, revisionID translator.R
105122 Path : "/readyz" ,
106123 Port : 8081 ,
107124 }, TimeoutSeconds : 30 },
108- VolumeMounts : []* ateapipb.VolumeMount {
125+ VolumeMounts : append ( []* ateapipb.VolumeMount {
109126 {Name : durableDataVolume , MountPath : durableDataMount },
110127 {Name : egressTrustVolume , MountPath : egressTrustMount },
111128 {Name : actorIdentityVolume , MountPath : actorIdentityMount },
112- },
129+ }, toolMounts ... ),
113130 }},
114131 WorkerSelector : workerSelectorForPool (workerKey ),
115132 SnapshotConfig : & ateapipb.SnapshotConfig {
@@ -118,7 +135,7 @@ func ActorTemplateForRevision(spec *translator.Revision, revisionID translator.R
118135 // Pin the server default so immutable comparison survives creation.
119136 GoldenSnapshotConfig : & ateapipb.GoldenSnapshotConfig {Mode : ateapipb .GoldenSnapshotMode_GOLDEN_SNAPSHOT_MODE_ENABLED },
120137 },
121- Volumes : []* ateapipb.Volume {
138+ Volumes : append ( []* ateapipb.Volume {
122139 {Name : durableDataVolume , DurableDir : & ateapipb.DurableDirVolumeSource {}},
123140 // Substrate regenerates this projection on Run and Restore. A fork
124141 // therefore routes storage calls as its own actor, never its source.
@@ -130,7 +147,7 @@ func ActorTemplateForRevision(spec *translator.Revision, revisionID translator.R
130147 {Name : egressTrustVolume , SystemInfo : & ateapipb.SystemInfoVolumeSource {DataSources : []* ateapipb.SystemInfoDataSource {
131148 {TrustBundle : & ateapipb.TrustBundleDataSource {Names : []string {"egress-mitm.ate.dev" }, Path : "trust-bundle.pem" }},
132149 }}},
133- },
150+ }, toolVolumes ... ),
134151 }
135152 for i , image := range spec .SkillImages {
136153 name := fmt .Sprintf ("skill-%d" , i )
@@ -147,6 +164,33 @@ func ActorTemplateForRevision(spec *translator.Revision, revisionID translator.R
147164 return template , nil
148165}
149166
167+ // toolImageVolumes projects each tool image as a read-only image volume mounted
168+ // under toolpath.MountRoot. The CRD validates the entries; the check here keeps
169+ // a hand-built revision on the same contract Substrate enforces.
170+ func toolImageVolumes (images []translator.ToolImage ) ([]* ateapipb.Volume , []* ateapipb.VolumeMount , []string , error ) {
171+ var volumes []* ateapipb.Volume
172+ var mounts []* ateapipb.VolumeMount
173+ var names []string
174+ seen := make (map [string ]struct {}, len (images ))
175+ for _ , tool := range images {
176+ if errs := validation .IsDNS1123Label (tool .Name ); len (errs ) > 0 {
177+ return nil , nil , nil , fmt .Errorf ("tool image name %q: %s" , tool .Name , strings .Join (errs , "; " ))
178+ }
179+ if _ , duplicate := seen [tool .Name ]; duplicate {
180+ return nil , nil , nil , fmt .Errorf ("tool image name %q is listed twice" , tool .Name )
181+ }
182+ seen [tool .Name ] = struct {}{}
183+ if ! image .IsDigestPinned (tool .Reference ) {
184+ return nil , nil , nil , fmt .Errorf ("tool image %q must be pinned by sha256 digest" , tool .Name )
185+ }
186+ volumeName := toolImageVolumePrefix + tool .Name
187+ volumes = append (volumes , & ateapipb.Volume {Name : volumeName , Image : & ateapipb.ImageVolumeSource {Reference : tool .Reference }})
188+ mounts = append (mounts , & ateapipb.VolumeMount {Name : volumeName , MountPath : toolpath .MountPath (tool .Name )})
189+ names = append (names , tool .Name )
190+ }
191+ return volumes , mounts , names , nil
192+ }
193+
150194// ActorTemplateSpecEqual compares the client-owned immutable fields of two
151195// templates, excluding server-owned metadata and golden-snapshot status.
152196func ActorTemplateSpecEqual (left , right * ateapipb.ActorTemplate ) bool {
0 commit comments