Disable Bucket/Replication (feature) if not enough permissions (#662)
* Bucket/Replication (feature) if not enough permissions * Address comments * Remove Consts fetchPerms
This commit is contained in:
@@ -1724,6 +1724,39 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/has-permission": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"UserAPI"
|
||||
],
|
||||
"summary": "Checks whether the user can perform a series of actions",
|
||||
"operationId": "HasPermissionTo",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/hasPermissionRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/hasPermissionResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Generic error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/login": {
|
||||
"get": {
|
||||
"security": [],
|
||||
@@ -4094,6 +4127,28 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"hasPermissionRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"actions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/policyArgs"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"hasPermissionResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"permissions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/permissionAction"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"iamEntity": {
|
||||
"type": "string",
|
||||
"pattern": "^[\\w+=,.@-]{1,64}$"
|
||||
@@ -4704,6 +4759,17 @@ func init() {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"permissionAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"can": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"podAffinityTerm": {
|
||||
"description": "Required. A pod affinity term, associated with the corresponding weight.",
|
||||
"type": "object",
|
||||
@@ -4777,6 +4843,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"policyArgs": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string"
|
||||
},
|
||||
"bucket_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"policyEntity": {
|
||||
"type": "string",
|
||||
"default": "user",
|
||||
@@ -7483,6 +7563,39 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/has-permission": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"UserAPI"
|
||||
],
|
||||
"summary": "Checks whether the user can perform a series of actions",
|
||||
"operationId": "HasPermissionTo",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/hasPermissionRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/hasPermissionResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Generic error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/login": {
|
||||
"get": {
|
||||
"security": [],
|
||||
@@ -10462,6 +10575,28 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"hasPermissionRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"actions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/policyArgs"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"hasPermissionResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"permissions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/permissionAction"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"iamEntity": {
|
||||
"type": "string",
|
||||
"pattern": "^[\\w+=,.@-]{1,64}$"
|
||||
@@ -11028,6 +11163,17 @@ func init() {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"permissionAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"can": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"podAffinityTerm": {
|
||||
"description": "Required. A pod affinity term, associated with the corresponding weight.",
|
||||
"type": "object",
|
||||
@@ -11079,6 +11225,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"policyArgs": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string"
|
||||
},
|
||||
"bucket_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"policyEntity": {
|
||||
"type": "string",
|
||||
"default": "user",
|
||||
|
||||
@@ -184,6 +184,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
|
||||
AdminAPIGroupInfoHandler: admin_api.GroupInfoHandlerFunc(func(params admin_api.GroupInfoParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation admin_api.GroupInfo has not yet been implemented")
|
||||
}),
|
||||
UserAPIHasPermissionToHandler: user_api.HasPermissionToHandlerFunc(func(params user_api.HasPermissionToParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation user_api.HasPermissionTo has not yet been implemented")
|
||||
}),
|
||||
AdminAPIListAllTenantsHandler: admin_api.ListAllTenantsHandlerFunc(func(params admin_api.ListAllTenantsParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation admin_api.ListAllTenants has not yet been implemented")
|
||||
}),
|
||||
@@ -475,6 +478,8 @@ type ConsoleAPI struct {
|
||||
AdminAPIGetUserInfoHandler admin_api.GetUserInfoHandler
|
||||
// AdminAPIGroupInfoHandler sets the operation handler for the group info operation
|
||||
AdminAPIGroupInfoHandler admin_api.GroupInfoHandler
|
||||
// UserAPIHasPermissionToHandler sets the operation handler for the has permission to operation
|
||||
UserAPIHasPermissionToHandler user_api.HasPermissionToHandler
|
||||
// AdminAPIListAllTenantsHandler sets the operation handler for the list all tenants operation
|
||||
AdminAPIListAllTenantsHandler admin_api.ListAllTenantsHandler
|
||||
// UserAPIListBucketEventsHandler sets the operation handler for the list bucket events operation
|
||||
@@ -777,6 +782,9 @@ func (o *ConsoleAPI) Validate() error {
|
||||
if o.AdminAPIGroupInfoHandler == nil {
|
||||
unregistered = append(unregistered, "admin_api.GroupInfoHandler")
|
||||
}
|
||||
if o.UserAPIHasPermissionToHandler == nil {
|
||||
unregistered = append(unregistered, "user_api.HasPermissionToHandler")
|
||||
}
|
||||
if o.AdminAPIListAllTenantsHandler == nil {
|
||||
unregistered = append(unregistered, "admin_api.ListAllTenantsHandler")
|
||||
}
|
||||
@@ -1198,6 +1206,10 @@ func (o *ConsoleAPI) initHandlerCache() {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["GET"]["/groups/{name}"] = admin_api.NewGroupInfo(o.context, o.AdminAPIGroupInfoHandler)
|
||||
if o.handlers["POST"] == nil {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["POST"]["/has-permission"] = user_api.NewHasPermissionTo(o.context, o.UserAPIHasPermissionToHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
||||
90
restapi/operations/user_api/has_permission_to.go
Normal file
90
restapi/operations/user_api/has_permission_to.go
Normal file
@@ -0,0 +1,90 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2021 MinIO, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
package user_api
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
)
|
||||
|
||||
// HasPermissionToHandlerFunc turns a function with the right signature into a has permission to handler
|
||||
type HasPermissionToHandlerFunc func(HasPermissionToParams, *models.Principal) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn HasPermissionToHandlerFunc) Handle(params HasPermissionToParams, principal *models.Principal) middleware.Responder {
|
||||
return fn(params, principal)
|
||||
}
|
||||
|
||||
// HasPermissionToHandler interface for that can handle valid has permission to params
|
||||
type HasPermissionToHandler interface {
|
||||
Handle(HasPermissionToParams, *models.Principal) middleware.Responder
|
||||
}
|
||||
|
||||
// NewHasPermissionTo creates a new http.Handler for the has permission to operation
|
||||
func NewHasPermissionTo(ctx *middleware.Context, handler HasPermissionToHandler) *HasPermissionTo {
|
||||
return &HasPermissionTo{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*HasPermissionTo swagger:route POST /has-permission UserAPI hasPermissionTo
|
||||
|
||||
Checks whether the user can perform a series of actions
|
||||
|
||||
*/
|
||||
type HasPermissionTo struct {
|
||||
Context *middleware.Context
|
||||
Handler HasPermissionToHandler
|
||||
}
|
||||
|
||||
func (o *HasPermissionTo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
r = rCtx
|
||||
}
|
||||
var Params = NewHasPermissionToParams()
|
||||
|
||||
uprinc, aCtx, err := o.Context.Authorize(r, route)
|
||||
if err != nil {
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
if aCtx != nil {
|
||||
r = aCtx
|
||||
}
|
||||
var principal *models.Principal
|
||||
if uprinc != nil {
|
||||
principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
|
||||
}
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
||||
res := o.Handler.Handle(Params, principal) // actually handle the request
|
||||
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
||||
94
restapi/operations/user_api/has_permission_to_parameters.go
Normal file
94
restapi/operations/user_api/has_permission_to_parameters.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2021 MinIO, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
package user_api
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
)
|
||||
|
||||
// NewHasPermissionToParams creates a new HasPermissionToParams object
|
||||
// no default values defined in spec.
|
||||
func NewHasPermissionToParams() HasPermissionToParams {
|
||||
|
||||
return HasPermissionToParams{}
|
||||
}
|
||||
|
||||
// HasPermissionToParams contains all the bound params for the has permission to operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters HasPermissionTo
|
||||
type HasPermissionToParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
||||
/*
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
Body *models.HasPermissionRequest
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
// for simple values it will use straight method calls.
|
||||
//
|
||||
// To ensure default values, the struct must have been initialized with NewHasPermissionToParams() beforehand.
|
||||
func (o *HasPermissionToParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body models.HasPermissionRequest
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
} else {
|
||||
res = append(res, errors.NewParseError("body", "body", "", err))
|
||||
}
|
||||
} else {
|
||||
// validate body object
|
||||
if err := body.Validate(route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
o.Body = &body
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
133
restapi/operations/user_api/has_permission_to_responses.go
Normal file
133
restapi/operations/user_api/has_permission_to_responses.go
Normal file
@@ -0,0 +1,133 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2021 MinIO, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
package user_api
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
)
|
||||
|
||||
// HasPermissionToCreatedCode is the HTTP code returned for type HasPermissionToCreated
|
||||
const HasPermissionToCreatedCode int = 201
|
||||
|
||||
/*HasPermissionToCreated A successful response.
|
||||
|
||||
swagger:response hasPermissionToCreated
|
||||
*/
|
||||
type HasPermissionToCreated struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.HasPermissionResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewHasPermissionToCreated creates HasPermissionToCreated with default headers values
|
||||
func NewHasPermissionToCreated() *HasPermissionToCreated {
|
||||
|
||||
return &HasPermissionToCreated{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the has permission to created response
|
||||
func (o *HasPermissionToCreated) WithPayload(payload *models.HasPermissionResponse) *HasPermissionToCreated {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the has permission to created response
|
||||
func (o *HasPermissionToCreated) SetPayload(payload *models.HasPermissionResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *HasPermissionToCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(201)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*HasPermissionToDefault Generic error response.
|
||||
|
||||
swagger:response hasPermissionToDefault
|
||||
*/
|
||||
type HasPermissionToDefault struct {
|
||||
_statusCode int
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Error `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewHasPermissionToDefault creates HasPermissionToDefault with default headers values
|
||||
func NewHasPermissionToDefault(code int) *HasPermissionToDefault {
|
||||
if code <= 0 {
|
||||
code = 500
|
||||
}
|
||||
|
||||
return &HasPermissionToDefault{
|
||||
_statusCode: code,
|
||||
}
|
||||
}
|
||||
|
||||
// WithStatusCode adds the status to the has permission to default response
|
||||
func (o *HasPermissionToDefault) WithStatusCode(code int) *HasPermissionToDefault {
|
||||
o._statusCode = code
|
||||
return o
|
||||
}
|
||||
|
||||
// SetStatusCode sets the status to the has permission to default response
|
||||
func (o *HasPermissionToDefault) SetStatusCode(code int) {
|
||||
o._statusCode = code
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the has permission to default response
|
||||
func (o *HasPermissionToDefault) WithPayload(payload *models.Error) *HasPermissionToDefault {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the has permission to default response
|
||||
func (o *HasPermissionToDefault) SetPayload(payload *models.Error) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *HasPermissionToDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(o._statusCode)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
104
restapi/operations/user_api/has_permission_to_urlbuilder.go
Normal file
104
restapi/operations/user_api/has_permission_to_urlbuilder.go
Normal file
@@ -0,0 +1,104 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2021 MinIO, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
package user_api
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the generate command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
golangswaggerpaths "path"
|
||||
)
|
||||
|
||||
// HasPermissionToURL generates an URL for the has permission to operation
|
||||
type HasPermissionToURL struct {
|
||||
_basePath string
|
||||
}
|
||||
|
||||
// WithBasePath sets the base path for this url builder, only required when it's different from the
|
||||
// base path specified in the swagger spec.
|
||||
// When the value of the base path is an empty string
|
||||
func (o *HasPermissionToURL) WithBasePath(bp string) *HasPermissionToURL {
|
||||
o.SetBasePath(bp)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBasePath sets the base path for this url builder, only required when it's different from the
|
||||
// base path specified in the swagger spec.
|
||||
// When the value of the base path is an empty string
|
||||
func (o *HasPermissionToURL) SetBasePath(bp string) {
|
||||
o._basePath = bp
|
||||
}
|
||||
|
||||
// Build a url path and query string
|
||||
func (o *HasPermissionToURL) Build() (*url.URL, error) {
|
||||
var _result url.URL
|
||||
|
||||
var _path = "/has-permission"
|
||||
|
||||
_basePath := o._basePath
|
||||
if _basePath == "" {
|
||||
_basePath = "/api/v1"
|
||||
}
|
||||
_result.Path = golangswaggerpaths.Join(_basePath, _path)
|
||||
|
||||
return &_result, nil
|
||||
}
|
||||
|
||||
// Must is a helper function to panic when the url builder returns an error
|
||||
func (o *HasPermissionToURL) Must(u *url.URL, err error) *url.URL {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if u == nil {
|
||||
panic("url can't be nil")
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
// String returns the string representation of the path with query string
|
||||
func (o *HasPermissionToURL) String() string {
|
||||
return o.Must(o.Build()).String()
|
||||
}
|
||||
|
||||
// BuildFull builds a full url with scheme, host, path and query string
|
||||
func (o *HasPermissionToURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
if scheme == "" {
|
||||
return nil, errors.New("scheme is required for a full url on HasPermissionToURL")
|
||||
}
|
||||
if host == "" {
|
||||
return nil, errors.New("host is required for a full url on HasPermissionToURL")
|
||||
}
|
||||
|
||||
base, err := o.Build()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
base.Scheme = scheme
|
||||
base.Host = host
|
||||
return base, nil
|
||||
}
|
||||
|
||||
// StringFull returns the string representation of a complete url
|
||||
func (o *HasPermissionToURL) StringFull(scheme, host string) string {
|
||||
return o.Must(o.BuildFull(scheme, host)).String()
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/minio/console/models"
|
||||
@@ -42,6 +44,15 @@ func registerAccountHandlers(api *operations.ConsoleAPI) {
|
||||
user_api.NewLoginCreated().WithPayload(changePasswordResponse).WriteResponse(w, p)
|
||||
})
|
||||
})
|
||||
// Checks if user can perform an action
|
||||
api.UserAPIHasPermissionToHandler = user_api.HasPermissionToHandlerFunc(func(params user_api.HasPermissionToParams, session *models.Principal) middleware.Responder {
|
||||
hasPermissionRespose, err := getUserHasPermissionsResponse(session, params)
|
||||
if err != nil {
|
||||
return user_api.NewHasPermissionToDefault(500).WithPayload(err)
|
||||
}
|
||||
// Custom response writer to update the session cookies
|
||||
return user_api.NewHasPermissionToCreated().WithPayload(hasPermissionRespose)
|
||||
})
|
||||
}
|
||||
|
||||
// changePassword validate current current user password and if it's correct set the new password
|
||||
@@ -92,3 +103,48 @@ func getChangePasswordResponse(session *models.Principal, params user_api.Accoun
|
||||
}
|
||||
return loginResponse, nil
|
||||
}
|
||||
|
||||
func getUserHasPermissionsResponse(session *models.Principal, params user_api.HasPermissionToParams) (*models.HasPermissionResponse, *models.Error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
|
||||
defer cancel()
|
||||
|
||||
mAdmin, err := newMAdminClient(session)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
// create a minioClient interface implementation
|
||||
// defining the client to be used
|
||||
adminClient := adminClient{client: mAdmin}
|
||||
|
||||
userPolicy, err := getAccountPolicy(ctx, adminClient)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
|
||||
var perms []*models.PermissionAction
|
||||
|
||||
for _, p := range params.Body.Actions {
|
||||
canPerform := userCanDo(iampolicy.Args{
|
||||
Action: iampolicy.Action(p.Action),
|
||||
BucketName: p.BucketName,
|
||||
}, userPolicy)
|
||||
perms = append(perms, &models.PermissionAction{
|
||||
Can: canPerform,
|
||||
ID: p.ID,
|
||||
})
|
||||
}
|
||||
|
||||
return &models.HasPermissionResponse{
|
||||
Permissions: perms,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func userCanDo(arg iampolicy.Args, userPolicy *iampolicy.Policy) bool {
|
||||
// check in all the statements if any allows the passed action
|
||||
for _, stmt := range userPolicy.Statements {
|
||||
if stmt.IsAllowed(arg) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -18,9 +18,12 @@ package restapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
)
|
||||
|
||||
@@ -106,3 +109,152 @@ func Test_changePassword(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_useCanDo(t *testing.T) {
|
||||
type args struct {
|
||||
arg iampolicy.Args
|
||||
userPolicy string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "Create Bucket",
|
||||
args: args{
|
||||
arg: iampolicy.Args{
|
||||
Action: "s3:CreateBucket",
|
||||
},
|
||||
userPolicy: `{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"admin:*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:*"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Create Bucket, No Admin",
|
||||
args: args{
|
||||
arg: iampolicy.Args{
|
||||
Action: "s3:CreateBucket",
|
||||
},
|
||||
userPolicy: `{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:*"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Create Bucket, By Prefix",
|
||||
args: args{
|
||||
arg: iampolicy.Args{
|
||||
Action: "s3:CreateBucket",
|
||||
},
|
||||
userPolicy: `{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:*"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::bucket1"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "Create Bucket, With Bucket Name",
|
||||
args: args{
|
||||
arg: iampolicy.Args{
|
||||
Action: "s3:CreateBucket",
|
||||
BucketName: "bucket2",
|
||||
},
|
||||
userPolicy: `{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:*"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::bucket1"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "Can't Create Bucket",
|
||||
args: args{
|
||||
arg: iampolicy.Args{
|
||||
Action: "s3:CreateBucket",
|
||||
BucketName: "bucket2",
|
||||
},
|
||||
userPolicy: `{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "VisualEditor1",
|
||||
"Effect": "Allow",
|
||||
"Action": "s3:ListBucket",
|
||||
"Resource": [
|
||||
"arn:aws:s3:::bucket1",
|
||||
"arn:aws:s3:::bucket1/*",
|
||||
"arn:aws:s3:::lkasdkljasd090901",
|
||||
"arn:aws:s3:::lkasdkljasd090901/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var pol iampolicy.Policy
|
||||
if err := json.Unmarshal([]byte(tt.args.userPolicy), &pol); err != nil {
|
||||
t.Errorf("Policy can't be parsed: %s", err)
|
||||
}
|
||||
if got := userCanDo(tt.args.arg, &pol); got != tt.want {
|
||||
t.Errorf("userCanDo() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +324,7 @@ func getAccountInfo(ctx context.Context, client MinioAdmin) ([]*models.Bucket, e
|
||||
if err != nil {
|
||||
return []*models.Bucket{}, err
|
||||
}
|
||||
|
||||
var bucketInfos []*models.Bucket
|
||||
for _, bucket := range info.Buckets {
|
||||
bucketElem := &models.Bucket{Name: swag.String(bucket.Name), CreationDate: bucket.Created.Format(time.RFC3339), Size: int64(bucket.Size)}
|
||||
|
||||
Reference in New Issue
Block a user