From 8a848bc287c00ef26922f6857f925999746da532 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Wed, 19 Jan 2022 17:32:49 +0100 Subject: [PATCH 1/3] Change authority and profile to default to context name when set Before this change the authority and profile would default to the first DNS name, potentially resulting in multiple CAs using the same directories and configuration or configurations being overwritten. After this change the name of the context will be used as the authority and profile name by default. They can still be overridden using the `--authority` and `--profile` flags. When no context name is provided, we still default to the first DNS name provided. Fixes #606 --- command/ca/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/ca/init.go b/command/ca/init.go index 5bcd6ded..6e98bfab 100644 --- a/command/ca/init.go +++ b/command/ca/init.go @@ -490,11 +490,11 @@ func initAction(ctx *cli.Context) (err error) { } ctxAuthority := ctx.String("authority") if ctxAuthority == "" { - ctxAuthority = dnsNames[0] + ctxAuthority = ctxName } ctxProfile := ctx.String("profile") if ctxProfile == "" { - ctxProfile = dnsNames[0] + ctxProfile = ctxName } if err := step.Contexts().Add(&step.Context{ Name: ctxName, From b1185a6db284323a7cf20fb88e6572f53659521f Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Fri, 4 Feb 2022 17:29:16 +0100 Subject: [PATCH 2/3] Bootstrap into context directory --- utils/cautils/bootstrap.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/utils/cautils/bootstrap.go b/utils/cautils/bootstrap.go index b344221a..2ff300be 100644 --- a/utils/cautils/bootstrap.go +++ b/utils/cautils/bootstrap.go @@ -61,8 +61,8 @@ type bootstrapContext struct { func withDefaultContextValues(context, authority, profile string) bootstrapOption { return func(bc *bootstrapContext) { bc.defaultContextName = context - bc.defaultAuthorityName = authority - bc.defaultProfileName = profile + bc.defaultAuthorityName = authority // effectively ignored in bootstrap now + bc.defaultProfileName = profile // effectively ignored in bootstrap now } } @@ -97,30 +97,30 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt } if UseContext(ctx) { - authority := ctx.String("authority") - if authority == "" { - authority = bc.defaultAuthorityName + ctxName := ctx.String("context") + if ctxName == "" { + ctxName = bc.defaultContextName } - context := ctx.String("context") - if context == "" { - context = bc.defaultContextName + ctxAuthority := ctx.String("authority") + if ctxAuthority == "" { + ctxAuthority = ctxName } - profile := ctx.String("profile") - if profile == "" { - profile = bc.defaultProfileName + ctxProfile := ctx.String("profile") + if ctxProfile == "" { + ctxProfile = ctxName } if err := step.Contexts().Add(&step.Context{ - Name: context, - Profile: profile, - Authority: authority, + Name: ctxName, + Profile: ctxProfile, + Authority: ctxAuthority, }); err != nil { return errors.Wrapf(err, "error adding context: '%s' - {authority: '%s', profile: '%s'}", - context, authority, profile) + ctxName, ctxAuthority, ctxProfile) } - if err := step.Contexts().SaveCurrent(context); err != nil { + if err := step.Contexts().SaveCurrent(ctxName); err != nil { return errors.Wrap(err, "error storing new default context") } - if err := step.Contexts().SetCurrent(context); err != nil { + if err := step.Contexts().SetCurrent(ctxName); err != nil { return errors.Wrap(err, "error setting context '%s'") } } else { From 870b0284ee9fbf8432783d5881683b31fd965f76 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Tue, 15 Feb 2022 22:54:06 +0100 Subject: [PATCH 3/3] Remove unused properties from default context settings --- utils/cautils/bootstrap.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/utils/cautils/bootstrap.go b/utils/cautils/bootstrap.go index 2ff300be..d9dfcfcb 100644 --- a/utils/cautils/bootstrap.go +++ b/utils/cautils/bootstrap.go @@ -52,17 +52,13 @@ func WarnContext() { type bootstrapOption func(bc *bootstrapContext) type bootstrapContext struct { - defaultContextName string - defaultAuthorityName string - defaultProfileName string - redirectURL string + defaultContextName string + redirectURL string } func withDefaultContextValues(context, authority, profile string) bootstrapOption { return func(bc *bootstrapContext) { bc.defaultContextName = context - bc.defaultAuthorityName = authority // effectively ignored in bootstrap now - bc.defaultProfileName = profile // effectively ignored in bootstrap now } }