From 65fa5cb133d4c0ffef1e904a73d574b45462f31b Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Tue, 28 Mar 2023 15:24:10 -0400 Subject: [PATCH] add missing issuer, fix various issues --- ziti/cmd/edge/create.go | 1 - ziti/cmd/edge/create_extjwtsigner.go | 15 +++++++++----- ziti/cmd/edge/list.go | 29 +++++++++++++++++++++++----- ziti/cmd/edge/update_extjwtsigner.go | 9 +++++++++ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/ziti/cmd/edge/create.go b/ziti/cmd/edge/create.go index b86ab5848..b40513d6a 100644 --- a/ziti/cmd/edge/create.go +++ b/ziti/cmd/edge/create.go @@ -30,7 +30,6 @@ func Ptr[T any](sub T) *T { return &sub } -// newCreateCmd creates a command object for the "list" command // newCreateCmd creates a command object for the "create" command func newCreateCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd := &cobra.Command{ diff --git a/ziti/cmd/edge/create_extjwtsigner.go b/ziti/cmd/edge/create_extjwtsigner.go index feedc3dc6..75dcdd463 100644 --- a/ziti/cmd/edge/create_extjwtsigner.go +++ b/ziti/cmd/edge/create_extjwtsigner.go @@ -58,15 +58,16 @@ func newCreateExtJwtSignerCmd(out io.Writer, errOut io.Writer) *cobra.Command { } cmd := &cobra.Command{ - Use: "ext-jwt-signer (-u |-p |-f ) [-a -c -xe]", + Use: "ext-jwt-signer (-u |-p |-f ) [-a -c -xe]", Short: "creates an external JWT signer managed by the Ziti Edge Controller", Long: "creates an external JWT signer managed by the Ziti Edge Controller", Args: func(cmd *cobra.Command, args []string) error { - if len(args) != 1 { - return fmt.Errorf("requires 1 arg, received %d", len(args)) + if len(args) != 2 { + return fmt.Errorf("requires 2 arg, received %d", len(args)) } options.ExtJwtSigner.Name = &args[0] + options.ExtJwtSigner.Issuer = &args[1] return nil @@ -108,11 +109,11 @@ func runCreateExtJwtSigner(options *createExtJwtSignerOptions) (err error) { hasCertPem := options.ExtJwtSigner.CertPem != nil || *options.ExtJwtSigner.CertPem == "" hasCertPath := options.CertFilePath != "" - if (hasJwks && (hasCertPem || hasCertPath)) || (hasCertPem && (hasJwks || hasCertPath)) || (hasCertPath && (hasJwks || hasCertPem)) { + if (hasJwks && !hasCertPem && !hasCertPath) || (hasCertPem && !hasJwks && !hasCertPath) || (hasCertPath && !hasJwks && !hasCertPem) { return errors.New("must specify only one certificate source (JWKS, cert file, or inline cert PEM") } - if hasCertPem || hasCertPath && (options.ExtJwtSigner.Kid == nil || *options.ExtJwtSigner.Kid == "") { + if (hasCertPem || hasCertPath) && (options.ExtJwtSigner.Kid == nil || *options.ExtJwtSigner.Kid == "") { return errors.New("must specify a KID if using a certificate file or inline PEM") } @@ -127,6 +128,10 @@ func runCreateExtJwtSigner(options *createExtJwtSignerOptions) (err error) { if options.JwksEndpoint != "" { jwks := strfmt.URI(options.JwksEndpoint) options.ExtJwtSigner.JwksEndpoint = &jwks + options.ExtJwtSigner.CertPem = nil + options.ExtJwtSigner.Kid = nil + } else { + options.ExtJwtSigner.JwksEndpoint = nil } if hasCertPath { diff --git a/ziti/cmd/edge/list.go b/ziti/cmd/edge/list.go index 2909fd85b..e067e2608 100644 --- a/ziti/cmd/edge/list.go +++ b/ziti/cmd/edge/list.go @@ -514,10 +514,16 @@ func runListExtJwtSigners(options *api.Options) error { outTable := table.NewWriter() outTable.SetStyle(table.StyleRounded) + outTable.Style().Options.SeparateRows = true rowConfigAutoMerge := table.RowConfig{AutoMerge: true, AutoMergeAlign: text.AlignLeft} - outTable.AppendHeader(table.Row{"ID", "Name", "Enabled", "Audience", "Type", "ClaimsProp", "UseExternalId", "Config", "Config"}, rowConfigAutoMerge) + outTable.SetColumnConfigs([]table.ColumnConfig{ + {Number: 1, AutoMerge: true, Align: text.AlignLeft}, + {Number: 2, AutoMerge: true, Align: text.AlignLeft}, + }) + + outTable.AppendHeader(table.Row{"ID", "Name", "Config", "Config"}, rowConfigAutoMerge) for _, entity := range result.GetPayload().Data { id := *entity.ID @@ -526,13 +532,28 @@ func runListExtJwtSigners(options *api.Options) error { isEnabled := *entity.Enabled claimsProperty := *entity.ClaimsProperty useExternalId := *entity.UseExternalID + issuer := *entity.Issuer if entity.JwksEndpoint != nil { confType := "JWKS" - outTable.AppendRow(table.Row{id, name, isEnabled, audience, confType, claimsProperty, useExternalId, "JWKS", entity.JwksEndpoint.String()}) + urlStr := entity.JwksEndpoint.String() + outTable.AppendRow(table.Row{id, name, "Audience", audience}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Claim Property", claimsProperty}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Enabled", isEnabled}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Issuer", issuer}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "JWKS URL", urlStr}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Type", confType}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Use External Id", useExternalId}, rowConfigAutoMerge) } else { confType := "CERT" - outTable.AppendRow(table.Row{id, name, isEnabled, audience, confType, claimsProperty, useExternalId, "Fingerprint", *entity.Fingerprint}) + fingerprint := *entity.Fingerprint + outTable.AppendRow(table.Row{id, name, "Audience", audience}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Claim Property", claimsProperty}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Enabled", isEnabled}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Issuer", issuer}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Fingerprint", fingerprint}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Type", confType}, rowConfigAutoMerge) + outTable.AppendRow(table.Row{id, name, "Use External Id", useExternalId}, rowConfigAutoMerge) } } @@ -540,8 +561,6 @@ func runListExtJwtSigners(options *api.Options) error { pagingInfo := newPagingInfo(payload.Meta) api.RenderTable(options, outTable, pagingInfo) - _, _ = fmt.Fprint(options.Out, "\nFlags: (V) Verified, (A) AutoCa Enrollment, (O) OttCA Enrollment, (E) Authentication Enabled\n\n") - return nil } diff --git a/ziti/cmd/edge/update_extjwtsigner.go b/ziti/cmd/edge/update_extjwtsigner.go index 529617279..7a9f532cc 100644 --- a/ziti/cmd/edge/update_extjwtsigner.go +++ b/ziti/cmd/edge/update_extjwtsigner.go @@ -73,6 +73,8 @@ func newUpdateExtJwtSignerCmd(out io.Writer, errOut io.Writer) *cobra.Command { return fmt.Errorf("too many positional arguments") } + options.nameOrId = args[0] + return nil }, Run: func(cmd *cobra.Command, args []string) { @@ -99,6 +101,7 @@ func newUpdateExtJwtSignerCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().StringVarP(options.ExtJwtSigner.CertPem, "cert-file", "f", "", "A public certificate PEM file, not usable with -u, -p") cmd.Flags().StringVarP(options.ExtJwtSigner.ExternalAuthURL, "external-auth-url", "y", "", "The URL that users are directed to obtain a JWT") cmd.Flags().StringVarP(options.ExtJwtSigner.Kid, "kid", "k", "", "The KID for the signer, required if using -p or -f") + cmd.Flags().StringVarP(options.ExtJwtSigner.Issuer, "issuer", "l", "", "The issuer for the signer") return cmd } @@ -124,6 +127,12 @@ func runUpdateExtJwtSigner(options updateExtJwtOptions) error { options.ExtJwtSigner.Name = nil } + if options.Cmd.Flag("issuer").Changed { + changed = true + } else { + options.ExtJwtSigner.Issuer = nil + } + if options.Cmd.Flag("use-external-id").Changed { changed = true } else {