feat(credentials): Refactor credential purposes (#2260)
* feat(credentials): Refactor credential purposes * Application credentials have been refactored to Brokered credentials * Egress credentials have been refactored to Injected Application credentials Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
This commit is contained in:
1 parent
271cc8f781
commit
a17e973712
49 files changed
+1516
-1051
No files matched your search
@@ -30,12 +30,12 @@ func init() {
|
||||
}
|
||||
|
||||
type extraCmdVars struct {
|
||||
flagHostSets []string
|
||||
flagHostSources []string
|
||||
flagApplicationCredentialSources []string
|
||||
flagEgressCredentialSources []string
|
||||
flagHostId string
|
||||
sar *targets.SessionAuthorizationResult
|
||||
flagHostSets []string
|
||||
flagHostSources []string
|
||||
flagBrokeredCredentialSources []string
|
||||
flagInjectedApplicationCredentialSources []string
|
||||
flagHostId string
|
||||
sar *targets.SessionAuthorizationResult
|
||||
}
|
||||
|
||||
func extraActionsFlagsMapFuncImpl() map[string][]string {
|
||||
@@ -47,9 +47,9 @@ func extraActionsFlagsMapFuncImpl() map[string][]string {
|
||||
"add-host-sources": {"id", "host-source", "version"},
|
||||
"remove-host-sources": {"id", "host-source", "version"},
|
||||
"set-host-sources": {"id", "host-source", "version"},
|
||||
"add-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"remove-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"set-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"add-credential-sources": {"id", "application-credential-source", "brokered-credential-source", "injected-application-credential-source", "version"},
|
||||
"remove-credential-sources": {"id", "application-credential-source", "brokered-credential-source", "injected-application-credential-source", "version"},
|
||||
"set-credential-sources": {"id", "application-credential-source", "brokered-credential-source", "injected-application-credential-source", "version"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
"",
|
||||
" Add credential sources to a tcp-type target:",
|
||||
"",
|
||||
` $ boundary targets add-credential-sources -id ttcp_1234567890 -application-credential-source clvlt_1234567890 -application-credential-source clvlt_0987654321`,
|
||||
` $ boundary targets add-credential-sources -id ttcp_1234567890 -brokered-credential-source clvlt_1234567890 -brokered-credential-source clvlt_0987654321`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
@@ -236,7 +236,7 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
"",
|
||||
" Remove credential sources from a tcp-type target:",
|
||||
"",
|
||||
` $ boundary targets remove-credential-sources -id ttcp_1234567890 -application-credential-source clvlt_1234567890 -application-credential-source clvlt_0987654321`,
|
||||
` $ boundary targets remove-credential-sources -id ttcp_1234567890 -brokered-credential-source clvlt_1234567890 -brokered-credential-source clvlt_0987654321`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
@@ -248,7 +248,7 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
"",
|
||||
" Set credential sources on a tcp-type target:",
|
||||
"",
|
||||
` $ boundary targets set-credential-sources -id ttcp_1234567890 -application-credential-source clvlt_1234567890`,
|
||||
` $ boundary targets set-credential-sources -id ttcp_1234567890 -brokered-credential-source clvlt_1234567890`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
@@ -293,17 +293,23 @@ func extraFlagsFuncImpl(c *Command, _ *base.FlagSets, f *base.FlagSet) {
|
||||
Target: &c.flagHostId,
|
||||
Usage: "The ID of a specific host to connect to out of the hosts from the target's host sets. If not specified, one is chosen at random.",
|
||||
})
|
||||
case "brokered-credential-source":
|
||||
f.StringSliceVar(&base.StringSliceVar{
|
||||
Name: "brokered-credential-source",
|
||||
Target: &c.flagBrokeredCredentialSources,
|
||||
Usage: "The credential source to add, set, or remove that Boundary will return to the user when creating a connection. May be specified multiple times.",
|
||||
})
|
||||
case "application-credential-source":
|
||||
f.StringSliceVar(&base.StringSliceVar{
|
||||
Name: "application-credential-source",
|
||||
Target: &c.flagApplicationCredentialSources,
|
||||
Usage: "The credential source for application purpose to add, set, or remove. May be specified multiple times.",
|
||||
Target: &c.flagBrokeredCredentialSources,
|
||||
Usage: "Deprecated: use -brokered-credential-source instead",
|
||||
})
|
||||
case "egress-credential-source":
|
||||
case "injected-application-credential-source":
|
||||
f.StringSliceVar(&base.StringSliceVar{
|
||||
Name: "egress-credential-source",
|
||||
Target: &c.flagEgressCredentialSources,
|
||||
Usage: "The credential source for egress purpose to add, set, or remove. May be specified multiple times.",
|
||||
Name: "injected-application-credential-source",
|
||||
Target: &c.flagInjectedApplicationCredentialSources,
|
||||
Usage: "The credential source to add, set, or remove that Boundary will inject when creating a connection. May be specified multiple times.",
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -404,49 +410,47 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]targets.Op
|
||||
}
|
||||
|
||||
case "add-credential-sources", "remove-credential-sources":
|
||||
// TODO: As we add other purposes, add them to this check
|
||||
if len(c.flagApplicationCredentialSources)+len(c.flagEgressCredentialSources) == 0 {
|
||||
c.UI.Error("No credential sources supplied via -application-credential-source or -egress-credential-source")
|
||||
if len(c.flagBrokeredCredentialSources)+len(c.flagInjectedApplicationCredentialSources) == 0 {
|
||||
c.UI.Error("No credential sources supplied via -brokered-credential-source or -injected-application-credential-source")
|
||||
return false
|
||||
}
|
||||
|
||||
if len(c.flagApplicationCredentialSources) > 0 {
|
||||
*opts = append(*opts, targets.WithApplicationCredentialSourceIds(c.flagApplicationCredentialSources))
|
||||
if len(c.flagBrokeredCredentialSources) > 0 {
|
||||
*opts = append(*opts, targets.WithBrokeredCredentialSourceIds(c.flagBrokeredCredentialSources))
|
||||
}
|
||||
if len(c.flagEgressCredentialSources) > 0 {
|
||||
*opts = append(*opts, targets.WithEgressCredentialSourceIds(c.flagEgressCredentialSources))
|
||||
if len(c.flagInjectedApplicationCredentialSources) > 0 {
|
||||
*opts = append(*opts, targets.WithInjectedApplicationCredentialSourceIds(c.flagInjectedApplicationCredentialSources))
|
||||
}
|
||||
|
||||
case "set-credential-sources":
|
||||
// TODO: As we add other purposes, add them to this check
|
||||
if len(c.flagApplicationCredentialSources)+len(c.flagEgressCredentialSources) == 0 {
|
||||
c.UI.Error("No credential sources supplied via -application-credential-source or -egress-credential-source")
|
||||
if len(c.flagBrokeredCredentialSources)+len(c.flagInjectedApplicationCredentialSources) == 0 {
|
||||
c.UI.Error("No credential sources supplied via -brokered-credential-source or -injected-application-credential-source")
|
||||
return false
|
||||
}
|
||||
|
||||
switch len(c.flagApplicationCredentialSources) {
|
||||
switch len(c.flagBrokeredCredentialSources) {
|
||||
case 0:
|
||||
// do nothing
|
||||
case 1:
|
||||
if c.flagApplicationCredentialSources[0] == "null" {
|
||||
*opts = append(*opts, targets.DefaultApplicationCredentialSourceIds())
|
||||
if c.flagBrokeredCredentialSources[0] == "null" {
|
||||
*opts = append(*opts, targets.DefaultBrokeredCredentialSourceIds())
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
*opts = append(*opts, targets.WithApplicationCredentialSourceIds(c.flagApplicationCredentialSources))
|
||||
*opts = append(*opts, targets.WithBrokeredCredentialSourceIds(c.flagBrokeredCredentialSources))
|
||||
}
|
||||
switch len(c.flagEgressCredentialSources) {
|
||||
switch len(c.flagInjectedApplicationCredentialSources) {
|
||||
case 0:
|
||||
// do nothing
|
||||
case 1:
|
||||
if c.flagEgressCredentialSources[0] == "null" {
|
||||
*opts = append(*opts, targets.DefaultEgressCredentialSourceIds())
|
||||
if c.flagInjectedApplicationCredentialSources[0] == "null" {
|
||||
*opts = append(*opts, targets.DefaultInjectedApplicationCredentialSourceIds())
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
*opts = append(*opts, targets.WithEgressCredentialSourceIds(c.flagEgressCredentialSources))
|
||||
*opts = append(*opts, targets.WithInjectedApplicationCredentialSourceIds(c.flagInjectedApplicationCredentialSources))
|
||||
}
|
||||
|
||||
case "authorize-session":
|
||||
@@ -610,36 +614,36 @@ func printItemTable(result api.GenericResult) string {
|
||||
}
|
||||
|
||||
var credentialSourceMaps map[credential.Purpose][]map[string]interface{}
|
||||
if len(item.ApplicationCredentialSources) > 0 {
|
||||
if len(item.BrokeredCredentialSources) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
}
|
||||
var applicationCredentialSourceMaps []map[string]interface{}
|
||||
for _, source := range item.ApplicationCredentialSources {
|
||||
var brokeredCredentialSourceMaps []map[string]interface{}
|
||||
for _, source := range item.BrokeredCredentialSources {
|
||||
m := map[string]interface{}{
|
||||
"ID": source.Id,
|
||||
"Credential Store ID": source.CredentialStoreId,
|
||||
}
|
||||
applicationCredentialSourceMaps = append(applicationCredentialSourceMaps, m)
|
||||
brokeredCredentialSourceMaps = append(brokeredCredentialSourceMaps, m)
|
||||
}
|
||||
credentialSourceMaps[credential.ApplicationPurpose] = applicationCredentialSourceMaps
|
||||
credentialSourceMaps[credential.BrokeredPurpose] = brokeredCredentialSourceMaps
|
||||
if l := len("Credential Store ID"); l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
if len(item.EgressCredentialSources) > 0 {
|
||||
if len(item.InjectedApplicationCredentialSources) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
}
|
||||
var egressCredentialSourceMaps []map[string]interface{}
|
||||
for _, source := range item.EgressCredentialSources {
|
||||
var injectedApplicationCredentialSourceMaps []map[string]interface{}
|
||||
for _, source := range item.InjectedApplicationCredentialSources {
|
||||
m := map[string]interface{}{
|
||||
"ID": source.Id,
|
||||
"Credential Store ID": source.CredentialStoreId,
|
||||
}
|
||||
egressCredentialSourceMaps = append(egressCredentialSourceMaps, m)
|
||||
injectedApplicationCredentialSourceMaps = append(injectedApplicationCredentialSourceMaps, m)
|
||||
}
|
||||
credentialSourceMaps[credential.EgressPurpose] = egressCredentialSourceMaps
|
||||
credentialSourceMaps[credential.InjectedApplicationPurpose] = injectedApplicationCredentialSourceMaps
|
||||
if l := len("Credential Store ID"); l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
@@ -685,13 +689,13 @@ func printItemTable(result api.GenericResult) string {
|
||||
|
||||
for purpose, sources := range credentialSourceMaps {
|
||||
switch purpose {
|
||||
case credential.ApplicationPurpose:
|
||||
case credential.BrokeredPurpose:
|
||||
ret = append(ret,
|
||||
" Application Credential Sources:",
|
||||
" Brokered Credential Sources:",
|
||||
)
|
||||
case credential.EgressPurpose:
|
||||
case credential.InjectedApplicationPurpose:
|
||||
ret = append(ret,
|
||||
" Egress Credential Sources:",
|
||||
" Injected Application Credential Sources:",
|
||||
)
|
||||
}
|
||||
for _, m := range sources {
|
||||
@@ -864,8 +868,8 @@ func exampleOutput() string {
|
||||
HostCatalogId: "hcst_1234567890",
|
||||
},
|
||||
},
|
||||
ApplicationCredentialSourceIds: []string{"clvlt_1234567890", "clvlt_0987654321"},
|
||||
ApplicationCredentialSources: []*targets.CredentialSource{
|
||||
BrokeredCredentialSourceIds: []string{"clvlt_1234567890", "clvlt_0987654321"},
|
||||
BrokeredCredentialSources: []*targets.CredentialSource{
|
||||
{
|
||||
Id: "clvlt_1234567890",
|
||||
CredentialStoreId: "csvlt_1234567890",
|
||||
|
||||
Reference in new issue
Block a user