How to retrieve kerberos ticket in order to mount Windows share from Jenkins pipeline?

Viewed 41

I have a Jenkins job that need to mount a remote Windows share to copy content into it. My Jenkins pipeline has a step where a bash script is triggered to:

  1. Refresh Kerberos ticket
  2. Mount Windows share on a temporary mountpoint with "sec=kerberos"

Strangely it is not functionning anymore and now I have a puzzling mount error:

mount.cifs kernel mount options: ip=XXX.XXX.XXX.XXX,unc=\server.domain.tld\C$,sec=krb5,vers=2.1,uid=XXX,gid=XXX,user=xxxxx@DOMAIN/TLD,prefixpath=share_folder,pass=******** mount error(126): Required key not available

Bash script (snippet)

kinit -V -R -k -t $WINRM_KERBEROS_KEYTAB $user
sudo mount -v -t cifs -o username=$user,sec=krb5,uid=$USER,gid=$USER,vers=2.1 "${smb_path}" "${mount_point}"

Jenkins file (snippet)

    stage("Monitoring scripts deployment") {
        when {
              expression {
                 params.ACTION == "Monitoring scripts deployment"
             }                        
        }
        
        steps {
            
            script {
                def server_list = params.SERVER_LIST.trim()
                
                def bash_script = """
                                     ${WORKSPACE}/deploy.sh --user ${WINRM_USER} --keytab ${WINRM_KERBEROS_KEYTAB} --action install --sourcedir ${WORKSPACE}/scripts --targetdir 'share_folder' --servers ${server_list}
                                  """ 
           
                def status_code = sh( script:bash_script, returnStatus:true )    

               if (status_code == 1){

                    def message = "Monitoring scripts can't be deployed"
                    catchError(message: message, buildResult: 'FAILURE', stageResult: 'FAILURE') {
                        error "$message"
                    }
                }                 
            }
        }
    }

Please note that issuing the same commands of the Bash script in a root shell works perfectly.

How could I make this Jenkins pipeline work as it use to and mount Windows share using Kerberos.

0 Answers
Related