Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into views-routing
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Jan 31, 2025
2 parents 97793a6 + cb7d61a commit cdd2a0a
Show file tree
Hide file tree
Showing 60 changed files with 5,374 additions and 5,214 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_race.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_race_evalengine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test_evalengine_mysql57.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test_evalengine_mysql80.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test_evalengine_mysql84.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test_mysql57.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test_mysql80.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test_mysql84.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld || echo "could not remove mysqld profile"
mkdir -p dist bin
curl -s -L https://github.com/coreos/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.3.10-linux-amd64/{etcd,etcdctl} bin/
curl -s -L https://github.com/coreos/etcd/releases/download/v3.5.17/etcd-v3.5.17-linux-amd64.tar.gz | tar -zxC dist
mv dist/etcd-v3.5.17-linux-amd64/{etcd,etcdctl} bin/
go mod download
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
2 changes: 1 addition & 1 deletion build.env
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export VTDATAROOT="${VTDATAROOT:-${VTROOT}/vtdataroot}"
export PATH="$PWD/bin:$PATH"
export PROTOC_VER=21.3
export ZK_VER=${ZK_VERSION:-3.8.0}
export ETCD_VER=v3.5.6
export ETCD_VER=v3.5.17
export CONSUL_VER=1.11.4
export TOXIPROXY_VER=v2.7.0

Expand Down
2 changes: 1 addition & 1 deletion docker/mini/install_mini_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
set -euo pipefail

# Install etcd
ETCD_VER=v3.4.9
ETCD_VER=v3.5.17
DOWNLOAD_URL=https://storage.googleapis.com/etcd

curl -k -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
Expand Down
50 changes: 50 additions & 0 deletions go/os2/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2025 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package os2

import (
"io/fs"
"os"
)

const (
// PermFile is a FileMode for regular files without world permission bits.
PermFile fs.FileMode = 0660
// PermDirectory is a FileMode for directories without world permission bits.
PermDirectory fs.FileMode = 0770
)

// Create is identical to os.Create except uses 0660 permission
// rather than 0666, to exclude world read/write bit.
func Create(name string) (*os.File, error) {
return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, PermFile)
}

// WriteFile is identical to os.WriteFile except permission of 0660 is used.
func WriteFile(name string, data []byte) error {
return os.WriteFile(name, data, PermFile)
}

// Mkdir is identical to os.Mkdir except permission of 0770 is used.
func Mkdir(path string) error {
return os.Mkdir(path, PermDirectory)
}

// MkdirAll is identical to os.MkdirAll except permission of 0770 is used.
func MkdirAll(path string) error {
return os.MkdirAll(path, PermDirectory)
}
12 changes: 12 additions & 0 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ func TestBackup(t *testing.T, setupType int, streamMode string, stripes int, cDe
return vterrors.Errorf(vtrpc.Code_UNKNOWN, "test failure: %s", test.name)
}
}

t.Run("check for files created with global permissions", func(t *testing.T) {
t.Logf("Confirming that none of the MySQL data directories that we've created have files with global permissions")
for _, ks := range localCluster.Keyspaces {
for _, shard := range ks.Shards {
for _, tablet := range shard.Vttablets {
tablet.VttabletProcess.ConfirmDataDirHasNoGlobalPerms(t)
}
}
}
})

return nil
}

Expand Down
60 changes: 60 additions & 0 deletions go/test/endtoend/cluster/vttablet_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"net/http"
"os"
"os/exec"
Expand All @@ -35,6 +36,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/constants/sidecar"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
Expand Down Expand Up @@ -711,6 +714,63 @@ func (vttablet *VttabletProcess) IsShutdown() bool {
return vttablet.proc == nil
}

// ConfirmDataDirHasNoGlobalPerms confirms that no files in the tablet's data directory
// have any global/world/other permissions enabled.
func (vttablet *VttabletProcess) ConfirmDataDirHasNoGlobalPerms(t *testing.T) {
datadir := vttablet.Directory
if _, err := os.Stat(datadir); errors.Is(err, os.ErrNotExist) {
t.Logf("Data directory %s no longer exists, skipping permissions check", datadir)
return
}

var allowedFiles = []string{
// These are intentionally created with the world/other read bit set by mysqld itself
// during the --initialize[-insecure] step.
// See: https://dev.mysql.com/doc/mysql-security-excerpt/en/creating-ssl-rsa-files-using-mysql.html
// "On Unix and Unix-like systems, the file access mode is 644 for certificate files
// (that is, world readable) and 600 for key files (that is, accessible only by the
// account that runs the server)."
path.Join("data", "ca.pem"),
path.Join("data", "client-cert.pem"),
path.Join("data", "public_key.pem"),
path.Join("data", "server-cert.pem"),
// The domain socket must have global perms for anyone to use it.
"mysql.sock",
// These files are created by xtrabackup.
path.Join("tmp", "xtrabackup_checkpoints"),
path.Join("tmp", "xtrabackup_info"),
}

var matches []string
fsys := os.DirFS(datadir)
err := fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, _ error) error {
// first check if the file should be skipped
for _, name := range allowedFiles {
if strings.HasSuffix(p, name) {
return nil
}
}

info, err := d.Info()
if err != nil {
return err
}

// check if any global bit is on the filemode
if info.Mode()&0007 != 0 {
matches = append(matches, fmt.Sprintf(
"%s (%s)",
path.Join(datadir, p),
info.Mode(),
))
}
return nil
})

require.NoError(t, err, "Error walking directory")
require.Empty(t, matches, "Found files with global permissions: %s\n", strings.Join(matches, "\n"))
}

// VttabletProcessInstance returns a VttabletProcess handle for vttablet process
// configured with the given Config.
// The process must be manually started by calling setup()
Expand Down
4 changes: 1 addition & 3 deletions go/test/endtoend/vreplication/vdiff_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ func getVDiffInfo(json string) *vdiffInfo {
}

func encodeString(in string) string {
var buf strings.Builder
sqltypes.NewVarChar(in).EncodeSQL(&buf)
return buf.String()
return sqltypes.EncodeStringSQL(in)
}

// generateMoreCustomers creates additional test data for better tests
Expand Down
22 changes: 10 additions & 12 deletions go/vt/binlog/binlogplayer/binlog_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (blp *BinlogPlayer) setVReplicationState(state binlogdatapb.VReplicationWor
})
}
blp.blplStats.State.Store(state.String())
query := fmt.Sprintf("update _vt.vreplication set state='%v', message=%v where id=%v", state.String(), encodeString(MessageTruncate(message)), blp.uid)
query := fmt.Sprintf("update _vt.vreplication set state=%v, message=%v where id=%v", encodeString(state.String()), encodeString(MessageTruncate(message)), blp.uid)
if _, err := blp.dbClient.ExecuteFetch(query, 1); err != nil {
return fmt.Errorf("could not set state: %v: %v", query, err)
}
Expand Down Expand Up @@ -637,9 +637,9 @@ func CreateVReplication(workflow string, source *binlogdatapb.BinlogSource, posi
protoutil.SortBinlogSourceTables(source)
return fmt.Sprintf("insert into _vt.vreplication "+
"(workflow, source, pos, max_tps, max_replication_lag, time_updated, transaction_timestamp, state, db_name, workflow_type, workflow_sub_type, defer_secondary_keys, options) "+
"values (%v, %v, %v, %v, %v, %v, 0, '%v', %v, %d, %d, %v, %s)",
"values (%v, %v, %v, %v, %v, %v, 0, %v, %v, %d, %d, %v, %s)",
encodeString(workflow), encodeString(source.String()), encodeString(position), maxTPS, maxReplicationLag,
timeUpdated, binlogdatapb.VReplicationWorkflowState_Running.String(), encodeString(dbName), workflowType,
timeUpdated, encodeString(binlogdatapb.VReplicationWorkflowState_Running.String()), encodeString(dbName), workflowType,
workflowSubType, deferSecondaryKeys, encodeString("{}"))
}

Expand All @@ -649,9 +649,9 @@ func CreateVReplicationState(workflow string, source *binlogdatapb.BinlogSource,
protoutil.SortBinlogSourceTables(source)
return fmt.Sprintf("insert into _vt.vreplication "+
"(workflow, source, pos, max_tps, max_replication_lag, time_updated, transaction_timestamp, state, db_name, workflow_type, workflow_sub_type, options) "+
"values (%v, %v, %v, %v, %v, %v, 0, '%v', %v, %d, %d, %s)",
"values (%v, %v, %v, %v, %v, %v, 0, %v, %v, %d, %d, %s)",
encodeString(workflow), encodeString(source.String()), encodeString(position), throttler.MaxRateModuleDisabled,
throttler.ReplicationLagModuleDisabled, time.Now().Unix(), state.String(), encodeString(dbName),
throttler.ReplicationLagModuleDisabled, time.Now().Unix(), encodeString(state.String()), encodeString(dbName),
workflowType, workflowSubType, encodeString("{}"))
}

Expand Down Expand Up @@ -694,15 +694,15 @@ func GenerateUpdateTimeThrottled(uid int32, timeThrottledUnix int64, componentTh
// StartVReplicationUntil returns a statement to start the replication with a stop position.
func StartVReplicationUntil(uid int32, pos string) string {
return fmt.Sprintf(
"update _vt.vreplication set state='%v', stop_pos=%v where id=%v",
binlogdatapb.VReplicationWorkflowState_Running.String(), encodeString(pos), uid)
"update _vt.vreplication set state=%v, stop_pos=%v where id=%v",
encodeString(binlogdatapb.VReplicationWorkflowState_Running.String()), encodeString(pos), uid)
}

// StopVReplication returns a statement to stop the replication.
func StopVReplication(uid int32, message string) string {
return fmt.Sprintf(
"update _vt.vreplication set state='%v', message=%v where id=%v",
binlogdatapb.VReplicationWorkflowState_Stopped.String(), encodeString(MessageTruncate(message)), uid)
"update _vt.vreplication set state=%v, message=%v where id=%v",
encodeString(binlogdatapb.VReplicationWorkflowState_Stopped.String()), encodeString(MessageTruncate(message)), uid)
}

// DeleteVReplication returns a statement to delete the replication.
Expand All @@ -717,9 +717,7 @@ func MessageTruncate(msg string) string {
}

func encodeString(in string) string {
buf := bytes.NewBuffer(nil)
sqltypes.NewVarChar(in).EncodeSQL(buf)
return buf.String()
return sqltypes.EncodeStringSQL(in)
}

// ReadVReplicationPos returns a statement to query the gtid for a
Expand Down
3 changes: 2 additions & 1 deletion go/vt/discovery/keyspace_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func (kss *keyspaceState) ensureConsistentLocked() {
// watcher. this means the ongoing availability event has been resolved, so we can broadcast
// a resolution event to all listeners
kss.consistent = true
log.Infof("keyspace %s is now consistent", kss.keyspace)

kss.moveTablesState = nil

Expand All @@ -328,7 +329,7 @@ func (kss *keyspaceState) ensureConsistentLocked() {
Serving: sstate.serving,
})

log.Infof("keyspace event resolved: %s is now consistent (serving: %t)",
log.V(2).Infof("keyspace event resolved: %s is now consistent (serving: %t)",
topoproto.KeyspaceShardString(sstate.target.Keyspace, sstate.target.Shard),
sstate.serving,
)
Expand Down
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/backupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/os2"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
Expand Down Expand Up @@ -723,7 +724,7 @@ func createStateFile(cnf *Mycnf) error {
// rename func to openStateFile
// change to return a *File
fname := filepath.Join(cnf.TabletDir(), RestoreState)
fd, err := os.Create(fname)
fd, err := os2.Create(fname)
if err != nil {
return fmt.Errorf("unable to create file: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/blackbox/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/capabilities"
"vitess.io/vitess/go/os2"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl"
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
Expand Down Expand Up @@ -182,7 +183,7 @@ func createBackupDir(root string, dirs ...string) error {

func createBackupFiles(root string, fileCount int, ext string) error {
for i := 0; i < fileCount; i++ {
f, err := os.Create(path.Join(root, fmt.Sprintf("%d.%s", i, ext)))
f, err := os2.Create(path.Join(root, fmt.Sprintf("%d.%s", i, ext)))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit cdd2a0a

Please sign in to comment.