@@ -20,9 +20,15 @@ public ContainerExecutor(ILogger<ContainerExecutor> logger, IConfiguration confi
2020 _dockerClient = new DockerClientConfiguration ( new Uri ( dockerEndpoint ) ) . CreateClient ( ) ;
2121 }
2222
23- public async Task < bool > ExecuteJobAsync ( Job job , Func < string , Task > orchestratorLogCallback , Func < string , Task > containerOutputCallback )
23+ public async Task < bool > ExecuteJobAsync (
24+ Job job ,
25+ Func < string , Task > orchestratorLogCallback ,
26+ Func < string , Task > containerOutputCallback ,
27+ byte [ ] ? certificatePfx = null ,
28+ string ? certificatePassword = null )
2429 {
2530 string ? containerId = null ;
31+ string ? tempCertPath = null ;
2632
2733 try
2834 {
@@ -38,6 +44,26 @@ public async Task<bool> ExecuteJobAsync(Job job, Func<string, Task> orchestrator
3844 envVars . Add ( $ "SCRIPT_PATH={ job . ScriptPath } ") ;
3945 envVars . Add ( $ "WHAT_IF={ job . IsWhatIf } ") ;
4046
47+ // Handle certificate if provided
48+ var binds = new List < string > ( ) ;
49+ if ( certificatePfx != null && ! string . IsNullOrEmpty ( certificatePassword ) )
50+ {
51+ await orchestratorLogCallback ( "Certificate provided - preparing for container" ) ;
52+
53+ // Write certificate to temp file
54+ tempCertPath = Path . Combine ( Path . GetTempPath ( ) , $ "cert-{ job . Id } .pfx") ;
55+ await File . WriteAllBytesAsync ( tempCertPath , certificatePfx ) ;
56+
57+ // Mount certificate into container
58+ binds . Add ( $ "{ tempCertPath } :/tmp/client-cert.pfx:ro") ;
59+
60+ // Add certificate environment variables
61+ envVars . Add ( "CLIENT_CERT_PATH=/tmp/client-cert.pfx" ) ;
62+ envVars . Add ( $ "CLIENT_CERT_PASSWORD={ certificatePassword } ") ;
63+
64+ _logger . LogInformation ( "Certificate mounted for job {JobId}" , job . Id ) ;
65+ }
66+
4167 await orchestratorLogCallback ( $ "Pulling container image: { job . ContainerImage } ") ;
4268
4369 // Debug: Log registry credential availability
@@ -140,7 +166,8 @@ await _dockerClient.Images.CreateImageAsync(
140166 Env = envVars ,
141167 HostConfig = new HostConfig
142168 {
143- AutoRemove = true
169+ AutoRemove = true ,
170+ Binds = binds . Any ( ) ? binds : null
144171 } ,
145172 Name = $ "iam-job-{ job . Id } "
146173 } ) ;
@@ -175,6 +202,20 @@ await _dockerClient.Images.CreateImageAsync(
175202 }
176203 finally
177204 {
205+ // Cleanup temp certificate file
206+ if ( ! string . IsNullOrEmpty ( tempCertPath ) && File . Exists ( tempCertPath ) )
207+ {
208+ try
209+ {
210+ File . Delete ( tempCertPath ) ;
211+ _logger . LogDebug ( "Deleted temporary certificate file: {Path}" , tempCertPath ) ;
212+ }
213+ catch ( Exception ex )
214+ {
215+ _logger . LogWarning ( ex , "Failed to delete temporary certificate file: {Path}" , tempCertPath ) ;
216+ }
217+ }
218+
178219 // Cleanup
179220 if ( containerId != null )
180221 {
0 commit comments