Skip to content

Commit a7ab5a5

Browse files
version: update version check to use safe introspection tool
Previously, we would query `crdb_internal.node_build_info` table to get a cluster's version info. Starting at 26.1, we'll be blocking access to crdb_internal tables, as they're considered part of the "unsafe internals". To mitigate this issue before release, we'll use instead `SHOW crdb_version` to collect version information about the cluster. Fixes: #154660 Release note: none
1 parent 876b2d5 commit a7ab5a5

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v3
2020
with:
21-
go-version: 1.17
21+
go-version: 1.24
2222
- name: golangci-lint
2323
uses: golangci/golangci-lint-action@v3
2424
with:
2525
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
26-
version: v1.46.2
26+
version: latest

testing/main_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ func startServerWithApplication(
112112
func getVersionFromDB(t *testing.T, db *sql.DB) *version.Version {
113113
t.Helper()
114114
var crdbVersion string
115-
if err := db.QueryRow(
116-
`SELECT value FROM crdb_internal.node_build_info where field = 'Version'`,
117-
).Scan(&crdbVersion); err != nil {
115+
if err := db.QueryRow("SHOW crdb_version").Scan(&crdbVersion); err != nil {
118116
t.Fatal(err)
119117
}
120118
v, err := version.Parse(crdbVersion)

version/version.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,23 @@ func (v Version) String() string {
7373
// of the form "vMAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]". This
7474
// conforms to https://semver.org/spec/v2.0.0.html
7575
var versionRE = regexp.MustCompile(
76-
`^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-.]+)?(\+[0-9A-Za-z-.]+|)?$`,
76+
`v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-.]+)?(\+[0-9A-Za-z-.]+|)?`,
7777
// ^major ^minor ^patch ^preRelease ^metadata
7878
)
7979

8080
// numericRE is the regexp used to check if an identifier is numeric.
8181
var numericRE = regexp.MustCompile(`^(0|[1-9][0-9]*)$`)
8282

83-
// Parse creates a version from a string. The string must be a valid semantic
83+
// Parse creates a version from a string. The string must contain a valid semantic
8484
// version (as per https://semver.org/spec/v2.0.0.html) in the format:
8585
// "vMINOR.MAJOR.PATCH[-PRERELEASE][+METADATA]".
8686
// MINOR, MAJOR, and PATCH are numeric values (without any leading 0s).
8787
// PRERELEASE and METADATA can contain ASCII characters and digits, hyphens and
8888
// dots.
89-
func Parse(str string) (*Version, error) {
90-
if !versionRE.MatchString(str) {
91-
return nil, errors.Errorf("invalid version string '%s'", str)
89+
func Parse(fullStr string) (*Version, error) {
90+
var str string
91+
if str = versionRE.FindString(fullStr); len(str) == 0 {
92+
return nil, errors.Errorf("invalid version string '%s'", fullStr)
9293
}
9394

9495
var v Version

0 commit comments

Comments
 (0)