glauth: Reenable configuring backends

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2020-09-24 11:40:51 +02:00
parent c4b67b6c3f
commit 033feb46a7
7 changed files with 134 additions and 554 deletions
@@ -0,0 +1,5 @@
Enhancement: Reenable configuring backends
We reintroduced the `backend-datastore` config option to choose between the `ldap`, `owncloud` (with graphapi) and `accounts` (the default) datastores.
https://github.com/owncloud/ocis/pull/600
+60 -542
View File
File diff suppressed because it is too large Load Diff
+5
View File
@@ -40,6 +40,8 @@ func Server(cfg *config.Config) *cli.Command {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
} }
cfg.Backend.Servers = c.StringSlice("backend-server")
return ParseConfig(c, cfg) return ParseConfig(c, cfg)
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
@@ -150,11 +152,14 @@ func Server(cfg *config.Config) *cli.Command {
Key: cfg.Ldaps.Key, Key: cfg.Ldaps.Key,
}, },
Backend: glauthcfg.Backend{ Backend: glauthcfg.Backend{
Datastore: cfg.Backend.Datastore,
BaseDN: cfg.Backend.BaseDN, BaseDN: cfg.Backend.BaseDN,
Insecure: cfg.Backend.Insecure, Insecure: cfg.Backend.Insecure,
NameFormat: cfg.Backend.NameFormat, NameFormat: cfg.Backend.NameFormat,
GroupFormat: cfg.Backend.GroupFormat, GroupFormat: cfg.Backend.GroupFormat,
Servers: cfg.Backend.Servers,
SSHKeyAttr: cfg.Backend.SSHKeyAttr, SSHKeyAttr: cfg.Backend.SSHKeyAttr,
UseGraphAPI: cfg.Backend.UseGraphAPI,
}, },
} }
+3
View File
@@ -46,11 +46,14 @@ type Ldaps struct {
// Backend defined the available backend configuration. // Backend defined the available backend configuration.
type Backend struct { type Backend struct {
Datastore string
BaseDN string BaseDN string
Insecure bool Insecure bool
NameFormat string NameFormat string
GroupFormat string GroupFormat string
Servers []string
SSHKeyAttr string SSHKeyAttr string
UseGraphAPI bool
} }
// Config combines all available configuration parts. // Config combines all available configuration parts.
+21 -1
View File
@@ -159,7 +159,14 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"GLAUTH_LDAPS_KEY"}, EnvVars: []string{"GLAUTH_LDAPS_KEY"},
Destination: &cfg.Ldaps.Key, Destination: &cfg.Ldaps.Key,
}, },
&cli.StringFlag{
Name: "backend-datastore",
Value: "accounts",
// TODO bring back config / flat file support
Usage: "datastore to use as the backend. one of accounts, ldap or owncloud",
EnvVars: []string{"GLAUTH_BACKEND_DATASTORE"},
Destination: &cfg.Backend.Datastore,
},
&cli.StringFlag{ &cli.StringFlag{
Name: "backend-basedn", Name: "backend-basedn",
Value: "dc=example,dc=org", Value: "dc=example,dc=org",
@@ -188,6 +195,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"GLAUTH_BACKEND_GROUP_FORMAT"}, EnvVars: []string{"GLAUTH_BACKEND_GROUP_FORMAT"},
Destination: &cfg.Backend.GroupFormat, Destination: &cfg.Backend.GroupFormat,
}, },
&cli.StringSliceFlag{
Name: "backend-server",
Value: cli.NewStringSlice("https://demo.owncloud.com"),
Usage: `--backend-server http://internal1.example.com [--backend-server http://internal2.example.com]`,
EnvVars: []string{"GLAUTH_BACKEND_SERVERS"},
},
&cli.StringFlag{ &cli.StringFlag{
Name: "backend-ssh-key-attr", Name: "backend-ssh-key-attr",
Value: "sshPublicKey", Value: "sshPublicKey",
@@ -195,5 +208,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"GLAUTH_BACKEND_SSH_KEY_ATTR"}, EnvVars: []string{"GLAUTH_BACKEND_SSH_KEY_ATTR"},
Destination: &cfg.Backend.SSHKeyAttr, Destination: &cfg.Backend.SSHKeyAttr,
}, },
&cli.BoolFlag{
Name: "backend-use-graphapi",
Value: true,
Usage: "use Graph API, only for owncloud datastore",
EnvVars: []string{"GLAUTH_BACKEND_USE_GRAPHAPI"},
Destination: &cfg.Backend.UseGraphAPI,
},
} }
} }
+1 -1
View File
@@ -448,7 +448,7 @@ func (h ocisHandler) Close(boundDN string, conn net.Conn) error {
return nil return nil
} }
// NewOCISHandler implements a glauth backend with ocis-accounts as tdhe datasource // NewOCISHandler implements a glauth backend with ocis-accounts as the datasource
func NewOCISHandler(opts ...Option) handler.Handler { func NewOCISHandler(opts ...Option) handler.Handler {
options := newOptions(opts...) options := newOptions(opts...)
+39 -10
View File
@@ -2,9 +2,11 @@ package glauth
import ( import (
"errors" "errors"
"fmt"
"github.com/GeertJohan/yubigo" "github.com/GeertJohan/yubigo"
"github.com/glauth/glauth/pkg/config" "github.com/glauth/glauth/pkg/config"
"github.com/glauth/glauth/pkg/handler"
"github.com/go-logr/logr" "github.com/go-logr/logr"
"github.com/nmcclain/ldap" "github.com/nmcclain/ldap"
"github.com/owncloud/ocis/glauth/pkg/mlogr" "github.com/owncloud/ocis/glauth/pkg/mlogr"
@@ -18,7 +20,8 @@ type LdapSvc struct {
l *ldap.Server l *ldap.Server
} }
// Server initializes the debug service and server. // Server initializes the ldap server.
// It is a fork github.com/glauth/pkg/server because it would introduce a go-micro dependency upstream.
func Server(opts ...Option) (*LdapSvc, error) { func Server(opts ...Option) (*LdapSvc, error) {
options := newOptions(opts...) options := newOptions(opts...)
@@ -40,15 +43,41 @@ func Server(opts ...Option) (*LdapSvc, error) {
// configure the backend // configure the backend
s.l = ldap.NewServer() s.l = ldap.NewServer()
s.l.EnforceLDAP = true s.l.EnforceLDAP = true
h := NewOCISHandler( var h handler.Handler
AccountsService(options.AccountsService), switch s.c.Backend.Datastore {
GroupsService(options.GroupsService), /* TODO bring back file config
Logger(options.Logger), case "config":
Config(s.c), h = handler.NewConfigHandler(
) handler.Logger(s.log),
s.l.BindFunc("", h) handler.Config(s.c),
s.l.SearchFunc("", h) handler.YubiAuth(s.yubiAuth),
s.l.CloseFunc("", h) )
*/
case "ldap":
h = handler.NewLdapHandler(
handler.Logger(s.log),
handler.Config(s.c),
)
case "owncloud":
h = handler.NewOwnCloudHandler(
handler.Logger(s.log),
handler.Config(s.c),
)
case "accounts":
h = NewOCISHandler(
AccountsService(options.AccountsService),
GroupsService(options.GroupsService),
Logger(options.Logger),
Config(s.c),
)
default:
return nil, fmt.Errorf("unsupported backend %s - must be 'ldap', 'owncloud' or 'accounts'", s.c.Backend.Datastore)
//return nil, fmt.Errorf("unsupported backend %s - must be 'config', 'homed', 'ldap', 'owncloud' or 'accounts'", s.c.Backend.Datastore)
}
s.log.V(3).Info("Using backend", "datastore", s.c.Backend.Datastore)
s.l.BindFunc(s.c.Backend.BaseDN, h)
s.l.SearchFunc(s.c.Backend.BaseDN, h)
s.l.CloseFunc(s.c.Backend.BaseDN, h)
return &s, nil return &s, nil
} }