@@ -170,6 +170,53 @@ func (c *GitClone) setupBasicAuth() error {
170170 return fmt .Errorf ("unknown basic-auth workspace format: expected .git-credentials/.gitconfig or username/password files" )
171171}
172172
173+ // setupSSH sets up SSH keys from an ssh-directory workspace.
174+ func (c * GitClone ) setupSSH () error {
175+ if c .Params .SshDirectory == "" {
176+ return nil
177+ }
178+
179+ sshDir := c .Params .SshDirectory
180+ userHome := c .Params .UserHome
181+
182+ // Check if the SSH directory exists
183+ if _ , err := os .Stat (sshDir ); os .IsNotExist (err ) {
184+ l .Logger .Infof ("SSH directory not found: %s" , sshDir )
185+ return nil
186+ }
187+
188+ l .Logger .Infof ("Setting up SSH keys from %s" , sshDir )
189+
190+ destSSHDir := filepath .Join (userHome , ".ssh" )
191+
192+ // Create destination .ssh directory
193+ if err := os .MkdirAll (destSSHDir , 0700 ); err != nil {
194+ return fmt .Errorf ("failed to create .ssh directory: %w" , err )
195+ }
196+
197+ // Copy all files from source to destination
198+ entries , err := os .ReadDir (sshDir )
199+ if err != nil {
200+ return fmt .Errorf ("failed to read SSH directory: %w" , err )
201+ }
202+
203+ for _ , entry := range entries {
204+ if entry .IsDir () {
205+ continue // Skip subdirectories
206+ }
207+
208+ srcPath := filepath .Join (sshDir , entry .Name ())
209+ destPath := filepath .Join (destSSHDir , entry .Name ())
210+
211+ if err := copyFile (srcPath , destPath , 0400 ); err != nil {
212+ return fmt .Errorf ("failed to copy SSH file %s: %w" , entry .Name (), err )
213+ }
214+ }
215+
216+ l .Logger .Info ("SSH keys configured" )
217+ return nil
218+ }
219+
173220// fileExists checks if a file exists and is not a directory.
174221func fileExists (path string ) bool {
175222 info , err := os .Stat (path )
0 commit comments