auth: protect all maintainence APIs when auth is enabled
All maintenance APIs require admin privilege when auth is enabled, otherwise, the request will be rejected. If auth isn't enabled, then no such requirement any more. Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
|
||||
"go.etcd.io/etcd/server/v3/auth"
|
||||
"go.etcd.io/etcd/server/v3/etcdserver"
|
||||
)
|
||||
|
||||
@ -164,3 +165,23 @@ func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChan
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type AuthGetter interface {
|
||||
AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error)
|
||||
AuthStore() auth.AuthStore
|
||||
}
|
||||
|
||||
type AuthAdmin struct {
|
||||
ag AuthGetter
|
||||
}
|
||||
|
||||
// isPermitted verifies the user has admin privilege.
|
||||
// Only users with "root" role are permitted.
|
||||
func (aa *AuthAdmin) isPermitted(ctx context.Context) error {
|
||||
authInfo, err := aa.ag.AuthInfoFromCtx(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return aa.ag.AuthStore().IsAdminPermitted(authInfo)
|
||||
}
|
||||
|
Reference in New Issue
Block a user