Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Store SSH private key on the file system from SSH plugin #352

Merged
merged 5 commits into from
Jul 19, 2019

Conversation

vinokurig
Copy link
Contributor

What does this PR do?

Store SSH private key file on the file system when key is generated from the SSH Plugin

What issues does this PR fix or reference?

fixes eclipse-che/che#13866

Release Notes

Docs PR

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@sunix
Copy link
Contributor

sunix commented Jul 16, 2019

@vinokurig Could you describe the end user flow that would use that ?
How can I test it ? how can I set ssh keys ?

Copy link
Contributor

@l0rd l0rd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that a user will generate/create a key pair and update the ssh config in theia container. This is an operation that the user will do only once.

Then, when he delete this workspace and creates a new one, the SSH key pair will be mounted as a Kubernetes secret. But what about the SSH config? Will it be re-generated and mounted as well?

plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
@evidolob evidolob added this to the 7.0.0 milestone Jul 17, 2019
@vparfonov
Copy link
Contributor

I understand that a user will generate/create a key pair and update the ssh config in theia container. This is an operation that the user will do only once.

Then, when he delete this workspace and creates a new one, the SSH key pair will be mounted as a Kubernetes secret. But what about the SSH config? Will it be re-generated and mounted as well?

yes, it's done here https://github.com/eclipse/che/pull/13809/files#diff-5e2165ab176b2a1fb9829aa579fa546fR139

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@vinokurig vinokurig requested a review from rhopp as a code owner July 17, 2019 09:20
@vinokurig
Copy link
Contributor Author

@sunix

@vinokurig Could you describe the end user flow that would use that ?
How can I test it ? how can I set ssh keys ?

When user executes command: SSH: generate key pair... the plugin generates an SSH key pair and stores it in the che database. The improvement generates a file with a private ssh key and a config file that refers the private key to host. It allows to execute git operation via SSH.
To test it you need to generate a new SSH key, store the public key in the git provider (github.com), then you can clone a repository by ssh url and push to remote.

@sunix
Copy link
Contributor

sunix commented Jul 17, 2019

ok so the ssh key generation work is done on wsmaster ? and we have a dedicated service on wsmaster API. I guess this is comming from che6 but it sounds weird in a Che7 architecture.
is it just for generating keys ? if yes I am not sure it has to stay on wsmaster ... it could just be a microservice that runs on a container or invoking the right command locally... just thinking out loud ...

@vinokurig
Copy link
Contributor Author

@sunix

ok so the ssh key generation work is done on wsmaster ? and we have a dedicated service on wsmaster API. I guess this is comming from che6 but it sounds weird in a Che7 architecture.
is it just for generating keys ? if yes I am not sure it has to stay on wsmaster ... it could just be a microservice that runs on a container or invoking the right command locally... just thinking out loud ...

Agree, but that's a separate issue.

@sunix
Copy link
Contributor

sunix commented Jul 18, 2019

Agree, but that's a separate issue.

Is it an existing GH issue ? could you create one if not ?
Again thinking out loud, but it could just be invoking the right command in the local theia container

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

and we won't have to deal with the legacy problems (like having to deal with the host provider stuff)

@vinokurig
Copy link
Contributor Author

Is it an existing GH issue ? could you create one if not ?

eclipse-che/che#13522

@vinokurig
Copy link
Contributor Author

@l0rd Reworked the plugin according to eclipse-che/che#13494 (comment), could you please review

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
Copy link
Contributor

@l0rd l0rd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but we need a review by someone from IDE2 team as well. @evidolob can you help with it?

plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
plugins/ssh-plugin/src/ssh-plugin-backend.ts Outdated Show resolved Hide resolved
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@vinokurig
Copy link
Contributor Author

@benoitf I've fixed all your comments could you please review

Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found small glitches

};

const updateConfig = async function (hostName: string): Promise<void> {
const sshDir = resolve(os.homedir(), '.ssh');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I was referencing a function for ssh folder, it was for this part
resolve(os.homedir(), '.ssh')

if (sshServiceValue) {
return Promise.resolve(sshServiceValue.label);
const getKeyFilePath = function (name: string): string {
return resolve(os.homedir(), '.ssh', name.replace('.', '_'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably function here should be for resolve(os.homedir(), '.ssh')

also function() can be replaced by getKeyFilePath = (name:string): string => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably function here should be for resolve(os.homedir(), '.ssh')

We need to resolve key file name as well

description: 'SSH keys injected into all Workspace Containers'
}
];
const getHostName = async function (): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(): Promise<string> => { ?

const keyConfig = `\nHost ${hostName.startsWith('default-') ? '*' : hostName}\nIdentityFile ${getKeyFilePath(hostName)}\n`;
const configContentBuffer = await readFile(configFile);
if (configContentBuffer.indexOf(keyConfig) >= 0) {
const newConfigContent = configContentBuffer.toString().replace(keyConfig, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace function is only replacing the first occurence, it's ok ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is not expected that the config file has 2 identical key configs

.then(key => {
theia.workspace.openTextDocument({ content: key.publicKey });
.get('vcs', keyName)
.then(async key => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we use a promise there with then and not with await ?

const key = await sshkeyManager.get(sshServiceName, keyName)
const document = await theia.workspace.openTextDocument({ content: key.publicKey });
theia.window.showTextDocument(document);

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@vinokurig vinokurig merged commit 9d210ad into master Jul 19, 2019
@vinokurig vinokurig deleted the improveSshPlugin branch July 19, 2019 14:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve SSH plugin to be able to execute git commands via ssh
6 participants