|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bufio" |
4 | 5 | "bytes" |
5 | 6 | "context" |
6 | 7 | "fmt" |
@@ -408,6 +409,38 @@ func runOutro(c *cli.Context) error { |
408 | 409 | return addons.NewApplier(opts...).Outro(c.Context) |
409 | 410 | } |
410 | 411 |
|
| 412 | +// validateSSHDConfig checks if we can ssh into ourselves as root using ssh |
| 413 | +// keys. XXX this is a workaround while we don't implement a different method |
| 414 | +// of installation that does not require ssh access. |
| 415 | +func validateSSHDConfig() error { |
| 416 | + sshdcfg := "/etc/ssh/sshd_config" |
| 417 | + fp, err := os.Open(sshdcfg) |
| 418 | + if err != nil { |
| 419 | + return fmt.Errorf("unable to read sshd_config (%s): %w", sshdcfg, err) |
| 420 | + } |
| 421 | + defer fp.Close() |
| 422 | + scanner := bufio.NewScanner(fp) |
| 423 | + var invalid bool |
| 424 | + for scanner.Scan() { |
| 425 | + line := scanner.Text() |
| 426 | + if !strings.HasPrefix(line, "PermitRootLogin") { |
| 427 | + continue |
| 428 | + } |
| 429 | + invalid = strings.HasSuffix(line, "no") |
| 430 | + break |
| 431 | + } |
| 432 | + if !invalid { |
| 433 | + return nil |
| 434 | + } |
| 435 | + fmt.Printf("PermitRootLogin config is set to 'no' in %s\n", sshdcfg) |
| 436 | + fmt.Printf("This will prevent %s from installing.\n", defaults.BinaryName()) |
| 437 | + fmt.Printf("You can temporarily enable root login by changing the\n") |
| 438 | + fmt.Printf("PermitRootLogin config to 'without-password' and restarting\n") |
| 439 | + fmt.Printf("the sshd service. Once the installation is finished you can\n") |
| 440 | + fmt.Printf("restore the original configuration.\n") |
| 441 | + return fmt.Errorf("ssh root access is not allowed") |
| 442 | +} |
| 443 | + |
411 | 444 | // installCommands executes the "install" command. This will ensure that a |
412 | 445 | // k0sctl.yaml file exists and then run `k0sctl apply` to apply the cluster. |
413 | 446 | // Once this is finished then a "kubeconfig" file is created. |
@@ -455,6 +488,10 @@ var installCommand = &cli.Command{ |
455 | 488 | metrics.ReportApplyFinished(c, fmt.Errorf("wrong upgrade on decentralized install")) |
456 | 489 | return fmt.Errorf("decentralized install detected") |
457 | 490 | } |
| 491 | + if err := validateSSHDConfig(); err != nil { |
| 492 | + metrics.ReportApplyFinished(c, err) |
| 493 | + return err |
| 494 | + } |
458 | 495 | logrus.Infof("Materializing binaries") |
459 | 496 | if err := goods.Materialize(); err != nil { |
460 | 497 | err := fmt.Errorf("unable to materialize binaries: %w", err) |
|
0 commit comments