From bdcb43d057cc483ce6ab6de682392a8f7d5d0c36 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Mon, 24 Jun 2024 07:12:39 -0400 Subject: [PATCH] VIndexes: Stop recommending md5 based vindex types as md5 is considered insecure (#16113) Signed-off-by: Matt Lord --- .../vreplication/lookupvindex/lookupvindex.go | 2 +- go/vt/vtctl/workflow/materializer_test.go | 20 +++++++++---------- go/vt/vtgate/vindexes/vschema.go | 6 ++---- go/vt/vtgate/vindexes/vschema_test.go | 12 +++++------ go/vt/wrangler/materializer_test.go | 8 ++++---- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/go/cmd/vtctldclient/command/vreplication/lookupvindex/lookupvindex.go b/go/cmd/vtctldclient/command/vreplication/lookupvindex/lookupvindex.go index b703e873bd0..9650a52e8a5 100644 --- a/go/cmd/vtctldclient/command/vreplication/lookupvindex/lookupvindex.go +++ b/go/cmd/vtctldclient/command/vreplication/lookupvindex/lookupvindex.go @@ -291,7 +291,7 @@ func registerCommands(root *cobra.Command) { create.Flags().StringSliceVar(&createOptions.TableOwnerColumns, "table-owner-columns", nil, "The columns to read from the owner table. These will be used to build the hash which gets stored as the keyspace_id value in the lookup table.") create.MarkFlagRequired("table-owner-columns") create.Flags().StringVar(&createOptions.TableName, "table-name", "", "The name of the lookup table. If not specified, then it will be created using the same name as the Lookup Vindex.") - create.Flags().StringVar(&createOptions.TableVindexType, "table-vindex-type", "", "The primary vindex name/type to use for the lookup table, if the table-keyspace is sharded. This must match the name of a vindex defined in the table-keyspace. If no value is provided then the default type will be used based on the table-owner-columns types.") + create.Flags().StringVar(&createOptions.TableVindexType, "table-vindex-type", "", "The primary vindex name/type to use for the lookup table, if the table-keyspace is sharded. If no value is provided then the default type will be used based on the table-owner-columns types.") create.Flags().BoolVar(&createOptions.IgnoreNulls, "ignore-nulls", false, "Do not add corresponding records in the lookup table if any of the owner table's 'from' fields are NULL.") create.Flags().BoolVar(&createOptions.ContinueAfterCopyWithOwner, "continue-after-copy-with-owner", true, "Vindex will continue materialization after the backfill completes when an owner is provided.") // VReplication specific flags. diff --git a/go/vt/vtctl/workflow/materializer_test.go b/go/vt/vtctl/workflow/materializer_test.go index d9fe7b9eb1f..51a7d22d5eb 100644 --- a/go/vt/vtctl/workflow/materializer_test.go +++ b/go/vt/vtctl/workflow/materializer_test.go @@ -1531,15 +1531,15 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { out: &vschemapb.Keyspace{ Sharded: true, Vindexes: map[string]*vschemapb.Vindex{ - "unicode_loose_md5": { - Type: "unicode_loose_md5", + "unicode_loose_xxhash": { + Type: "unicode_loose_xxhash", }, }, Tables: map[string]*vschemapb.Table{ "lkp": { ColumnVindexes: []*vschemapb.ColumnVindex{{ Column: "c1", - Name: "unicode_loose_md5", + Name: "unicode_loose_xxhash", }}, }, }, @@ -1581,7 +1581,7 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { Vindexes: map[string]*vschemapb.Vindex{ // Create a misleading vindex name. "xxhash": { - Type: "unicode_loose_md5", + Type: "unicode_loose_xxhash", }, }, }, @@ -1803,7 +1803,7 @@ func TestCreateCustomizedVindex(t *testing.T) { }, "lookup": { ColumnVindexes: []*vschemapb.ColumnVindex{{ - Name: "unicode_loose_md5", + Name: "unicode_loose_xxhash", Column: "c1", }}, }, @@ -1823,8 +1823,8 @@ func TestCreateCustomizedVindex(t *testing.T) { "xxhash": { Type: "xxhash", }, - "unicode_loose_md5": { // Non default vindex type for the column. - Type: "unicode_loose_md5", + "unicode_loose_xxhash": { // Non default vindex type for the column. + Type: "unicode_loose_xxhash", }, }, Tables: map[string]*vschemapb.Table{ @@ -1842,8 +1842,8 @@ func TestCreateCustomizedVindex(t *testing.T) { "xxhash": { Type: "xxhash", }, - "unicode_loose_md5": { - Type: "unicode_loose_md5", + "unicode_loose_xxhash": { + Type: "unicode_loose_xxhash", }, "v": { Type: "lookup_unique", @@ -1869,7 +1869,7 @@ func TestCreateCustomizedVindex(t *testing.T) { "lookup": { ColumnVindexes: []*vschemapb.ColumnVindex{{ Column: "c1", - Name: "unicode_loose_md5", + Name: "unicode_loose_xxhash", }}, }, }, diff --git a/go/vt/vtgate/vindexes/vschema.go b/go/vt/vtgate/vindexes/vschema.go index 924a28b309d..838476f061f 100644 --- a/go/vt/vtgate/vindexes/vschema.go +++ b/go/vt/vtgate/vindexes/vschema.go @@ -1378,12 +1378,10 @@ func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error) { // the given SQL data type. func ChooseVindexForType(typ querypb.Type) (string, error) { switch { - case sqltypes.IsIntegral(typ): + case sqltypes.IsIntegral(typ) || sqltypes.IsBinary(typ): return "xxhash", nil case sqltypes.IsText(typ): - return "unicode_loose_md5", nil - case sqltypes.IsBinary(typ): - return "binary_md5", nil + return "unicode_loose_xxhash", nil } return "", vterrors.Errorf( vtrpcpb.Code_INVALID_ARGUMENT, diff --git a/go/vt/vtgate/vindexes/vschema_test.go b/go/vt/vtgate/vindexes/vschema_test.go index 40cba720a0c..0cb47294c91 100644 --- a/go/vt/vtgate/vindexes/vschema_test.go +++ b/go/vt/vtgate/vindexes/vschema_test.go @@ -960,22 +960,22 @@ func TestChooseVindexForType(t *testing.T) { out: "", }, { in: sqltypes.Text, - out: "unicode_loose_md5", + out: "unicode_loose_xxhash", }, { in: sqltypes.Blob, - out: "binary_md5", + out: "xxhash", }, { in: sqltypes.VarChar, - out: "unicode_loose_md5", + out: "unicode_loose_xxhash", }, { in: sqltypes.VarBinary, - out: "binary_md5", + out: "xxhash", }, { in: sqltypes.Char, - out: "unicode_loose_md5", + out: "unicode_loose_xxhash", }, { in: sqltypes.Binary, - out: "binary_md5", + out: "xxhash", }, { in: sqltypes.Bit, out: "", diff --git a/go/vt/wrangler/materializer_test.go b/go/vt/wrangler/materializer_test.go index 23cae954b83..a506d52d511 100644 --- a/go/vt/wrangler/materializer_test.go +++ b/go/vt/wrangler/materializer_test.go @@ -952,15 +952,15 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { out: &vschemapb.Keyspace{ Sharded: true, Vindexes: map[string]*vschemapb.Vindex{ - "unicode_loose_md5": { - Type: "unicode_loose_md5", + "unicode_loose_xxhash": { + Type: "unicode_loose_xxhash", }, }, Tables: map[string]*vschemapb.Table{ "lkp": { ColumnVindexes: []*vschemapb.ColumnVindex{{ Column: "c1", - Name: "unicode_loose_md5", + Name: "unicode_loose_xxhash", }}, }, }, @@ -1002,7 +1002,7 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { Vindexes: map[string]*vschemapb.Vindex{ // Create a misleading vindex name. "xxhash": { - Type: "unicode_loose_md5", + Type: "unicode_loose_xxhash", }, }, },