Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5393ee

Browse files
Make authorization plugins use pluginv2.
Signed-off-by: Anusha Ragunathan <[email protected]>
1 parent 1845f50 commit c5393ee

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

cmd/dockerd/daemon.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
275275
"graphdriver": d.GraphDriverName(),
276276
}).Info("Docker daemon")
277277

278+
cli.d = d
279+
280+
// initMiddlewares needs cli.d to be populated. Dont change this init order.
278281
cli.initMiddlewares(api, serverConfig)
279282
initRouter(api, d, c)
280283

281-
cli.d = d
282284
cli.setupConfigReloadTrap()
283285

284286
// The serve API routine never exits unless an error occurs
@@ -438,6 +440,6 @@ func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config
438440
u := middleware.NewUserAgentMiddleware(v)
439441
s.UseMiddleware(u)
440442

441-
cli.authzMiddleware = authorization.NewMiddleware(cli.Config.AuthorizationPlugins)
443+
cli.authzMiddleware = authorization.NewMiddleware(cli.Config.AuthorizationPlugins, cli.d.PluginStore)
442444
s.UseMiddleware(cli.authzMiddleware)
443445
}

daemon/daemon.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type Daemon struct {
9696
gidMaps []idtools.IDMap
9797
layerStore layer.Store
9898
imageStore image.Store
99-
pluginStore *pluginstore.Store
99+
PluginStore *pluginstore.Store
100100
nameIndex *registrar.Registrar
101101
linkIndex *linkIndex
102102
containerd libcontainerd.Client
@@ -559,7 +559,7 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
559559
driverName = config.GraphDriver
560560
}
561561

562-
d.pluginStore = pluginstore.NewStore(config.Root)
562+
d.PluginStore = pluginstore.NewStore(config.Root)
563563

564564
d.layerStore, err = layer.NewStoreFromOptions(layer.StoreOptions{
565565
StorePath: config.Root,
@@ -568,7 +568,7 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
568568
GraphDriverOptions: config.GraphOptions,
569569
UIDMaps: uidMaps,
570570
GIDMaps: gidMaps,
571-
PluginGetter: d.pluginStore,
571+
PluginGetter: d.PluginStore,
572572
})
573573
if err != nil {
574574
return nil, err
@@ -926,7 +926,7 @@ func (daemon *Daemon) configureVolumes(rootUID, rootGID int) (*store.VolumeStore
926926
return nil, err
927927
}
928928

929-
volumedrivers.RegisterPluginGetter(daemon.pluginStore)
929+
volumedrivers.RegisterPluginGetter(daemon.PluginStore)
930930

931931
if !volumedrivers.Register(volumesDriver, volumesDriver.Name()) {
932932
return nil, fmt.Errorf("local volume driver could not be registered")
@@ -1102,7 +1102,7 @@ func (daemon *Daemon) reloadClusterDiscovery(config *Config) error {
11021102
if daemon.netController == nil {
11031103
return nil
11041104
}
1105-
netOptions, err := daemon.networkOptions(daemon.configStore, daemon.pluginStore, nil)
1105+
netOptions, err := daemon.networkOptions(daemon.configStore, daemon.PluginStore, nil)
11061106
if err != nil {
11071107
logrus.WithError(err).Warnf("failed to get options with network controller")
11081108
return nil

daemon/daemon_experimental.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (daemon *Daemon) verifyExperimentalContainerSettings(hostConfig *container.
1313
}
1414

1515
func pluginInit(d *Daemon, cfg *Config, remote libcontainerd.Remote) error {
16-
return plugin.Init(cfg.Root, d.pluginStore, remote, d.RegistryService, cfg.LiveRestoreEnabled, d.LogPluginEvent)
16+
return plugin.Init(cfg.Root, d.PluginStore, remote, d.RegistryService, cfg.LiveRestoreEnabled, d.LogPluginEvent)
1717
}
1818

1919
func pluginShutdown() {

daemon/daemon_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ func configureKernelSecuritySupport(config *Config, driverName string) error {
613613
}
614614

615615
func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
616-
netOptions, err := daemon.networkOptions(config, daemon.pluginStore, activeSandboxes)
616+
netOptions, err := daemon.networkOptions(config, daemon.PluginStore, activeSandboxes)
617617
if err != nil {
618618
return nil, err
619619
}

pkg/authorization/middleware.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net/http"
55

66
"github.com/Sirupsen/logrus"
7+
"github.com/docker/docker/pkg/plugingetter"
78
"golang.org/x/net/context"
89
)
910

@@ -15,7 +16,8 @@ type Middleware struct {
1516

1617
// NewMiddleware creates a new Middleware
1718
// with a slice of plugins names.
18-
func NewMiddleware(names []string) *Middleware {
19+
func NewMiddleware(names []string, pg plugingetter.PluginGetter) *Middleware {
20+
SetPluginGetter(pg)
1921
return &Middleware{
2022
plugins: newPlugins(names),
2123
}

pkg/authorization/plugin.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package authorization
33
import (
44
"sync"
55

6+
"github.com/docker/docker/pkg/plugingetter"
67
"github.com/docker/docker/pkg/plugins"
78
)
89

@@ -33,6 +34,18 @@ func newPlugins(names []string) []Plugin {
3334
return plugins
3435
}
3536

37+
var getter plugingetter.PluginGetter
38+
39+
// SetPluginGetter sets the plugingetter
40+
func SetPluginGetter(pg plugingetter.PluginGetter) {
41+
getter = pg
42+
}
43+
44+
// GetPluginGetter gets the plugingetter
45+
func GetPluginGetter() plugingetter.PluginGetter {
46+
return getter
47+
}
48+
3649
// authorizationPlugin is an internal adapter to docker plugin system
3750
type authorizationPlugin struct {
3851
plugin *plugins.Client
@@ -80,7 +93,14 @@ func (a *authorizationPlugin) initPlugin() error {
8093
var err error
8194
a.once.Do(func() {
8295
if a.plugin == nil {
83-
plugin, e := plugins.Get(a.name, AuthZApiImplements)
96+
var plugin plugingetter.CompatPlugin
97+
var e error
98+
99+
if pg := GetPluginGetter(); pg != nil {
100+
plugin, e = pg.Get(a.name, AuthZApiImplements, plugingetter.LOOKUP)
101+
} else {
102+
plugin, e = plugins.Get(a.name, AuthZApiImplements)
103+
}
84104
if e != nil {
85105
err = e
86106
return

0 commit comments

Comments
 (0)