mirror of
https://github.com/distribution/distribution.git
synced 2025-09-24 20:46:52 +00:00
reg/auth: remove contexts from Authorized method
The details of how request-scoped information is propagated through the registry server app should be left as private implementation details so they can be changed without fear of breaking compatibility with third-party code which imports the distribution module. The AccessController interface unnecessarily bakes into the public API details of how authorization grants are propagated through request contexts. In practice the only values the in-tree authorizers attach to the request contexts are the UserInfo and Resources for the request. Change the AccessController interface to return the UserInfo and Resources directly to allow us to change how request contexts are used within the app without altering the AccessController interface contract. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -797,7 +797,7 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont
|
||||
accessRecords = appendCatalogAccessRecord(accessRecords, r)
|
||||
}
|
||||
|
||||
ctx, err := app.accessController.Authorized(r.WithContext(context.Context), accessRecords...)
|
||||
grant, err := app.accessController.Authorized(r.WithContext(context.Context), accessRecords...)
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case auth.Challenge:
|
||||
@@ -818,6 +818,12 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont
|
||||
|
||||
return err
|
||||
}
|
||||
if grant == nil {
|
||||
return fmt.Errorf("access controller returned neither an access grant nor an error")
|
||||
}
|
||||
|
||||
ctx := auth.WithUser(context.Context, grant.User)
|
||||
ctx = auth.WithResources(ctx, grant.Resources)
|
||||
|
||||
dcontext.GetLogger(ctx, auth.UserNameKey).Info("authorized request")
|
||||
// TODO(stevvooe): This pattern needs to be cleaned up a bit. One context
|
||||
|
Reference in New Issue
Block a user