Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserAdd and RoleAdd bypass --quota-backend-bytes #16150

Open
4 tasks done
CaojiamingAlan opened this issue Jun 28, 2023 · 5 comments
Open
4 tasks done

UserAdd and RoleAdd bypass --quota-backend-bytes #16150

CaojiamingAlan opened this issue Jun 28, 2023 · 5 comments

Comments

@CaojiamingAlan
Copy link
Contributor

Bug report criteria

What happened?

When the db size hit the limit of --quota-backend-bytes, users can still add users and roles, causing the db size continue to increase.

What did you expect to happen?

user add/role add should also return ErrNoSpace when hitting the limit

How can we reproduce it (as minimally and precisely as possible)?

  1. Start etcd server with a low --quota-backend-bytes, for example 200kB: etcd --quota-backend-bytes=$((200*1024))

Check the db size with etcdctl --write-out=table endpoint status
The db's initial size is 98kB:
image

  1. Use scripts to add 1000 users:
package main

import (
	"context"
	"fmt"
	clientv3 "go.etcd.io/etcd/client/v3"
	"google.golang.org/grpc"
	"math/rand"
	"time"
)

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(n int) string {
	b := make([]rune, n)
	for i := range b {
		b[i] = letterRunes[rand.Intn(len(letterRunes))]
	}
	return string(b)
}

func main() {
	fmt.Println("start")
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"localhost:2379"},
		DialTimeout: time.Second * 5,
		DialOptions: []grpc.DialOption{grpc.WithBlock()},
	})
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	for i := 0; i < 1000; i++ {
		_, err := cli.UserAdd(context.Background(), RandStringRunes(100), "password")
		if err != nil {
			fmt.Println(err.Error())
			return
		}
	}
}
  1. Check the db size, it is now 500kB, despite showing a NOSPACE alarm
image

Anything else we need to know?

No response

Etcd version (please run commands below)

I believe all versions are affected

Etcd configuration (command line flags or environment variables)

No response

Etcd debug information (please run commands below, feel free to obfuscate the IP address or FQDN in the output)

No response

Relevant log output

No response

@chaochn47
Copy link
Member

Thanks @CaojiamingAlan for bringing it up!

Looks like it is missed not only in the quota applier but in grpc API layer.

@iuriatan
Copy link
Contributor

iuriatan commented Jul 2, 2023

It looks like a good first issue to me. If you think it's OK, I'd like to work on it and bring some update up until Wednesday, 5th.

@CaojiamingAlan
Copy link
Contributor Author

@iuriatan Thank you for your enthusiasm. However, IMHO lets not rush to fix this.

In fact, the title of the issue may be a little bit misleading, since the set of auth related apis that need to be considered includes all the apis that write new records to the authstore(UserAdd/UserChangePassword/UserGrantRole/UserRevokeRole/RoleAdd/RoleGrantPermission/RoleRevokePermission etc.)

And for each api, it involves several parts of work:

  1. Estimate the cost of each api as here
  2. Implementing a new layer of grpc APIs as here
  3. Override the apis for applierV3Capped and quotaApplierV3

All of the three parts do not have enough test coverage yet. Therefore, I don't think a PR that change all these manually would be accepted. We should improve the test coverage first and try to make changes after that. #16036 (comment)

I would also like to hear other's opinion about this.

@iuriatan
Copy link
Contributor

iuriatan commented Jul 6, 2023

@CaojiamingAlan Can you help defining some cases to be tested? I can work on extending appliers test coverage while the community discuss strategies.

@CaojiamingAlan
Copy link
Contributor Author

The tests I've written so far covers the correctness of permission checks and alarm handling, but not yet throughly test the correctness of the result of applying. For example, first PUT and then RANGE to see whether the result matches. There are still some apis are not covered at all, like ClusterVersionSet.
You can run
go test -coverprofile coverage.out && go tool cover -html=coverage.out
under the server/etcdserver/apply folder to generate a report showing the test coverage.

iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 13, 2023
* add `put` tests on quota applier

Following discussions on  etcd-io#16036 and etcd-io#16150, this patch aims to improve
appliers test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 14, 2023
* add `put` tests on quota applier

Following discussions on  etcd-io#16036 and etcd-io#16150, this patch aims to improve
appliers test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 14, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch aims to improve
appliers test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 14, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch improves appliers
test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 15, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch improves appliers
test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 15, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch improves appliers
test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 15, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch improves appliers
test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Jul 27, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch improves appliers
test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
iuriatan added a commit to iuriatan/etcd that referenced this issue Aug 10, 2023
* add `put` tests on quota applier

Following discussions on etcd-io#16036 and etcd-io#16150, this patch improves appliers
test coverage.

Signed-off-by: iuriatan <iuriatan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants