@@ -52,19 +52,22 @@ const remove = (args: readonly string[], inspect: readonly string[], remaining:
5252 if ( ! absent ( check ) ) throw new Error ( `Failed to confirm removal of ${ kind } .` ) ;
5353} ;
5454
55- export function assertVendorNetwork ( network : VendorNetwork , invocation ?: InvocationInput , agentName ?: string ) : void {
55+ const validateVendorNetwork = ( network : VendorNetwork , invocation : InvocationInput | undefined ,
56+ agentName : string | undefined , remaining : ( ) => number ) : void => {
5657 const identity = identities . get ( network ) ;
5758 if ( ! identity ) throw new Error ( 'Vendor network was not created by the trusted network builder.' ) ;
5859 if ( invocation && ( identity . invocation !== invocation || network . vendor !== invocation . vendor ) )
5960 throw new Error ( 'Vendor network does not belong to this invocation.' ) ;
6061 assertBuiltAgentImage ( identity . imageId ) ;
61- const inspect = JSON . parse ( docker ( [ 'container' , 'inspect' , network . proxyContainer ] , 30_000 ) ) [ 0 ] as
62+ const inspect = JSON . parse ( docker ( [ 'container' , 'inspect' , network . proxyContainer ] , remaining ( ) ) ) [ 0 ] as
6263 { State ?: { Running ?: boolean } ; Config ?: { Image ?: string ; User ?: string ; Labels ?: Record < string , string > ; Env ?: string [ ] ;
6364 Entrypoint ?: string [ ] | null ; Cmd ?: string [ ] | null } ;
6465 HostConfig ?: { ReadonlyRootfs ?: boolean ; Privileged ?: boolean ; CapDrop ?: string [ ] ; CapAdd ?: string [ ] | null ;
65- SecurityOpt ?: string [ ] ; Memory ?: number ; MemorySwap ?: number ; NanoCpus ?: number ; PidsLimit ?: number } ;
66+ SecurityOpt ?: string [ ] ; Memory ?: number ; MemorySwap ?: number ; NanoCpus ?: number ; PidsLimit ?: number ;
67+ NetworkMode ?: string ; PidMode ?: string ; IpcMode ?: string ; UTSMode ?: string ; UsernsMode ?: string ;
68+ CgroupnsMode ?: string ; Devices ?: unknown [ ] | null ; DeviceRequests ?: unknown [ ] | null } ;
6669 NetworkSettings ?: { Networks ?: Record < string , unknown > } ; Mounts ?: unknown [ ] } | undefined ;
67- const inspectedNetwork = JSON . parse ( docker ( [ 'network' , 'inspect' , network . name ] , 30_000 ) ) [ 0 ] as
70+ const inspectedNetwork = JSON . parse ( docker ( [ 'network' , 'inspect' , network . name ] , remaining ( ) ) ) [ 0 ] as
6871 { Internal ?: boolean ; Driver ?: string ; Labels ?: Record < string , string > ; IPAM ?: { Config ?: Array < { Subnet ?: string } > } ;
6972 Containers ?: Record < string , { Name ?: string } > } | undefined ;
7073 const networks = Object . keys ( inspect ?. NetworkSettings ?. Networks ?? { } ) . sort ( ) ;
@@ -77,6 +80,10 @@ export function assertVendorNetwork(network: VendorNetwork, invocation?: Invocat
7780 || ! [ 'no-new-privileges' , 'no-new-privileges:true' ] . includes ( inspect . HostConfig . SecurityOpt [ 0 ] ?? '' )
7881 || inspect . HostConfig . PidsLimit !== 64 || inspect . HostConfig . Memory !== 64 * 1024 * 1024
7982 || inspect . HostConfig . MemorySwap !== 64 * 1024 * 1024 || inspect . HostConfig . NanoCpus !== 250_000_000
83+ || inspect . HostConfig . NetworkMode !== network . name || inspect . HostConfig . PidMode !== ''
84+ || inspect . HostConfig . IpcMode !== 'private' || inspect . HostConfig . UTSMode !== ''
85+ || inspect . HostConfig . UsernsMode !== '' || inspect . HostConfig . CgroupnsMode !== 'private'
86+ || ( inspect . HostConfig . Devices ?. length ?? 0 ) !== 0 || ( inspect . HostConfig . DeviceRequests ?. length ?? 0 ) !== 0
8087 || JSON . stringify ( networks ) !== JSON . stringify ( [ 'bridge' , network . name ] . sort ( ) ) || inspect . Mounts ?. length
8188 || inspect . Config ?. Entrypoint ?. [ 0 ] !== 'node'
8289 || JSON . stringify ( inspect . Config ?. Cmd ) !== JSON . stringify ( [ '/usr/local/lib/codeboost-egress-proxy.mjs' ] )
@@ -87,6 +94,12 @@ export function assertVendorNetwork(network: VendorNetwork, invocation?: Invocat
8794 || inspectedNetwork . IPAM ?. Config ?. length !== 1 || inspectedNetwork . IPAM . Config [ 0 ] ?. Subnet !== identity . subnet
8895 || ! endpoints . includes ( network . proxyContainer ) || endpoints . some ( name => ! name || ! allowedEndpoints . includes ( name ) ) )
8996 throw new Error ( 'Vendor network or proxy changed after allocation.' ) ;
97+ remaining ( ) ;
98+ } ;
99+
100+ export function assertVendorNetwork ( network : VendorNetwork , invocation ?: InvocationInput , agentName ?: string ,
101+ timeoutMs = 30_000 ) : void {
102+ validateVendorNetwork ( network , invocation , agentName , deadline ( timeoutMs ) ) ;
90103}
91104
92105export function createVendorNetwork ( invocation : InvocationInput , imageId : string ,
@@ -118,7 +131,7 @@ export function createVendorNetwork(invocation: InvocationInput, imageId: string
118131 ] . join ( '' ) ] , remaining ( ) ) ;
119132 const network = Object . freeze ( { name, proxyContainer, proxyUrl : 'http://codeboost-proxy:3128' , vendor } ) ;
120133 identities . set ( network , Object . freeze ( { allocationId, imageId, invocation, subnet } ) ) ;
121- assertVendorNetwork ( network , invocation ) ;
134+ validateVendorNetwork ( network , invocation , undefined , remaining ) ;
122135 remaining ( ) ;
123136 return network ;
124137 } catch ( error ) {
0 commit comments