mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Fix authorization issue - when request is denied return forbbiden exist code (403).
- Return 403 (forbidden) when request is denied in authorization flows (including integration test) - Fix #22428 - Close #22431 Signed-off-by: Liron Levin <liron@twistlock.com>
This commit is contained in:
		
							parent
							
								
									b0a5762348
								
							
						
					
					
						commit
						526abc00b1
					
				
					 4 changed files with 48 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -85,7 +85,7 @@ func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error {
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		if !authRes.Allow {
 | 
			
		||||
			return fmt.Errorf("authorization denied by plugin %s: %s", plugin.Name(), authRes.Msg)
 | 
			
		||||
			return newAuthorizationError(plugin.Name(), authRes.Msg)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +110,7 @@ func (ctx *Ctx) AuthZResponse(rm ResponseModifier, r *http.Request) error {
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		if !authRes.Allow {
 | 
			
		||||
			return fmt.Errorf("authorization denied by plugin %s: %s", plugin.Name(), authRes.Msg)
 | 
			
		||||
			return newAuthorizationError(plugin.Name(), authRes.Msg)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -163,3 +163,17 @@ func headers(header http.Header) map[string]string {
 | 
			
		|||
	}
 | 
			
		||||
	return v
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// authorizationError represents an authorization deny error
 | 
			
		||||
type authorizationError struct {
 | 
			
		||||
	error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HTTPErrorStatusCode returns the authorization error status code (forbidden)
 | 
			
		||||
func (e authorizationError) HTTPErrorStatusCode() int {
 | 
			
		||||
	return http.StatusForbidden
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newAuthorizationError(plugin, msg string) authorizationError {
 | 
			
		||||
	return authorizationError{error: fmt.Errorf("authorization denied by plugin %s: %s", plugin, msg)}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue