* feature (auth): required schema changes for auth ldap method (#2669) chore (auth/ldap): move schema changes to next avail migration number * feature (auth/ldap): define AuthMethod and all its value objects (#2703) * feature (auth/ldap): storage protos * feature (auth/ldap): define AuthMethod and all its value objects * feature (auth/ldap): add repo and reading an auth method (#2718) * feature (auth/ldap): add Repository.CreateAuthMethod(...) and Repository.DeleteAuthMethod(...) (#2724) * feature (auth/ldap): add Repository.UpdateAuthMethod(...) (#2739) * feature (auth/ldap): add Account * feature (auth/ldap): add AuthMethod.EnableGroups * fix (auth/ldap): refactor AuthMethod.oplog to enforce proper constraints * feature (auth/ldap): add Account repo functions * refactor (auth/ldap): remove entry attributes from account Realized the entry attributes could have absolutely anything in them (including binary data) and since we absolutely don't have to have them there's just no reason to take on the risk. * feature (auth/ldap): add AuthMethod.UseTokenGroups * feature (auth/ldap): add Authenticate(...) * refactor (auth/ldap): ensure options take a context as the 1st parameter * feature (auth/ldap): add Account attribute maps * chore (auth/ldap): make fmt deltas * feature (auth/ldap): add managed groups (#2760) * tests (auth/ldap): add missing unit test to Repository.DeleteAccount(...) Add bits to test the delete operation when you're not able to generate oplog metadata * feature (auth/ldap): add managed groups fixup! feature (auth/ldap): add managed groups (#2760) * feature (auth/ldap): service proto definition (#2761) * feature (handlers/authmethods): add handlers for ldap auth method operations (#2794) * feature (auth/ldap): add Account attribute maps * chore (auth/ldap): update cap/ldap to latest version * feature (auth/ldap): add ldap api generation definitions * feature (authmethods): add ldap repo NewService(...) * feature (authmethods/ldap): add proper mask_mapping to protobufs * feature (authmethods): add support to get an ldap auth method * refactor (auth/ldap): export TestGenerateCA(...) * feature (authmethods): add support to create an ldap auth method * feature (authmethods): add support to delete an ldap auth method * feature (authmethods): add support to list ldap auth methods * refactor (auth/ldap): make urls optional for NewAuthMethod(...) * refactor (auth/ldap): export ldap.TestInvalidPem * chore: make fmt changes * fix (auth/ldap): properly handle group search config Add constraints and tests to ensure when an ldap AuthMethod.EnableGroups is true, and UseTokenGroups is false; that there's a GroupDn configured for finding a user's associated groups * feature (authmethods): add support to update an ldap auth methods * chore (db/ldap): tmp mv migrations so there's no conflict with ongoing work * feature (verifier): add ldap auth method to verifier bits * fix (controller): prevent panic when controller stops when there's no listener * feature (authmethods): add support to authenticate via ldap auth methods * chore (migrations): fix whitespace in stmt * chore: fmt fixup * tests (auth/ldap): invalid err msg * feature (cli/authmethods): add support for ldap auth-methods CRUD and authenticate (#2810) * feature (authmethods): add CLI support for ldap auth methods CRUD * tests (api/auth): ldap auth method classification tests * feature (authmethods): add CLI support for ldap auth authenticate * feature (auth/ldap): set request timeouts for ldap server connections * feature (handlers/authmethods): handle u_anon listing properly. * feature (account/handers): ldap account and managed group CRUDL APIs (#2852) * feature (auth/ldap) add repository Listing of ManagedGroupMemberAccount * feature (controller/handlers): add ldapRepoFn to accounts service * feature (auth/ldap) register ldap managed group subtype * feature (account/handlers): ldap account CRUDL APIs * feature (controller/handlers): add ldapRepo to managed groups service * feature (account/handlers): ldap managed group CRUDL APIs * docs (domain): add LDAP accounts, auth-methods and managed groups (#2857) * feature (ldap/cli) add ldap accounts and managed groups CRUDL commands (#2856) * fix (handlers/authmethods): fix ldap authorized actions (#2892) * feature (cli/ldap/authenticate): use primary auth method if none is provided (#2890) * fix (auth/ldap): support setting the state attribute * feature (cli/ldap/authenticate): use primary auth method if none is provided * feature (wh/ldap) add tests for new ldap auth method and accounts (#2919) * refactor (migrations/ldap): mv to correct directory * chore: add copyright headers * fix (api/authmethods/ldap): renumber new LdapAuthMethodAttributes field * fix (auth/ldap): allow the auth method state to be updated (#2951) * chore: update sdk and api versions for llb - this is tmp until merging * tests (managed groups): add required errContains for new test
511 lines
16 KiB
Go
511 lines
16 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package authmethodscmd
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
"errors"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/hashicorp/boundary/api/authmethods"
|
|
"github.com/hashicorp/boundary/internal/cmd/base"
|
|
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
|
)
|
|
|
|
func init() {
|
|
extraLdapActionsFlagsMapFunc = extraLdapActionsFlagsMapFuncImpl
|
|
extraLdapFlagsFunc = extraLdapFlagsFuncImpl
|
|
extraLdapFlagsHandlingFunc = extraLdapFlagHandlingFuncImpl
|
|
}
|
|
|
|
type extraLdapCmdVars struct {
|
|
flagState string
|
|
flagUrls []string
|
|
flagInsecureTls bool
|
|
flagDiscoverDn bool
|
|
flagAnonGroupSearch bool
|
|
flagUpnDomain string
|
|
flagStartTls bool
|
|
flagUserDn string
|
|
flagUserAttr string
|
|
flagUserFilter string
|
|
flagEnableGroups bool
|
|
flagGroupDn string
|
|
flagGroupAttr string
|
|
flagGroupFilter string
|
|
flagCertificates []string
|
|
flagClientCertificate string
|
|
flagClientCertificateKey string
|
|
flagBindDn string
|
|
flagBindPassword string
|
|
flagUseTokenGroups bool
|
|
flagAccountAttributeMaps []string
|
|
}
|
|
|
|
const (
|
|
urlsFlagName = "urls"
|
|
insecureTlsFlagName = "insecure-tls"
|
|
discoverDnFlagName = "discover-dn"
|
|
anonGroupSearchFlagName = "anon-group-search"
|
|
upnDomainFlagName = "upn-domain"
|
|
startTlsFlagName = "start-tls"
|
|
userDnFlagName = "user-dn"
|
|
userAttrFlagName = "user-attr"
|
|
userFilterFlagName = "user-filter"
|
|
enableGroupsFlagName = "enable-groups"
|
|
groupDnFlagName = "group-dn"
|
|
groupAttrFlagName = "group-attr"
|
|
groupFilterFlagName = "group-filter"
|
|
certificatesFlagName = "certificate"
|
|
clientCertificateFlagName = "client-certificate"
|
|
clientCertificateKeyFlagName = "client-certificate-key"
|
|
bindDnFlagName = "bind-dn"
|
|
bindPasswordFlagName = "bind-password"
|
|
useTokenGroupsFlagName = "use-token-groups"
|
|
accountAttributeMaps = "account-attribute-map"
|
|
)
|
|
|
|
func extraLdapActionsFlagsMapFuncImpl() map[string][]string {
|
|
flags := map[string][]string{
|
|
"create": {
|
|
urlsFlagName,
|
|
insecureTlsFlagName,
|
|
discoverDnFlagName,
|
|
anonGroupSearchFlagName,
|
|
upnDomainFlagName,
|
|
startTlsFlagName,
|
|
userDnFlagName,
|
|
userAttrFlagName,
|
|
userFilterFlagName,
|
|
enableGroupsFlagName,
|
|
groupDnFlagName,
|
|
groupAttrFlagName,
|
|
groupFilterFlagName,
|
|
certificatesFlagName,
|
|
clientCertificateFlagName,
|
|
clientCertificateKeyFlagName,
|
|
bindDnFlagName,
|
|
bindPasswordFlagName,
|
|
useTokenGroupsFlagName,
|
|
accountAttributeMaps,
|
|
stateFlagName,
|
|
},
|
|
}
|
|
flags["update"] = flags["create"]
|
|
return flags
|
|
}
|
|
|
|
func extraLdapFlagsFuncImpl(c *LdapCommand, set *base.FlagSets, _ *base.FlagSet) {
|
|
f := set.NewFlagSet("LDAP Auth Method Options")
|
|
|
|
for _, name := range flagsLdapMap[c.Func] {
|
|
switch name {
|
|
case urlsFlagName:
|
|
f.StringSliceVar(&base.StringSliceVar{
|
|
Name: urlsFlagName,
|
|
Target: &c.flagUrls,
|
|
Usage: "The LDAP URLs that specify LDAP servers to connect to (required). May be specified multiple times.",
|
|
})
|
|
case startTlsFlagName:
|
|
f.BoolVar(&base.BoolVar{
|
|
Name: startTlsFlagName,
|
|
Target: &c.flagStartTls,
|
|
Usage: "Issue StartTLS command after connecting (optional).",
|
|
})
|
|
case insecureTlsFlagName:
|
|
f.BoolVar(&base.BoolVar{
|
|
Name: insecureTlsFlagName,
|
|
Target: &c.flagInsecureTls,
|
|
Usage: "Skip the LDAP server SSL certificate validation (optional) - insecure and use with caution.",
|
|
})
|
|
case discoverDnFlagName:
|
|
f.BoolVar(&base.BoolVar{
|
|
Name: discoverDnFlagName,
|
|
Target: &c.flagDiscoverDn,
|
|
Usage: "Use anon bind to discover the bind DN of a user (optional).",
|
|
})
|
|
case anonGroupSearchFlagName:
|
|
f.BoolVar(&base.BoolVar{
|
|
Name: anonGroupSearchFlagName,
|
|
Target: &c.flagAnonGroupSearch,
|
|
Usage: "Use anon bind when performing LDAP group searches (optional).",
|
|
})
|
|
case upnDomainFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: upnDomainFlagName,
|
|
Target: &c.flagUpnDomain,
|
|
Usage: "The userPrincipalDomain used to construct the UPN string for the authenticating user (optional).",
|
|
})
|
|
case userDnFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: userDnFlagName,
|
|
Target: &c.flagUserDn,
|
|
Usage: "The base DN under which to perform user search (optional).",
|
|
})
|
|
case userAttrFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: userAttrFlagName,
|
|
Target: &c.flagUserAttr,
|
|
Usage: "The attribute on user entry matching the username passed when authenticating (optional).",
|
|
})
|
|
case userFilterFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: userFilterFlagName,
|
|
Target: &c.flagUserFilter,
|
|
Usage: "A go template used to construct a LDAP user search filter (optional).",
|
|
})
|
|
case enableGroupsFlagName:
|
|
f.BoolVar(&base.BoolVar{
|
|
Name: enableGroupsFlagName,
|
|
Target: &c.flagEnableGroups,
|
|
Usage: "Find the authenticated user's groups during authentication (optional).",
|
|
})
|
|
case groupDnFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: groupDnFlagName,
|
|
Target: &c.flagGroupDn,
|
|
Usage: "The base DN under which to perform group search.",
|
|
})
|
|
case groupAttrFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: groupAttrFlagName,
|
|
Target: &c.flagGroupAttr,
|
|
Usage: "The attribute that enumerates a user's group membership from entries returned by a group search (optional).",
|
|
})
|
|
case groupFilterFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: groupFilterFlagName,
|
|
Target: &c.flagGroupFilter,
|
|
Usage: "A go template used to construct a LDAP group search filter (optional).",
|
|
})
|
|
case certificatesFlagName:
|
|
f.StringSliceVar(&base.StringSliceVar{
|
|
Name: certificatesFlagName,
|
|
Target: &c.flagCertificates,
|
|
Usage: "PEM-encoded X.509 CA certificate in ASN.1 DER form that can be used as a trust anchor when connecting to an LDAP server(optional). This may be specified multiple times",
|
|
})
|
|
case clientCertificateFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: clientCertificateFlagName,
|
|
Target: &c.flagClientCertificate,
|
|
Usage: "PEM-encoded X.509 client certificate in ASN.1 DER form that can be used to authenticate against an LDAP server(optional).",
|
|
})
|
|
case clientCertificateKeyFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: clientCertificateKeyFlagName,
|
|
Target: &c.flagClientCertificateKey,
|
|
Usage: "PEM-encoded X.509 client certificate key in PKCS #8, ASN.1 DER form used with the client certificate (optional).",
|
|
})
|
|
case bindDnFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: bindDnFlagName,
|
|
Target: &c.flagBindDn,
|
|
Usage: "The distinguished name of entry to bind when performing user and group searches (optional).",
|
|
})
|
|
case bindPasswordFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: bindPasswordFlagName,
|
|
Target: &c.flagBindPassword,
|
|
Usage: "The password to use along with bind-dn performing user and group searches (optional).",
|
|
})
|
|
case useTokenGroupsFlagName:
|
|
f.BoolVar(&base.BoolVar{
|
|
Name: useTokenGroupsFlagName,
|
|
Target: &c.flagUseTokenGroups,
|
|
Usage: "Use the Active Directory tokenGroups constructed attribute of the user to find the group memberships (optional).",
|
|
})
|
|
case stateFlagName:
|
|
f.StringVar(&base.StringVar{
|
|
Name: stateFlagName,
|
|
Target: &c.flagState,
|
|
Usage: "The desired operational state of the auth method.",
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func (c *LdapCommand) extraLdapHelpFunc(helpMap map[string]func() string) string {
|
|
var helpStr string
|
|
switch c.Func {
|
|
case "create":
|
|
helpStr = base.WrapForHelpText([]string{
|
|
"Usage: boundary auth-methods create ldap [options] [args]",
|
|
"",
|
|
" Create an ldap-type auth method. Example:",
|
|
"",
|
|
` $ boundary auth-methods create ldap -name prodops -description "LDAP auth-method for ProdOps"`,
|
|
"",
|
|
"",
|
|
})
|
|
|
|
case "update":
|
|
helpStr = base.WrapForHelpText([]string{
|
|
"Usage: boundary auth-methods update ldap [options] [args]",
|
|
"",
|
|
" Update an ldap-type auth method given its ID. Example:",
|
|
"",
|
|
` $ boundary auth-methods update ldap -id amldap_1234567890 -name "devops" -description "LDAP auth-method for DevOps"`,
|
|
"",
|
|
"",
|
|
})
|
|
}
|
|
return helpStr + c.Flags().Help()
|
|
}
|
|
|
|
func extraLdapFlagHandlingFuncImpl(c *LdapCommand, _ *base.FlagSets, opts *[]authmethods.Option) bool {
|
|
switch {
|
|
case len(c.flagUrls) == 0:
|
|
case len(c.flagUrls) == 1 && c.flagUrls[0] == "null":
|
|
c.UI.Error(fmt.Sprintf("There must be at least one %q", urlsFlagName))
|
|
return false
|
|
default:
|
|
for _, urlString := range c.flagUrls {
|
|
u, err := url.Parse(urlString)
|
|
if err != nil {
|
|
c.UI.Error(fmt.Sprintf("Error parsing URL %q: %s", urlString, err))
|
|
return false
|
|
}
|
|
switch u.Scheme {
|
|
case "ldap", "ldaps":
|
|
default:
|
|
c.UI.Error(fmt.Sprintf("scheme in url %q is neither ldap nor ldaps", urlString))
|
|
return false
|
|
}
|
|
}
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUrls(c.flagUrls))
|
|
}
|
|
|
|
switch c.flagStartTls {
|
|
case true:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodStartTls(true))
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodStartTls(false))
|
|
}
|
|
|
|
switch c.flagInsecureTls {
|
|
case true:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodInsecureTls(true))
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodInsecureTls(false))
|
|
}
|
|
|
|
switch c.flagDiscoverDn {
|
|
case true:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodDiscoverDn(true))
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodDiscoverDn(false))
|
|
}
|
|
|
|
switch c.flagAnonGroupSearch {
|
|
case true:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodAnonGroupSearch(true))
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodAnonGroupSearch(false))
|
|
}
|
|
|
|
switch c.flagUpnDomain {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodUpnDomain())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUpnDomain(c.flagUpnDomain))
|
|
}
|
|
|
|
switch c.flagUserDn {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodUserDn())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUserDn(c.flagUserDn))
|
|
}
|
|
|
|
switch c.flagUserAttr {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodUserAttr())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUserAttr(c.flagUserAttr))
|
|
}
|
|
|
|
switch c.flagUserFilter {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodUserFilter())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUserFilter(c.flagUserFilter))
|
|
}
|
|
|
|
switch c.flagEnableGroups {
|
|
case true:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodEnableGroups(true))
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodEnableGroups(false))
|
|
}
|
|
|
|
switch c.flagGroupDn {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodGroupDn())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodGroupDn(c.flagGroupDn))
|
|
}
|
|
|
|
switch c.flagGroupAttr {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodGroupAttr())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodGroupAttr(c.flagGroupAttr))
|
|
}
|
|
|
|
switch c.flagGroupFilter {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodGroupFilter())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodGroupFilter(c.flagGroupFilter))
|
|
}
|
|
|
|
switch {
|
|
case len(c.flagCertificates) == 0:
|
|
case len(c.flagCertificates) == 1 && c.flagCertificates[0] == "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodCertificates())
|
|
default:
|
|
pems := make([]string, 0, len(c.flagCertificates))
|
|
for _, certFlag := range c.flagCertificates {
|
|
p, err := parseutil.MustParsePath(certFlag)
|
|
switch {
|
|
case err == nil:
|
|
if validationErr := validateCerts(p); validationErr != nil {
|
|
c.UI.Error(fmt.Sprintf("invalid certificate in %q: %s", certFlag, validationErr.Error()))
|
|
return false
|
|
}
|
|
pems = append(pems, p)
|
|
case errors.Is(err, parseutil.ErrNotParsed):
|
|
c.UI.Error("Certificate flag must be used with env:// or file:// syntax")
|
|
return false
|
|
default:
|
|
c.UI.Error(fmt.Sprintf("Error parsing certificate flag: %v", err))
|
|
return false
|
|
}
|
|
}
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodCertificates(pems))
|
|
}
|
|
|
|
switch c.flagClientCertificate {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodClientCertificate())
|
|
default:
|
|
p, err := parseutil.MustParsePath(c.flagClientCertificate)
|
|
switch {
|
|
case err == nil:
|
|
if validationErr := validateCerts(p); validationErr != nil {
|
|
c.UI.Error(fmt.Sprintf("invalid client certificate in %q: %s", c.flagClientCertificate, validationErr.Error()))
|
|
return false
|
|
}
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodClientCertificate(p))
|
|
case errors.Is(err, parseutil.ErrNotParsed):
|
|
c.UI.Error("Client certificate flag must be used with env:// or file:// syntax")
|
|
return false
|
|
default:
|
|
c.UI.Error(fmt.Sprintf("Error parsing client certificate flag: %v", err))
|
|
return false
|
|
}
|
|
}
|
|
|
|
switch c.flagClientCertificateKey {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodClientCertificateKey())
|
|
default:
|
|
key, err := parseutil.MustParsePath(c.flagClientCertificateKey)
|
|
switch {
|
|
case err == nil:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodClientCertificateKey(key))
|
|
case errors.Is(err, parseutil.ErrNotParsed):
|
|
c.UI.Error("Client certificate key flag must be used with env:// or file:// syntax")
|
|
return false
|
|
default:
|
|
c.UI.Error(fmt.Sprintf("Error parsing client certificate key flag: %v", err))
|
|
return false
|
|
}
|
|
}
|
|
|
|
switch c.flagBindDn {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodBindDn())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodBindDn(c.flagBindDn))
|
|
}
|
|
|
|
switch c.flagBindPassword {
|
|
case "":
|
|
case "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodBindPassword())
|
|
default:
|
|
password, err := parseutil.MustParsePath(c.flagBindPassword)
|
|
switch {
|
|
case err == nil:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodBindPassword(password))
|
|
case errors.Is(err, parseutil.ErrNotParsed):
|
|
c.UI.Error("Bind password flag must be used with env:// or file:// syntax")
|
|
return false
|
|
default:
|
|
c.UI.Error(fmt.Sprintf("Error parsing bind password flag: %v", err))
|
|
return false
|
|
}
|
|
}
|
|
|
|
switch c.flagUseTokenGroups {
|
|
case true:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUseTokenGroups(true))
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodUseTokenGroups(false))
|
|
}
|
|
|
|
switch {
|
|
case len(c.flagAccountAttributeMaps) == 0:
|
|
case len(c.flagAccountAttributeMaps) == 1 && c.flagAccountAttributeMaps[0] == "null":
|
|
*opts = append(*opts, authmethods.DefaultLdapAuthMethodAccountAttributeMaps())
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodAccountAttributeMaps(c.flagAccountAttributeMaps))
|
|
}
|
|
|
|
switch c.flagState {
|
|
case "":
|
|
// there is a default value during "create", so it's okay to not
|
|
// specify a state
|
|
case "null":
|
|
c.UI.Error("State is required, you cannot set it to null")
|
|
return false
|
|
default:
|
|
*opts = append(*opts, authmethods.WithLdapAuthMethodState(c.flagState))
|
|
}
|
|
return true
|
|
}
|
|
|
|
func validateCerts(pems ...string) error {
|
|
if len(pems) == 0 {
|
|
return errors.New("no PEMs provided")
|
|
}
|
|
for _, p := range pems {
|
|
if p == "" {
|
|
return errors.New("empty certificate PEM")
|
|
}
|
|
block, _ := pem.Decode([]byte(p))
|
|
if block == nil {
|
|
return errors.New("failed to parse certificate: invalid PEM encoding")
|
|
}
|
|
_, err := x509.ParseCertificate(block.Bytes)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to parse certificate: invalid block: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|