From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BBD00139084 for ; Wed, 6 Dec 2017 13:25:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A3F01E0F72; Wed, 6 Dec 2017 13:25:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6F3D7E0F72 for ; Wed, 6 Dec 2017 13:25:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A9E3133BEBE for ; Wed, 6 Dec 2017 13:25:18 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 42650AE77 for ; Wed, 6 Dec 2017 13:25:17 +0000 (UTC) From: "Michael Palimaka" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michael Palimaka" Message-ID: <1512566705.8f32aaece51aeeb7adaa038196d0c7870c0803f4.kensington@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: sys-auth/docker_auth/files/ X-VCS-Repository: repo/gentoo X-VCS-Files: sys-auth/docker_auth/files/docker_auth-ldap-group-support.patch X-VCS-Directories: sys-auth/docker_auth/files/ X-VCS-Committer: kensington X-VCS-Committer-Name: Michael Palimaka X-VCS-Revision: 8f32aaece51aeeb7adaa038196d0c7870c0803f4 X-VCS-Branch: master Date: Wed, 6 Dec 2017 13:25:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 8925dae6-d630-4320-9487-2b0ba2e12d19 X-Archives-Hash: 10bd82b18aadfdb05de92961c15c4804 commit: 8f32aaece51aeeb7adaa038196d0c7870c0803f4 Author: Michael Mair-Keimberger gmail com> AuthorDate: Sat Dec 2 17:00:47 2017 +0000 Commit: Michael Palimaka gentoo org> CommitDate: Wed Dec 6 13:25:05 2017 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8f32aaec sys-auth/docker_auth: remove unused patch Closes: https://github.com/gentoo/gentoo/pull/6403 .../files/docker_auth-ldap-group-support.patch | 363 --------------------- 1 file changed, 363 deletions(-) diff --git a/sys-auth/docker_auth/files/docker_auth-ldap-group-support.patch b/sys-auth/docker_auth/files/docker_auth-ldap-group-support.patch deleted file mode 100644 index 69858872f49..00000000000 --- a/sys-auth/docker_auth/files/docker_auth-ldap-group-support.patch +++ /dev/null @@ -1,363 +0,0 @@ -From 4a33badac6b74617dfe3797a716a6907cf018b27 Mon Sep 17 00:00:00 2001 -From: Kevin -Date: Mon, 27 Feb 2017 19:09:52 +1300 -Subject: [PATCH 1/3] Initial proof of concept mapping memberOf CN to the label - groups #63 - ---- - auth_server/authn/ldap_auth.go | 73 ++++++++++++++++++++++++++++++++++-------- - 1 file changed, 60 insertions(+), 13 deletions(-) - -diff --git a/auth_server/authn/ldap_auth.go b/auth_server/authn/ldap_auth.go -index f8fc08f..42f5ad0 100644 ---- a/auth_server/authn/ldap_auth.go -+++ b/auth_server/authn/ldap_auth.go -@@ -17,7 +17,6 @@ - package authn - - import ( -- "bytes" - "crypto/tls" - "fmt" - "io/ioutil" -@@ -71,10 +70,20 @@ func (la *LDAPAuth) Authenticate(account string, password PasswordString) (bool, - account = la.escapeAccountInput(account) - - filter := la.getFilter(account) -- accountEntryDN, uSearchErr := la.ldapSearch(l, &la.config.Base, &filter, &[]string{}) -+ -+ // dnAndGroupAttr := []string{"DN"} // example of no groups mapping attribute -+ groupAttribute := "memberOf" -+ dnAndGroupAttr := []string{"DN", groupAttribute} -+ -+ entryAttrMap, uSearchErr := la.ldapSearch(l, &la.config.Base, &filter, &dnAndGroupAttr) - if uSearchErr != nil { - return false, nil, uSearchErr - } -+ if len(entryAttrMap) < 1 || entryAttrMap["DN"] == nil || len(entryAttrMap["DN"]) != 1 { -+ return false, nil, NoMatch // User does not exist -+ } -+ -+ accountEntryDN := entryAttrMap["DN"][0] - if accountEntryDN == "" { - return false, nil, NoMatch // User does not exist - } -@@ -93,6 +102,20 @@ func (la *LDAPAuth) Authenticate(account string, password PasswordString) (bool, - return false, nil, bindErr - } - -+ // Extract group names from the attribute values -+ if entryAttrMap[groupAttribute] != nil { -+ rawGroups := entryAttrMap[groupAttribute] -+ labels := make(map[string][]string) -+ var groups []string -+ for _, value := range rawGroups { -+ cn := la.getCNFromDN(value) -+ groups = append(groups, cn) -+ } -+ labels["groups"] = groups -+ -+ return true, labels, nil -+ } -+ - return true, nil, nil - } - -@@ -170,9 +193,9 @@ func (la *LDAPAuth) getFilter(account string) string { - - //ldap search and return required attributes' value from searched entries - //default return entry's DN value if you leave attrs array empty --func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, attrs *[]string) (string, error) { -+func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, attrs *[]string) (map[string][]string, error) { - if l == nil { -- return "", fmt.Errorf("No ldap connection!") -+ return nil, fmt.Errorf("No ldap connection!") - } - glog.V(2).Infof("Searching...basedDN:%s, filter:%s", *baseDN, *filter) - searchRequest := ldap.NewSearchRequest( -@@ -183,30 +206,54 @@ func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, att - nil) - sr, err := l.Search(searchRequest) - if err != nil { -- return "", err -+ return nil, err - } - - if len(sr.Entries) == 0 { -- return "", nil // User does not exist -+ return nil, nil // User does not exist - } else if len(sr.Entries) > 1 { -- return "", fmt.Errorf("Too many entries returned.") -+ return nil, fmt.Errorf("Too many entries returned.") - } - -- var buffer bytes.Buffer -+ result := make(map[string][]string) - for _, entry := range sr.Entries { -+ - if len(*attrs) == 0 { - glog.V(2).Infof("Entry DN = %s", entry.DN) -- buffer.WriteString(entry.DN) -+ result["DN"] = []string{entry.DN} - } else { - for _, attr := range *attrs { -- values := strings.Join(entry.GetAttributeValues(attr), " ") -- glog.V(2).Infof("Entry %s = %s", attr, values) -- buffer.WriteString(values) -+ var values []string -+ if attr == "DN" { -+ // DN is excluded from attributes -+ values = []string{entry.DN} -+ } else { -+ values = entry.GetAttributeValues(attr) -+ } -+ valuesString := strings.Join(values, "\n") -+ glog.V(2).Infof("Entry %s = %s", attr, valuesString) -+ result[attr] = values -+ } -+ } -+ } -+ -+ return result, nil -+} -+ -+func (la *LDAPAuth) getCNFromDN(dn string) string { -+ parsedDN, err := ldap.ParseDN(dn) -+ if err != nil || len(parsedDN.RDNs) > 0 { -+ for _, rdn := range parsedDN.RDNs { -+ for _, rdnAttr := range rdn.Attributes { -+ if rdnAttr.Type == "CN" { -+ return rdnAttr.Value -+ } - } - } - } - -- return buffer.String(), nil -+ // else try using raw DN -+ return dn - } - - func (la *LDAPAuth) Stop() { - -From ddde2fa779e746d7e74cd972a4c6795c72f17ee6 Mon Sep 17 00:00:00 2001 -From: Kevin -Date: Tue, 28 Feb 2017 18:09:55 +1300 -Subject: [PATCH 2/3] Apply attribute mapping from configuration - ---- - auth_server/authn/ldap_auth.go | 125 ++++++++++++++++++++++++----------------- - 1 file changed, 74 insertions(+), 51 deletions(-) - -diff --git a/auth_server/authn/ldap_auth.go b/auth_server/authn/ldap_auth.go -index 42f5ad0..6f733a2 100644 ---- a/auth_server/authn/ldap_auth.go -+++ b/auth_server/authn/ldap_auth.go -@@ -26,16 +26,22 @@ import ( - "github.com/golang/glog" - ) - -+type LabelMap struct { -+ Attribute string `yaml:"attribute,omitempty"` -+ ParseCN bool `yaml:"parse_cn,omitempty"` -+} -+ - type LDAPAuthConfig struct { -- Addr string `yaml:"addr,omitempty"` -- TLS string `yaml:"tls,omitempty"` -- InsecureTLSSkipVerify bool `yaml:"insecure_tls_skip_verify,omitempty"` -- Base string `yaml:"base,omitempty"` -- Filter string `yaml:"filter,omitempty"` -- BindDN string `yaml:"bind_dn,omitempty"` -- BindPasswordFile string `yaml:"bind_password_file,omitempty"` -- GroupBaseDN string `yaml:"group_base_dn,omitempty"` -- GroupFilter string `yaml:"group_filter,omitempty"` -+ Addr string `yaml:"addr,omitempty"` -+ TLS string `yaml:"tls,omitempty"` -+ InsecureTLSSkipVerify bool `yaml:"insecure_tls_skip_verify,omitempty"` -+ Base string `yaml:"base,omitempty"` -+ Filter string `yaml:"filter,omitempty"` -+ BindDN string `yaml:"bind_dn,omitempty"` -+ BindPasswordFile string `yaml:"bind_password_file,omitempty"` -+ LabelMaps map[string]LabelMap `yaml:"labels,omitempty"` -+ GroupBaseDN string `yaml:"group_base_dn,omitempty"` -+ GroupFilter string `yaml:"group_filter,omitempty"` - } - - type LDAPAuth struct { -@@ -71,22 +77,19 @@ func (la *LDAPAuth) Authenticate(account string, password PasswordString) (bool, - - filter := la.getFilter(account) - -- // dnAndGroupAttr := []string{"DN"} // example of no groups mapping attribute -- groupAttribute := "memberOf" -- dnAndGroupAttr := []string{"DN", groupAttribute} -+ labelAttributes, labelsConfigErr := la.getLabelAttributes() -+ if labelsConfigErr != nil { -+ return false, nil, labelsConfigErr -+ } - -- entryAttrMap, uSearchErr := la.ldapSearch(l, &la.config.Base, &filter, &dnAndGroupAttr) -+ accountEntryDN, entryAttrMap, uSearchErr := la.ldapSearch(l, &la.config.Base, &filter, &labelAttributes) - if uSearchErr != nil { - return false, nil, uSearchErr - } -- if len(entryAttrMap) < 1 || entryAttrMap["DN"] == nil || len(entryAttrMap["DN"]) != 1 { -- return false, nil, NoMatch // User does not exist -- } -- -- accountEntryDN := entryAttrMap["DN"][0] - if accountEntryDN == "" { - return false, nil, NoMatch // User does not exist - } -+ - // Bind as the user to verify their password - if len(accountEntryDN) > 0 { - err := l.Bind(accountEntryDN, string(password)) -@@ -102,21 +105,13 @@ func (la *LDAPAuth) Authenticate(account string, password PasswordString) (bool, - return false, nil, bindErr - } - -- // Extract group names from the attribute values -- if entryAttrMap[groupAttribute] != nil { -- rawGroups := entryAttrMap[groupAttribute] -- labels := make(map[string][]string) -- var groups []string -- for _, value := range rawGroups { -- cn := la.getCNFromDN(value) -- groups = append(groups, cn) -- } -- labels["groups"] = groups -- -- return true, labels, nil -+ // Extract labels from the attribute values -+ labels, labelsExtractErr := la.getLabelsFromMap(entryAttrMap) -+ if labelsExtractErr != nil { -+ return false, nil, labelsExtractErr - } - -- return true, nil, nil -+ return true, labels, nil - } - - func (la *LDAPAuth) bindReadOnlyUser(l *ldap.Conn) error { -@@ -193,9 +188,9 @@ func (la *LDAPAuth) getFilter(account string) string { - - //ldap search and return required attributes' value from searched entries - //default return entry's DN value if you leave attrs array empty --func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, attrs *[]string) (map[string][]string, error) { -+func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, attrs *[]string) (string, map[string][]string, error) { - if l == nil { -- return nil, fmt.Errorf("No ldap connection!") -+ return "", nil, fmt.Errorf("No ldap connection!") - } - glog.V(2).Infof("Searching...basedDN:%s, filter:%s", *baseDN, *filter) - searchRequest := ldap.NewSearchRequest( -@@ -206,38 +201,66 @@ func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, att - nil) - sr, err := l.Search(searchRequest) - if err != nil { -- return nil, err -+ return "", nil, err - } - - if len(sr.Entries) == 0 { -- return nil, nil // User does not exist -+ return "", nil, nil // User does not exist - } else if len(sr.Entries) > 1 { -- return nil, fmt.Errorf("Too many entries returned.") -+ return "", nil, fmt.Errorf("Too many entries returned.") - } - -- result := make(map[string][]string) -+ attributes := make(map[string][]string) -+ var entryDn string - for _, entry := range sr.Entries { -- -+ entryDn = entry.DN - if len(*attrs) == 0 { -- glog.V(2).Infof("Entry DN = %s", entry.DN) -- result["DN"] = []string{entry.DN} -+ glog.V(2).Infof("Entry DN = %s", entryDn) - } else { - for _, attr := range *attrs { -- var values []string -- if attr == "DN" { -- // DN is excluded from attributes -- values = []string{entry.DN} -- } else { -- values = entry.GetAttributeValues(attr) -- } -- valuesString := strings.Join(values, "\n") -- glog.V(2).Infof("Entry %s = %s", attr, valuesString) -- result[attr] = values -+ values := entry.GetAttributeValues(attr) -+ glog.V(2).Infof("Entry %s = %s", attr, strings.Join(values, "\n")) -+ attributes[attr] = values - } - } - } - -- return result, nil -+ return entryDn, attributes, nil -+} -+ -+func (la *LDAPAuth) getLabelAttributes() ([]string, error) { -+ labelAttributes := make([]string, len(la.config.LabelMaps)) -+ i := 0 -+ for key, mapping := range la.config.LabelMaps { -+ if mapping.Attribute == "" { -+ return nil, fmt.Errorf("Label %s is missing 'attribute' to map from", key) -+ } -+ labelAttributes[i] = mapping.Attribute -+ i++ -+ } -+ return labelAttributes, nil -+} -+ -+func (la *LDAPAuth) getLabelsFromMap(attrMap map[string][]string) (map[string][]string, error) { -+ labels := make(map[string][]string) -+ for key, mapping := range la.config.LabelMaps { -+ if mapping.Attribute == "" { -+ return nil, fmt.Errorf("Label %s is missing 'attribute' to map from", key) -+ } -+ -+ mappingValues := attrMap[mapping.Attribute] -+ if mappingValues != nil { -+ if mapping.ParseCN { -+ // shorten attribute to its common name -+ for i, value := range mappingValues { -+ cn := la.getCNFromDN(value) -+ mappingValues[i] = cn -+ } -+ } -+ labels[key] = mappingValues -+ } -+ } -+ return labels, nil - } - - func (la *LDAPAuth) getCNFromDN(dn string) string { - -From cd37001980267a99a9faa19f1927891af63acb90 Mon Sep 17 00:00:00 2001 -From: Kevin -Date: Tue, 28 Feb 2017 18:27:16 +1300 -Subject: [PATCH 3/3] Remove unused configuration fields, never implemented? - ---- - auth_server/authn/ldap_auth.go | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/auth_server/authn/ldap_auth.go b/auth_server/authn/ldap_auth.go -index 6f733a2..9c8bcb8 100644 ---- a/auth_server/authn/ldap_auth.go -+++ b/auth_server/authn/ldap_auth.go -@@ -40,8 +40,6 @@ type LDAPAuthConfig struct { - BindDN string `yaml:"bind_dn,omitempty"` - BindPasswordFile string `yaml:"bind_password_file,omitempty"` - LabelMaps map[string]LabelMap `yaml:"labels,omitempty"` -- GroupBaseDN string `yaml:"group_base_dn,omitempty"` -- GroupFilter string `yaml:"group_filter,omitempty"` - } - - type LDAPAuth struct {