Browse code

Revert "Update authz plugin list on failure."

This reverts commit fae904af02a184833d2cd5ce9fdd61a4083707c7.

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>

Riyaz Faizullabhoy authored on 2016/11/03 06:29:40
Showing 3 changed files
... ...
@@ -52,8 +52,6 @@ type Ctx struct {
52 52
 }
53 53
 
54 54
 // AuthZRequest authorized the request to the docker daemon using authZ plugins
55
-// Side effect: If the authz plugin is invalid, then update ctx.plugins, so that
56
-// the caller(middleware) can update its list and stop retrying with invalid plugins.
57 55
 func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error {
58 56
 	var body []byte
59 57
 	if sendBody(ctx.requestURI, r.Header) && r.ContentLength > 0 && r.ContentLength < maxBodySize {
... ...
@@ -85,14 +83,11 @@ func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error {
85 85
 		}
86 86
 	}
87 87
 
88
-	for i, plugin := range ctx.plugins {
88
+	for _, plugin := range ctx.plugins {
89 89
 		logrus.Debugf("AuthZ request using plugin %s", plugin.Name())
90 90
 
91 91
 		authRes, err := plugin.AuthZRequest(ctx.authReq)
92 92
 		if err != nil {
93
-			if err == ErrInvalidPlugin {
94
-				ctx.plugins = append(ctx.plugins[:i], ctx.plugins[i+1:]...)
95
-			}
96 93
 			return fmt.Errorf("plugin %s failed with error: %s", plugin.Name(), err)
97 94
 		}
98 95
 
... ...
@@ -105,8 +100,6 @@ func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error {
105 105
 }
106 106
 
107 107
 // AuthZResponse authorized and manipulates the response from docker daemon using authZ plugins
108
-// Side effect: If the authz plugin is invalid, then update ctx.plugins, so that
109
-// the caller(middleware) can update its list and stop retrying with invalid plugins.
110 108
 func (ctx *Ctx) AuthZResponse(rm ResponseModifier, r *http.Request) error {
111 109
 	ctx.authReq.ResponseStatusCode = rm.StatusCode()
112 110
 	ctx.authReq.ResponseHeaders = headers(rm.Header())
... ...
@@ -115,14 +108,11 @@ func (ctx *Ctx) AuthZResponse(rm ResponseModifier, r *http.Request) error {
115 115
 		ctx.authReq.ResponseBody = rm.RawBody()
116 116
 	}
117 117
 
118
-	for i, plugin := range ctx.plugins {
118
+	for _, plugin := range ctx.plugins {
119 119
 		logrus.Debugf("AuthZ response using plugin %s", plugin.Name())
120 120
 
121 121
 		authRes, err := plugin.AuthZResponse(ctx.authReq)
122 122
 		if err != nil {
123
-			if err == ErrInvalidPlugin {
124
-				ctx.plugins = append(ctx.plugins[:i], ctx.plugins[i+1:]...)
125
-			}
126 123
 			return fmt.Errorf("plugin %s failed with error: %s", plugin.Name(), err)
127 124
 		}
128 125
 
... ...
@@ -2,7 +2,6 @@ package authorization
2 2
 
3 3
 import (
4 4
 	"net/http"
5
-	"strings"
6 5
 	"sync"
7 6
 
8 7
 	"github.com/Sirupsen/logrus"
... ...
@@ -60,11 +59,6 @@ func (m *Middleware) WrapHandler(handler func(ctx context.Context, w http.Respon
60 60
 
61 61
 		if err := authCtx.AuthZRequest(w, r); err != nil {
62 62
 			logrus.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err)
63
-			if strings.Contains(err.Error(), ErrInvalidPlugin.Error()) {
64
-				m.mu.Lock()
65
-				m.plugins = authCtx.plugins
66
-				m.mu.Unlock()
67
-			}
68 63
 			return err
69 64
 		}
70 65
 
... ...
@@ -78,11 +72,6 @@ func (m *Middleware) WrapHandler(handler func(ctx context.Context, w http.Respon
78 78
 
79 79
 		if err := authCtx.AuthZResponse(rw, r); errD == nil && err != nil {
80 80
 			logrus.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err)
81
-			if strings.Contains(err.Error(), ErrInvalidPlugin.Error()) {
82
-				m.mu.Lock()
83
-				m.plugins = authCtx.plugins
84
-				m.mu.Unlock()
85
-			}
86 81
 			return err
87 82
 		}
88 83
 
... ...
@@ -1,20 +1,12 @@
1 1
 package authorization
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"sync"
6 5
 
7 6
 	"github.com/docker/docker/pkg/plugingetter"
8 7
 	"github.com/docker/docker/pkg/plugins"
9 8
 )
10 9
 
11
-var (
12
-	// ErrInvalidPlugin indicates that the plugin cannot be used. This is
13
-	// because the plugin was not found or does not implement necessary
14
-	// functionality
15
-	ErrInvalidPlugin = errors.New("invalid plugin")
16
-)
17
-
18 10
 // Plugin allows third party plugins to authorize requests and responses
19 11
 // in the context of docker API
20 12
 type Plugin interface {
... ...
@@ -110,7 +102,7 @@ func (a *authorizationPlugin) initPlugin() error {
110 110
 				plugin, e = plugins.Get(a.name, AuthZApiImplements)
111 111
 			}
112 112
 			if e != nil {
113
-				err = ErrInvalidPlugin
113
+				err = e
114 114
 				return
115 115
 			}
116 116
 			a.plugin = plugin.Client()