platform9 / ssh-provider

SSH Machine Controller for the Cluster API
11 stars 4 forks source link

Add sudo support to ssh machine client #28

Open dlipovetsky opened 6 years ago

dlipovetsky commented 6 years ago

Not every operation on the machine requires sudo, so I suggest that we do not decide to use sudo at client create time.

I think that for each function the client provides, it should provide a variant that takes a user as input:

RunCommandAs(username, cmd string) ([]byte, []byte, error)
WriteFileAs(username, path string, mode os.FileMode, b []byte) error
ReadFileAs(username, path string) ([]byte, error)
MkdirAllAs(username string, path string, mode os.FileMode) error

As for the implementation of the file/dir commands, I think SFTP is causing more trouble than it's worth. If we change the implementation, we can keep the current operations. I tested these manually. I think we can assume that all hosts have tee and cat.

WriteFile(As)

1. (sudo) tee $path > /dev/null
2. (sudo) chmod $mode $path

ReadFile(As)

1. (sudo) cat $path

MkdirAll(As)

1. (sudo) mkdir -p $path
2. (sudo) chmod $path
dlipovetsky commented 6 years ago

Proposed improvement filed: https://github.com/platform9/ssh-provider/issues/28