Skip to content

Commit

Permalink
Allow to fetch and apply certificates with root user read only access (
Browse files Browse the repository at this point in the history
…#7678)

* readonly file scp fix error

Signed-off-by: Vivek Shankar <vshankar@progress.com>

* removed sudo

Signed-off-by: Vivek Shankar <vshankar@progress.com>

* added sudo while cat

Signed-off-by: Vivek Shankar <vshankar@progress.com>

Signed-off-by: Vivek Shankar <vshankar@progress.com>
  • Loading branch information
vivekshankar1 committed Jan 27, 2023
1 parent 58d822a commit aa7f3b4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/automate-cli/cmd/chef-automate/certRotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (c *certRotateFlow) getCertFromFile(certPath string, infra *AutomteHAInfraD
certPath = strings.TrimSpace(certPath)
// Checking if the given path is remote or local.
if c.IsRemotePath(certPath) {
remoteFilePath, fileName, hostIP, err := c.GetRemoteFileDetails(certPath, infra)
remoteFilePath, _, hostIP, err := c.GetRemoteFileDetails(certPath, infra)
if err != nil {
return nil, err
}
Expand All @@ -608,12 +608,11 @@ func (c *certRotateFlow) getCertFromFile(certPath string, infra *AutomteHAInfraD
sshConfig.hostIP = hostIP
sshUtil := NewSSHUtil(sshConfig)

filePath, err := sshUtil.copyFileFromRemote(remoteFilePath, fileName)
out, err := sshUtil.connectAndExecuteCommandOnRemote("sudo cat "+remoteFilePath, true)
if err != nil {
return nil, errors.New(fmt.Sprintf("Unable to copy file from remote path: %v", certPath))
return nil, errors.Wrap(err, fmt.Sprintf("Unable to read file from remote path: %v", certPath))
}
defer os.Remove(filePath)
return c.FileUtils.ReadFile(filePath)
return []byte(out), nil
}
return c.FileUtils.ReadFile(certPath)
}
Expand Down

0 comments on commit aa7f3b4

Please sign in to comment.