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 sshuser flag #335

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add sshuser flag
  • Loading branch information
tedteng committed Sep 8, 2023
commit eb87afbbb9d079603e4f0f1c76e41f577eb19ebf
1 change: 1 addition & 0 deletions docs/help/gardenctl_ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ gardenctl ssh --keep-bastion --bastion-name cli-xxxxxxxx --public-key-file /path
--seed string target the given seed cluster
--shoot string target the given shoot cluster
--skip-availability-check Skip checking for SSH bastion host availability.
--ssh-user string ssh user is the name of the Shoot cluster node ssh login user name.
--wait-timeout duration Maximum duration to wait for the bastion to become available. (default 10m0s)
```

Expand Down
18 changes: 15 additions & 3 deletions pkg/cmd/ssh/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ import (
const (
// SSHBastionUsername is the system username on the bastion host.
SSHBastionUsername = "gardener"
// SSHNodeUsername is the system username on any of the shoot cluster nodes.
SSHNodeUsername = "gardener"
// DefaultUsername is the default system username on any of the shoot cluster nodes.
tedteng marked this conversation as resolved.
Show resolved Hide resolved
DefaultUsername = "gardener"
// SSHPort is the TCP port on a bastion instance that allows incoming SSH.
SSHPort = 22
)

// SSHNodeUsername is ssh login user name.
var SSHNodeUsername string

tedteng marked this conversation as resolved.
Show resolved Hide resolved
// wrappers used for unit tests only.
var (
// keepAliveInterval is the interval in which bastions should be given the
Expand Down Expand Up @@ -194,6 +197,9 @@ type SSHOptions struct {
// bastion host, but leave it up to the user to SSH themselves.
NodeName string

// SSHUser is the name of the Shoot cluster node ssh login user name
tedteng marked this conversation as resolved.
Show resolved Hide resolved
SSHUser string
tedteng marked this conversation as resolved.
Show resolved Hide resolved

// SSHPublicKeyFile is the full path to the file containing the user's
// public SSH key. If not given, gardenctl will create a new temporary keypair.
SSHPublicKeyFile PublicKeyFile
Expand Down Expand Up @@ -258,7 +264,7 @@ func (o *SSHOptions) AddFlags(flagSet *pflag.FlagSet) {
flagSet.StringVar(&o.BastionPort, "bastion-port", o.BastionPort, "SSH port of the bastion used for the SSH client command. Defaults to port 22")
flagSet.StringSliceVar(&o.BastionUserKnownHostsFiles, "bastion-user-known-hosts-file", o.BastionUserKnownHostsFiles, "Path to a custom known hosts file for the SSH connection to the bastion. This file is used to verify the public keys of remote hosts when establishing a secure connection.")
flagSet.BoolVarP(&o.ConfirmAccessRestriction, "confirm-access-restriction", "y", o.ConfirmAccessRestriction, "Bypasses the need for confirmation of any access restrictions. Set this flag only if you are fully aware of the access restrictions.")

flagSet.StringVar(&o.SSHUser, "ssh-user", o.SSHUser, "ssh user is the name of the Shoot cluster node ssh login user name.")
tedteng marked this conversation as resolved.
Show resolved Hide resolved
o.Options.AddFlags(flagSet)
}

Expand Down Expand Up @@ -310,6 +316,12 @@ func (o *SSHOptions) Complete(f util.Factory, cmd *cobra.Command, args []string)
o.BastionName = name
}

if o.SSHUser == "" {
SSHNodeUsername = DefaultUsername
} else {
SSHNodeUsername = o.SSHUser
}

tedteng marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand Down