enhance: disallow tikv/rawkv usages (#30027)

Data write through rawkv API may pollute tikv data. It should be
disallowed.
We will add this check to all repos that involves metadata access.
In the longer term, we should have a metadata service that implements
access control.

relate: #30029

Signed-off-by: yiwangdr <yiwangdr@gmail.com>
This commit is contained in:
yiwangdr 2024-02-05 18:41:41 -08:00 committed by GitHub
parent d097d558b6
commit 85246c1f5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 24 deletions

View File

@ -106,6 +106,10 @@ linters-settings:
desc: not allowed, use github.com/cockroachdb/errors desc: not allowed, use github.com/cockroachdb/errors
- pkg: "io/ioutil" - pkg: "io/ioutil"
desc: ioutil is deprecated after 1.16, 1.17, use os and io package instead desc: ioutil is deprecated after 1.16, 1.17, use os and io package instead
- pkg: "github.com/tikv/client-go/rawkv"
desc: not allowed, use github.com/tikv/client-go/v2/txnkv
- pkg: "github.com/tikv/client-go/v2/rawkv"
desc: not allowed, use github.com/tikv/client-go/v2/txnkv
forbidigo: forbidigo:
forbid: forbid:
- '^time\.Tick$' - '^time\.Tick$'

View File

@ -17,11 +17,9 @@
package tikv package tikv
import ( import (
"context"
"os" "os"
"testing" "testing"
"github.com/tikv/client-go/v2/rawkv"
"github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/testutils"
tilib "github.com/tikv/client-go/v2/tikv" tilib "github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv" "github.com/tikv/client-go/v2/txnkv"
@ -29,15 +27,11 @@ import (
"github.com/milvus-io/milvus/pkg/util/paramtable" "github.com/milvus-io/milvus/pkg/util/paramtable"
) )
var ( var txnClient *txnkv.Client
txnClient *txnkv.Client
rawClient *rawkv.Client
)
// creates a local TiKV Store for testing purpose. // creates a local TiKV Store for testing purpose.
func setupLocalTiKV() { func setupLocalTiKV() {
setupLocalTxn() setupLocalTxn()
setupLocalRaw()
} }
func setupLocalTxn() { func setupLocalTxn() {
@ -53,19 +47,6 @@ func setupLocalTxn() {
txnClient = &txnkv.Client{KVStore: store} txnClient = &txnkv.Client{KVStore: store}
} }
func setupLocalRaw() {
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
if err != nil {
panic(err)
}
testutils.BootstrapWithSingleStore(cluster)
rawClient = &rawkv.Client{}
p := rawkv.ClientProbe{Client: rawClient}
p.SetPDClient(pdClient)
p.SetRegionCache(tilib.NewRegionCache(pdClient))
p.SetRPCClient(client)
}
// Connects to a remote TiKV service for testing purpose. By default, it assumes the TiKV is from localhost. // Connects to a remote TiKV service for testing purpose. By default, it assumes the TiKV is from localhost.
func setupRemoteTiKV() { func setupRemoteTiKV() {
pdsn := "127.0.0.1:2379" pdsn := "127.0.0.1:2379"
@ -74,10 +55,6 @@ func setupRemoteTiKV() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
rawClient, err = rawkv.NewClientWithOpts(context.Background(), []string{pdsn})
if err != nil {
panic(err)
}
} }
func setupTiKV(useRemote bool) { func setupTiKV(useRemote bool) {