Skip to content

Commit de8695f

Browse files
authored
engflow_auth: add --insecure flag to "login" (#72)
If set, then disable server TLS validation. Can be used for testing.
1 parent 0bc0cc4 commit de8695f

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

cmd/engflow_auth/main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ package main
1616

1717
import (
1818
"context"
19+
"crypto/tls"
1920
"encoding/json"
2021
"errors"
2122
"fmt"
2223
"io"
2324
"io/fs"
2425
"net"
26+
"net/http"
2527
"net/url"
2628
"os"
2729
"os/signal"
@@ -224,6 +226,18 @@ func (r *appState) import_(cliCtx *cli.Context) error {
224226
func (r *appState) login(cliCtx *cli.Context) error {
225227
ctx := cliCtx.Context
226228

229+
if cliCtx.Bool("insecure") {
230+
fmt.Fprintf(cliCtx.App.ErrWriter, "Warning: server TLS validation is disabled\n")
231+
httpClient := &http.Client{
232+
Transport: &http.Transport{
233+
TLSClientConfig: &tls.Config{
234+
InsecureSkipVerify: true,
235+
},
236+
},
237+
}
238+
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
239+
}
240+
227241
if cliCtx.NArg() != 1 {
228242
return autherr.CodedErrorf(autherr.CodeBadParams, "expected exactly 1 positional argument, a cluster name")
229243
}
@@ -349,6 +363,10 @@ func makeApp(root *appState) *cli.App {
349363
Name: "alias",
350364
Usage: "Comma-separated list of alias hostnames for this cluster",
351365
}
366+
insecureFlag := &cli.BoolFlag{
367+
Name: "insecure",
368+
Usage: "Disable server TLS validation",
369+
}
352370

353371
app := &cli.App{
354372
Name: "engflow_auth",
@@ -386,7 +404,7 @@ credential helper protocol.`),
386404
Initiates an interactive OAuth2 flow to log into the cluster at
387405
CLUSTER_URL.`),
388406
Action: root.login,
389-
Flags: []cli.Flag{aliasFlag, storeFlag},
407+
Flags: []cli.Flag{aliasFlag, storeFlag, insecureFlag},
390408
},
391409
{
392410
Name: "logout",

0 commit comments

Comments
 (0)