add missing issuer, fix various issues

This commit is contained in:
Andrew Martinez
2023-03-28 15:24:10 -04:00
parent 79ff705763
commit 65fa5cb133
4 changed files with 43 additions and 11 deletions
-1
View File
@@ -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{
+10 -5
View File
@@ -58,15 +58,16 @@ func newCreateExtJwtSignerCmd(out io.Writer, errOut io.Writer) *cobra.Command {
}
cmd := &cobra.Command{
Use: "ext-jwt-signer <name> (-u <jwksEndpoint>|-p <cert pem>|-f <cert file>) [-a <audience> -c <claimProperty> -xe]",
Use: "ext-jwt-signer <name> <issuer> (-u <jwksEndpoint>|-p <cert pem>|-f <cert file>) [-a <audience> -c <claimProperty> -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 {
+24 -5
View File
@@ -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
}
+9
View File
@@ -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 {