Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add known hosts to manual provisioner #16662

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

DanielKenichi
Copy link

@DanielKenichi DanielKenichi commented Dec 2, 2023

Automatically provisioning machines via SSH is interesting for the implementation of models. Juju can accept manual provisioning on its machines. However, manual provisioning of a new machine asks for host confirmation by the user interactively. To make the task of automation easier, it is interesting to provide an option of defining the set of hosts in a specified file.

QA steps

To quickly verify this new option, first build the project with the applied changes. Then, bootstrap a localhost cloud with juju bootstrap localhost test-controller and launch a linux container with lxc launch ubuntu:22.04 . Add a test model with juju add-model foo and try juju add-machine --known-hosts <path-to-known-hosts-file> ssh:ubuntu@<lxd instance ip>.

Verify that the known_hosts file used is not the default located on ~/.ssh, and that the specified file is used instead.

Checklist

  • Code style: imports ordered, good names, simple structure, etc
  • Comments saying why design decisions were made
  • Integration tests, with comments saying what you're testing

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

7 similar comments
@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@jujubot
Copy link
Collaborator

jujubot commented Dec 2, 2023

Thanks for opening a pull request! Please follow the instructions here to ensure your pull request is ready for review. Then, a maintainer will review your patch.

@hpidcock @anvial

@hpidcock hpidcock added the 4.0 label Dec 4, 2023
@tlm
Copy link
Member

tlm commented Dec 13, 2023

Thanks @DanielKenichi for your contribution. Much appreciated and definitely looks like a good addition to Juju.

May I ask if there is a specific version of Juju you would like to see this available in? At the moment this PR is currently targeting our master branch which will end up in Juju 4.0 release that won't happen for a little while yet.

In the meantime I will start having a look at this PR and get you some feedback. Would you also be able to let us know how much more you would be willing to work on this PR if it needs a little bit of extra work to get it across the line?

Cheers

@tlm tlm self-requested a review December 13, 2023 06:50
@DanielKenichi
Copy link
Author

Heyo @tlm!

Thanks for the feedback! We really appreciate it!

There isn't a specific version of juju we would like to see it in, so I think there is no problem if it ends up on Juju 4.0.

About working more on it, as long as there is no problem with me being more active on my freetime on weekends, I am willing to work as much as it needs since I think it is a good and fun experience to work with the codebase.

My friends @migeyel @SaraO3O and @SnakeZ0 also had a part on this so I will be keeping them in touch with the feedbacks as well ok?

Copy link
Member

@tlm tlm left a comment

Choose a reason for hiding this comment

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

Thanks for the work thus far. I have left some comments for your considerations.

I am also thinking some of these ssh functions are becoming long in the tooth for ssh options getting passed to them and wondering if we should introduce an options ssh structure into the mix.

If this is something you don't feel comfortable with designing I am happy to put a commit on this PR with a design.

Cheers
tlm

cmd/juju/machine/add.go Outdated Show resolved Hide resolved
cmd/juju/machine/add.go Outdated Show resolved Hide resolved
environs/manual/provisioner.go Outdated Show resolved Hide resolved
cmd/juju/machine/add.go Outdated Show resolved Hide resolved
environs/manual/sshprovisioner/sshprovisioner.go Outdated Show resolved Hide resolved
environs/manual/sshprovisioner/sshprovisioner.go Outdated Show resolved Hide resolved
environs/manual/sshprovisioner/sshprovisioner.go Outdated Show resolved Hide resolved
environs/manual/sshprovisioner/sshprovisioner.go Outdated Show resolved Hide resolved
@DanielKenichi DanielKenichi force-pushed the add-known-hosts-to-manual-provisioner branch from 47bffd0 to 14684a1 Compare February 7, 2024 14:00
@SimonRichardson
Copy link
Member

/build

@DanielKenichi DanielKenichi force-pushed the add-known-hosts-to-manual-provisioner branch 2 times, most recently from c5cc5b8 to f51e26b Compare March 5, 2024 00:52
@DanielKenichi
Copy link
Author

Hi @tlm!

would you mind having a look at the changes done after your last review?

@hpidcock hpidcock added decaying Pull requests that are decaying and will be eventually closed without merge. and removed has merge conflicts labels Mar 18, 2024
@SimonRichardson
Copy link
Member

/build

@SimonRichardson
Copy link
Member

@DanielKenichi you have test failures:

=== RUN   Test
PASS: environ_network_test.go:19: environNetworkSuite.TestSupportsSpaces	0.000s

----------------------------------------------------------------------
PANIC: environ_test.go:151: environSuite.TestConstraintsValidator

[LOG] 0:00.000 WARNING juju.environs.config unknown config field "ca-cert"
[LOG] 0:00.000 WARNING juju.environs.config unknown config field "ca-private-key"
[LOG] 0:00.000 WARNING juju.environs.config unknown config field "controller-uuid"
[LOG] 0:00.000 WARNING juju.environs.config unknown config field "controller-uuid"
[LOG] 0:00.000 WARNING juju.environs.config unknown config field "ca-cert"
[LOG] 0:00.000 WARNING juju.environs.config unknown config field "ca-private-key"
... Panic: reflect.Set: value of type func(string) (instance.HardwareCharacteristics, string, error) is not assignable to type func(string, string) (instance.HardwareCharacteristics, string, error) (PC=0x43B2FE)

/usr/local/go/src/runtime/panic.go:914
  in gopanic
/usr/local/go/src/reflect/value.go:3307
  in Value.assignTo
/usr/local/go/src/reflect/value.go:2260
  in Value.Set
/home/jenkins/go/pkg/mod/github.com/juju/[email protected]/patch.go:46
  in PatchValue
/home/jenkins/go/pkg/mod/github.com/juju/[email protected]/cleanup.go:125
  in CleanupSuite.PatchValue
environ_test.go:152
  in environSuite.TestConstraintsValidator
/usr/local/go/src/reflect/value.go:380
  in Value.Call
/usr/local/go/src/runtime/asm_amd64.s:1650
  in goexit

----------------------------------------------------------------------
PASS: environ_test.go:169: environSuite.TestConstraintsValidatorInsideController	0.000s
PASS: environ_test.go:83: environSuite.TestDestroyController	0.000s
PASS: environ_test.go:48: environSuite.TestInstances	0.000s
PASS: environ_test.go:182: environSuite.TestPrecheck	0.000s
PASS: environ_test.go:211: controllerInstancesSuite.TestControllerInstances	0.000s
PASS: environ_test.go:259: controllerInstancesSuite.TestControllerInstancesError	0.008s
PASS: environ_test.go:266: controllerInstancesSuite.TestControllerInstancesInternal	0.000s
PASS: environ_test.go:252: controllerInstancesSuite.TestControllerInstancesStderr	0.003s
PASS: credentials_test.go:31: credentialsSuite.TestCredentialSchemas	0.000s
PASS: credentials_test.go:35: credentialsSuite.TestDetectCredentials	0.000s

----------------------------------------------------------------------
PANIC: provider_test.go:31: providerSuite.SetUpTest

... Panic: reflect.Set: value of type func(string, string, string, string, io.Reader, io.Writer) error is not assignable to type func(string, string, string, string, string, io.Reader, io.Writer) error (PC=0x43B2FE)

/usr/local/go/src/runtime/panic.go:914
  in gopanic
/usr/local/go/src/reflect/value.go:3307
  in Value.assignTo
/usr/local/go/src/reflect/value.go:2260
  in Value.Set
/home/jenkins/go/pkg/mod/github.com/juju/[email protected]/patch.go:46
  in PatchValue
/home/jenkins/go/pkg/mod/github.com/juju/[email protected]/cleanup.go:125
  in CleanupSuite.PatchValue
provider_test.go:34
  in providerSuite.SetUpTest
/usr/local/go/src/reflect/value.go:380
  in Value.Call
/usr/local/go/src/runtime/asm_amd64.s:1650
  in goexit

----------------------------------------------------------------------
PANIC: provider_test.go:112: providerSuite.TestDefaultsCanBeOverriden

... Panic: Fixture has panicked (see related PANIC)

----------------------------------------------------------------------
MISS: provider_test.go:93: providerSuite.TestDisablesUpdatesByDefault
MISS: provider_test.go:84: providerSuite.TestNullAlias
MISS: provider_test.go:139: providerSuite.TestPingEndpointWithUser
MISS: provider_test.go:153: providerSuite.TestPingIP
MISS: provider_test.go:40: providerSuite.TestPrepareForBootstrapCloudEndpointAndRegion
MISS: provider_test.go:52: providerSuite.TestPrepareForBootstrapNoCloudEndpoint
MISS: provider_test.go:46: providerSuite.TestPrepareForBootstrapUserHost
MISS: provider_test.go:130: providerSuite.TestSchema
OOPS: 11 passed, 1 PANICKED, 1 FIXTURE-PANICKED, 9 MISSED
--- FAIL: Test (0.02s)
FAIL
coverage: 42.8% of statements
FAIL	github.com/juju/juju/internal/provider/manual	0.072s

DanielKenichi and others added 5 commits May 7, 2024 18:32
This check ensures that the given file and directory has correct
permissions for adding the machine fingerprint to it

ssh creates the file if it does not exists and
in case of the file not being accessible,
it continues silently with the connection
without adding any fingerprint to the file

But I think that what we want here is to fail early
if the knownhosts file is not writeable to inform the user that
the given file will not have the machine fingerprint added
@DanielKenichi DanielKenichi force-pushed the add-known-hosts-to-manual-provisioner branch from f917191 to 756c5af Compare May 7, 2024 21:50
@DanielKenichi
Copy link
Author

@hpidcock sorry for taking some time here, but finally fixed the merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 decaying Pull requests that are decaying and will be eventually closed without merge.
Projects
None yet
5 participants