Search code examples
c#hpc

How to programatically set user password credentials when connecting to an HPC Scheduler


I am trying to schedule a job on an HPC Server 2019 cluster. I would like to do this without having to enter the password of the service account that I am using. Below is the code but the without commenting the line of code it fails to connect

        string userName = GetKeyVaultSecret("ServiceAccount");
        string password = GetKeyVaultSecret("ServiceAccountPassword");

        using (IScheduler scheduler = new Scheduler())
        {
            try
            {
                    // Connect to the scheduler as another user
                    Console.WriteLine("Connecting to {0} as {1}...", clusterName, userName);
                    scheduler.SetCachedCredentials(userName,password); // If I comment this line I am prompted for a password and it connects
                    scheduler.ConnectServiceAsClient(clusterName, () => userName);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Could not connect to the scheduler: {0}", e.Message);
                if (e.InnerException != null) Console.WriteLine(e.InnerException.Message.ToString());
                return 1; 
            }

Solution

  • The mistake was that I should not be setting the username and password here but when I submit the job

            scheduler.SubmitJob(job, @"domain\" + userName, password);