Skip to content

Commit 1fa7d00

Browse files
authored
Merge pull request #1238 from smallstep/mariano/console
Add console flag to ssh commands
2 parents 4fc8e4e + 2a6e644 commit 1fa7d00

File tree

10 files changed

+21
-23
lines changed

10 files changed

+21
-23
lines changed

command/ca/ca.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ location being served by an existing fileserver in order to respond to ACME
137137
challenge validation requests.`,
138138
}
139139

140-
consoleFlag = cli.BoolFlag{
141-
Name: "console",
142-
Usage: "Complete the flow while remaining inside the terminal",
143-
}
144-
145140
fingerprintFlag = cli.StringFlag{
146141
Name: "fingerprint",
147142
Usage: "The <fingerprint> of the targeted root certificate.",

command/ca/certificate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ multiple SANs. The '--san' flag and the '--token' flag are mutually exclusive.`,
191191
flags.Force,
192192
flags.Offline,
193193
flags.PasswordFile,
194-
consoleFlag,
194+
flags.Console,
195195
flags.KMSUri,
196196
flags.X5cCert,
197197
flags.X5cKey,

command/ca/sign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ $ step ca sign foo.csr foo.crt \
124124
flags.Force,
125125
flags.Offline,
126126
flags.PasswordFile,
127-
consoleFlag,
127+
flags.Console,
128128
flags.KMSUri,
129129
flags.X5cCert,
130130
flags.X5cKey,

command/oauth/cmd.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package oauth
22

33
import (
4-
"bufio"
54
"bytes"
65
"crypto/sha256"
76
"crypto/x509"
@@ -901,11 +900,9 @@ func (o *oauth) DoDeviceAuthorization() (*token, error) {
901900
idr.Interval = defaultDeviceAuthzInterval
902901
}
903902

904-
fmt.Fprintf(os.Stderr, "Visit %s and enter the code: (press 'ENTER' to open default browser)\n", idr.VerificationURI)
903+
fmt.Fprintf(os.Stderr, "Visit %s and enter the code:\n", idr.VerificationURI)
905904
fmt.Fprintln(os.Stderr, idr.UserCode)
906905

907-
go openBrowserIfAsked(o, idr.VerificationURI)
908-
909906
// Poll the Token endpoint until the user completes the flow.
910907
data = url.Values{}
911908
data.Set("client_id", o.clientID)
@@ -939,13 +936,6 @@ func (o *oauth) DoDeviceAuthorization() (*token, error) {
939936
}
940937
}
941938

942-
func openBrowserIfAsked(o *oauth, u string) {
943-
reader := bufio.NewReader(os.Stdin)
944-
reader.ReadString('\n')
945-
946-
exec.OpenInBrowser(u, o.browser)
947-
}
948-
949939
var errHTTPToken = errors.New("bad request; token not returned")
950940

951941
func (o *oauth) deviceAuthzTokenPoll(data url.Values) (*token, error) {

command/ssh/certificate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func certificateCommand() cli.Command {
3939
[**--password-file**=<file>] [**--provisioner-password-file**=<file>]
4040
[**--add-user**] [**--not-before**=<time|duration>] [**--comment**=<comment>]
4141
[**--not-after**=<time|duration>] [**--token**=<token>] [**--issuer**=<name>]
42-
[**--no-password**] [**--insecure**] [**--force**] [**--x5c-cert**=<file>]
42+
[**--console**] [**--no-password**] [**--insecure**] [**--force**] [**--x5c-cert**=<file>]
4343
[**--x5c-key**=<file>] [**--k8ssa-token-path**=<file>] [**--no-agent**]
4444
[**--kty**=<key-type>] [**--curve**=<curve>] [**--size**=<size>]
4545
[**--ca-url**=<uri>] [**--root**=<file>] [**--context**=<name>]`,
@@ -176,6 +176,7 @@ $ step ssh certificate --kty OKP --curve Ed25519 mariano@work id_ed25519
176176
flags.Token,
177177
flags.TemplateSet,
178178
flags.TemplateSetFile,
179+
flags.Console,
179180
sshAddUserFlag,
180181
sshHostFlag,
181182
sshHostIDFlag,

command/ssh/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func configCommand() cli.Command {
3131
UsageText: `**step ssh config**
3232
[**--team**=<name>] [**--team-authority**=<sub-domain>] [**--host**]
3333
[**--set**=<key=value>] [**--set-file**=<file>] [**--dry-run**] [**--roots**]
34-
[**--federation**] [**--force**] [**--offline**] [**--ca-config**=<file>]
34+
[**--federation**] [**--console**] [**--force**] [**--offline**] [**--ca-config**=<file>]
3535
[**--ca-url**=<uri>] [**--root**=<file>] [**--context**=<name>]
3636
[**--authority**=<name>] [**--profile**=<name>]`,
3737
Description: `**step ssh config** configures SSH to be used with certificates. It also supports
@@ -89,6 +89,7 @@ user or host certificates`,
8989
times to set multiple variables.`,
9090
},
9191
flags.TemplateSetFile,
92+
flags.Console,
9293
flags.DryRun,
9394
flags.Force,
9495
flags.CaConfig,
@@ -204,6 +205,9 @@ func configAction(ctx *cli.Context) (recoverErr error) {
204205
if step.Contexts().Enabled() {
205206
data["Context"] = step.Contexts().GetCurrent().Name
206207
}
208+
if ctx.Bool("console") {
209+
data["Console"] = "true"
210+
}
207211
if len(sets) > 0 {
208212
for _, s := range sets {
209213
i := strings.Index(s, "=")

command/ssh/hosts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func hostsCommand() cli.Command {
1919
Action: command.ActionFunc(hostsAction),
2020
Usage: "returns a list of all valid hosts",
2121
UsageText: `**step ssh hosts** [**--set**=<key=value>] [**--set-file**=<file>]
22-
[**--offline**] [**--ca-config**=<file>] [**--ca-url**=<uri>] [**--root**=<file>]
22+
[**--console**] [**--offline**] [**--ca-config**=<file>] [**--ca-url**=<uri>] [**--root**=<file>]
2323
[**--context**=<name>]`,
2424
Description: `**step ssh hosts** returns a list of valid hosts for SSH.
2525
@@ -35,6 +35,7 @@ $ step ssh hosts
3535
Flags: []cli.Flag{
3636
flags.TemplateSet,
3737
flags.TemplateSetFile,
38+
flags.Console,
3839
flags.Offline,
3940
flags.CaConfig,
4041
flags.CaURL,

command/ssh/login.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func loginCommand() cli.Command {
2929
[**--token**=<token>] [**--provisioner**=<name>] [**--provisioner-password-file**=<file>]
3030
[**--principal**=<string>] [**--not-before**=<time|duration>] [**--not-after**=<time|duration>]
3131
[**--kty**=<key-type>] [**--curve**=<curve>] [**--size**=<size>] [**--comment**=<comment>]
32-
[**--set**=<key=value>] [**--set-file**=<file>] [**--force**] [**--insecure**]
32+
[**--set**=<key=value>] [**--set-file**=<file>] [**--console**] [**--force**] [**--insecure**]
3333
[**--offline**] [**--ca-config**=<file>]
3434
[**--ca-url**=<uri>] [**--root**=<file>] [**--context**=<name>]`,
3535
Description: `**step ssh login** generates a new SSH key pair and send a request to [step
@@ -93,6 +93,7 @@ $ step ssh certificate --kty OKP --curve Ed25519 mariano@work id_ed25519
9393
flags.NotAfter,
9494
flags.TemplateSet,
9595
flags.TemplateSetFile,
96+
flags.Console,
9697
flags.Force,
9798
flags.Offline,
9899
flags.CaConfig,

command/ssh/proxycommand.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func proxycommandCommand() cli.Command {
3333
Usage: "proxy ssh connections according to the host registry",
3434
UsageText: `**step ssh proxycommand** <user> <host> <port>
3535
[**--provisioner**=<name>] [**--set**=<key=value>] [**--set-file**=<file>]
36-
[**--offline**] [**--ca-config**=<file>]
36+
[**--console**] [**--offline**] [**--ca-config**=<file>]
3737
[**--ca-url**=<uri>] [**--root**=<file>] [**--context**=<name>]`,
3838
Description: `**step ssh proxycommand** looks into the host registry
3939
and proxies the ssh connection according to its configuration. This command
@@ -56,6 +56,7 @@ This command will add the user to the ssh-agent if necessary.
5656
flags.ProvisionerPasswordFileWithAlias,
5757
flags.TemplateSet,
5858
flags.TemplateSetFile,
59+
flags.Console,
5960
flags.Offline,
6061
flags.CaConfig,
6162
flags.CaURL,

flags/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ flag exists so it can be configured in $STEPPATH/config/defaults.json.`,
467467
Name: "comment",
468468
Usage: "The comment used when adding the certificate to an agent. Defaults to the subject if not provided.",
469469
}
470+
471+
Console = cli.BoolFlag{
472+
Name: "console",
473+
Usage: `Complete the flow while remaining inside the terminal.`,
474+
}
470475
)
471476

472477
// FingerprintFormatFlag returns a flag for configuring the fingerprint format.

0 commit comments

Comments
 (0)