Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

[kvm] Entering into pod #1303

Merged
merged 1 commit into from Oct 1, 2015
Merged

[kvm] Entering into pod #1303

merged 1 commit into from Oct 1, 2015

Conversation

jellonek
Copy link
Contributor

First step on route to implement entering into POD mounted as lkvm VM.

RFC. Especially @krnowak

@jonboulle jonboulle added this to the v0.9.0 milestone Aug 19, 2015
@@ -0,0 +1,12 @@
-----BEGIN RSA PRIVATE KEY-----
Copy link
Member

Choose a reason for hiding this comment

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

Does it mean that anyone (even non-root) who has IP connectivity to the container port 22 will be able to ssh using this well-known "private" key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar idea as in vagrant. sshd can be also enforced (but this would require rewriting config file in time of image preparation) to run only on particular interface/port (for example on primary interface with /31 netmask configured for... host<->vm connection purpose).

@jellonek jellonek force-pushed the entering branch 2 times, most recently from c335041 to a16434f Compare August 24, 2015 11:27
@jellonek
Copy link
Contributor Author

Ok, I've changed behavior. Instead of using hardcoded key pair, I'm generating such one per host machine, once in run or prepare time, and then I'm copying public key into roots authorized_keys for ssh.

So keys are generated once per host, and are copied once per POD.

@jellonek jellonek force-pushed the entering branch 2 times, most recently from 48d1577 to cbe96c5 Compare August 26, 2015 14:01
}

err = ensureKeyExistenceInPod(rootfsPath, dataDir)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

it is enough to just return err or even return ensureKeyExistenceInPod(rootfsPath, dataDir)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. Good catch.

@jellonek jellonek force-pushed the entering branch 2 times, most recently from 46e85d7 to 76a9b9d Compare August 26, 2015 14:42
return nets[0].IP.String(), nil
}

func execToSSH() int {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like "int as error code return here" - we should stick with error created by errors.Errorf() and then in main()

func main() {
    ...
    err := execToSSH()
    if err != nil {
       fmt.Fprintf(os.Stderr, "execToSSH: %v\n", err)
       os.Exit(1)
    }
}

the resposbility how to handle/display error should be left to caller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So probably You should also comment this same form in stage1/init/init.go
I was only replicating principles from other parts of rkt.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your application is completely independent, and there is not need to copy IMHO wrong pattern (also there is no custom to comment existing code within new PR 😏 )

update: I have looked more detailed in init.go, and this pattern was used, because different error codes are returned for every case (in your situation, you return 1 everywhere)

@jellonek jellonek force-pushed the entering branch 2 times, most recently from 15597df to 84b0444 Compare August 28, 2015 11:03
@jellonek jellonek changed the title [WIP] kvm: entering into POD [kvm] Entering into POD Aug 28, 2015
@jellonek jellonek force-pushed the entering branch 2 times, most recently from 3019bb1 to 9792e45 Compare August 28, 2015 11:09
@jellonek
Copy link
Contributor Author

typos in commit message...


func ensureDirExists(path string) error {
err := os.MkdirAll(path, 0700)
if err != nil && os.IsExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

slightly superfluous:

If path is already a directory, MkdirAll does nothing and returns nil.

@jonboulle
Copy link
Contributor

@vcaputo do you have any time to review this one?


STAGE1_INSTALL_DIRS += \
$(ACIROOTFSDIR)/etc:0755 \
$(ACIROOTFSDIR)/root/.ssh:0700 \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nothing depends on that directory, so it will not be created. Anyway, you create it in the code.

@jonboulle jonboulle changed the title [kvm] Entering into POD [kvm] Entering into pod Sep 18, 2015
@jonboulle
Copy link
Contributor

Sorry for the lateness, I've started writing this comment a few times over the past week and it keeps getting eaten by my browser.

In OOB discussions about this, @philips raised a serious concern about permanently running an SSH server in a pod. Aside from technical concerns (attack vector, resource usage, whatever) there is a conceptual/spec issue. Essentially, we're violating the network contract of the pod: instead of giving the application complete control over the networking namespace/interface(s) we provide them, we've now arbitrarily controlled one of their ports.

There were a couple of proposed solutions to mitigate this concern that we thought might be worth exploring:

  • could we spin up an sshd instance on-demand when a user does rkt enter, rather than having it always run? For example, signalling something to the pod via 9P and having it create a oneshot sshd on a random port
  • Eugene had an idea about inverting the connection; basically, rkt client would signal to the kvm pod that it should initiate a connection back to the client (which would effectively then be acting as the server). @eyakubovich I think you had an example of this from MS land, can you remind me?

@jellonek
Copy link
Contributor Author

Yes, there is a method to spin up ssh server only when it's needed - we can achieve this by socket activation. I planned to add this as next step in separate pull request (it also fixes tests prepared by @ppalucki) but if there is desire for this, in time of this weekend I'll code this.

Other thing is port on which ssh is listening (or systemd will wait for connection in inetd style after changing to use socket activation) - if such port will be randomized (some upper ports) - this also potentially increases "security by obscurity", and also gives back 22 port for user usage.

@jellonek jellonek force-pushed the entering branch 3 times, most recently from 8fb2259 to 994a206 Compare September 21, 2015 12:51
@ppalucki
Copy link
Contributor

@jellonek FYI TestEnv (races between run&enter) passes 👍 , even without explicitly defined ordering between application & sshd service.

Please consider moving host keys generation kvmCheckSSHSetup from run to enter command to optimize application startup.

@jellonek
Copy link
Contributor Author

As I mentioned before (or maybe in discussion with @krnowak) I will move this from run into enter (hopefully to stage1 part of entering) but after initial key generation this should have now minimal impact to application speed. Once keys are generated and stored into __datadir__/lkvm - there should be no slowdown of anything. Tests are a separate case, because (as i remember) datadir in time of tests is somewhere in /tmp.

@jellonek
Copy link
Contributor Author

Rebased onto master.

"-N", "", // no passphrase
).Output()
if err != nil {
return fmt.Errorf("error in keygen time. ret_val: %v, output: %v", err, string(out[:len(out)]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't string(out[:len(out)]) same as simply string(out)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Try it ;)
No, it isn't. It would not trim ending multiple \0

@krnowak
Copy link
Collaborator

krnowak commented Sep 30, 2015

Ok, minor nits I haven't noticed before (and this named return value issue that was not addressed yet), but otherwise I'm ready to merge it.

Once this is merged, I'll open an issue about stuff that needs to be addressed WRT. entering on KVM. That would be:

  • Use different data directory (/var/lib/rkt-lkvm-or-something)
  • Run the shell-providing daemon (funny wording to avoid using specific names) on demand by:
    • using socket activation with port randomization, or by
    • running something else, like:
      • something that does not require opening a port in container (which would in turn violates the spec/contract whatever), or
      • something simpler (rsh, telnet, whatever), but
      • it is problematic, because:
        • there is no suitable replacement in CoreOS distro, or
        • it would require to write your own stuff, or
        • it would require to build additional tool from sources (like we do with lkvm) to put it in stage1
  • Move the key generation out from stage0 (into stage1/enter_kvm)

@jellonek jellonek force-pushed the entering branch 2 times, most recently from d7965b1 to c647a4f Compare October 1, 2015 11:26
@@ -0,0 +1,36 @@
Port 22
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be 122?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't matter, we are using inetd mode of ssdh running (-i parameter) for "old style" socket activation.
I'll try to remove this line (should be working ok), but at this moment I don't have time to test this, so this could be done after merge in separate small issue.

@jellonek
Copy link
Contributor Author

jellonek commented Oct 1, 2015

Not ready to merge

krnowak added a commit that referenced this pull request Oct 1, 2015
@krnowak krnowak merged commit 62b27c6 into rkt:master Oct 1, 2015
@jellonek jellonek deleted the entering branch October 1, 2015 14:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants