Skip to content

Commit

Permalink
Backport of security: update go version to 1.20.4 into release/1.13.x (
Browse files Browse the repository at this point in the history
…#17243)

* no-op commit due to failed cherry-picking

* security: update go version to 1.20.4 (#17240)

* update go version to 1.20.3

* add changelog

* rename changelog file to remove underscore

* update to use 1.20.4

* update change log entry to reflect 1.20.4

* upgrading to 1.20

* [OSS] security: update go to 1.20.1 (#16263)

* security: update go to 1.20.1

* fixing auto_config_endpoint_test that was merged incorrectly

* go mod tidy

* fixing auto_config_endpoint_test that was merged incorrectly

* updating linter to 1.51.1

* go mod tidy on api

* go mod tidy

* removes ioutil usage everywhere which was deprecated in go1.16 (#15297)

* update go version to 1.18 for api and sdk, go mod tidy
* removes ioutil usage everywhere which was deprecated in go1.16 in favour of io and os packages. Also introduces a lint rule which forbids use of ioutil going forward.
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* go mod tidy

* getting rd of net in imports

* get rid of use of math.rand

* get rid of use of math/rand in audo_config_endpoint_test.go

* update leader test

---------

Co-authored-by: temp <temp@hashicorp.com>
Co-authored-by: John Murret <john.murret@hashicorp.com>
Co-authored-by: Dan Stough <dan.stough@hashicorp.com>
Co-authored-by: Kyle Schochenmaier <kschoche@gmail.com>
  • Loading branch information
5 people committed May 9, 2023
1 parent 6718324 commit f4b321c
Show file tree
Hide file tree
Showing 124 changed files with 418 additions and 486 deletions.
7 changes: 7 additions & 0 deletions .changelog/15297.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:improvement
api: updated the go module directive to 1.18.
```

```release-note:improvement
sdk: updated the go module directive to 1.18.
```
4 changes: 4 additions & 0 deletions .changelog/16263.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:security
Upgrade to use Go 1.20.1.
This resolves vulnerabilities [CVE-2022-41724](https://go.dev/issue/58001) in `crypto/tls` and [CVE-2022-41723](https://go.dev/issue/57855) in `net/http`.
```
12 changes: 12 additions & 0 deletions .changelog/17240.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```release-note:security
Upgrade to use Go 1.20.4.
This resolves vulnerabilities [CVE-2023-24537](https://github.com/advisories/GHSA-9f7g-gqwh-jpf5)(`go/scanner`),
[CVE-2023-24538](https://github.com/advisories/GHSA-v4m2-x4rp-hv22)(`html/template`),
[CVE-2023-24534](https://github.com/advisories/GHSA-8v5j-pwr7-w5f8)(`net/textproto`) and
[CVE-2023-24536](https://github.com/advisories/GHSA-9f7g-gqwh-jpf5)(`mime/multipart`).
Also, `golang.org/x/net` has been updated to v0.7.0 to resolve CVEs [CVE-2022-41721
](https://github.com/advisories/GHSA-fxg5-wq6x-vr4w
), [CVE-2022-27664](https://github.com/advisories/GHSA-69cg-p879-7622) and [CVE-2022-41723
](https://github.com/advisories/GHSA-vvpx-j8f3-3w6h
.)
```
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ jobs:
strategy:
matrix:
include:
- {go: "1.19.6", goos: "linux", goarch: "386"}
- {go: "1.19.6", goos: "linux", goarch: "amd64"}
- {go: "1.19.6", goos: "linux", goarch: "arm"}
- {go: "1.19.6", goos: "linux", goarch: "arm64"}
- {go: "1.19.6", goos: "freebsd", goarch: "386"}
- {go: "1.19.6", goos: "freebsd", goarch: "amd64"}
- {go: "1.19.6", goos: "windows", goarch: "386"}
- {go: "1.19.6", goos: "windows", goarch: "amd64"}
- {go: "1.19.6", goos: "solaris", goarch: "amd64"}
- {go: "1.20.4", goos: "linux", goarch: "386"}
- {go: "1.20.4", goos: "linux", goarch: "amd64"}
- {go: "1.20.4", goos: "linux", goarch: "arm"}
- {go: "1.20.4", goos: "linux", goarch: "arm64"}
- {go: "1.20.4", goos: "freebsd", goarch: "386"}
- {go: "1.20.4", goos: "freebsd", goarch: "amd64"}
- {go: "1.20.4", goos: "windows", goarch: "386"}
- {go: "1.20.4", goos: "windows", goarch: "amd64"}
- {go: "1.20.4", goos: "solaris", goarch: "amd64"}
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
matrix:
goos: [ darwin ]
goarch: [ "amd64", "arm64" ]
go: [ "1.19.6" ]
go: [ "1.20.4" ]
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # pin@v3.4.0
with:
working-directory: ${{ matrix.directory }}
version: v1.50.1
version: v1.51.1
args: --build-tags="${{ env.GOTAGS }}" -v
- name: Notify Slack
if: ${{ failure() }}
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ linters-settings:
forbidigo:
# Forbid the following identifiers (list of regexp).
forbid:
- '\bioutil\b(# Use io and os packages instead of ioutil)?'
- '\brequire\.New\b(# Use package-level functions with explicit TestingT)?'
- '\bassert\.New\b(# Use package-level functions with explicit TestingT)?'
# Exclude godoc examples from forbidigo checks.
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ SHELL = bash
# These version variables can either be a valid string for "go install <module>@<version>"
# or the string @DEV to imply use what is currently installed locally.
###
GOLANGCI_LINT_VERSION='v1.50.1'
MOCKERY_VERSION='v2.12.2'
GOLANGCI_LINT_VERSION='v1.51.1'
MOCKERY_VERSION='v2.20.0'
BUF_VERSION='v1.4.0'
PROTOC_GEN_GO_GRPC_VERSION="v1.2.0"
MOG_VERSION='v0.3.0'
MOG_VERSION='v0.4.0'
PROTOC_GO_INJECT_TAG_VERSION='v1.3.0'
PROTOC_GEN_GO_BINARY_VERSION="v0.0.1"
DEEP_COPY_VERSION='bc3f5aa5735d8a54961580a3a24422c308c831c2'
Expand Down
19 changes: 9 additions & 10 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -2021,7 +2020,7 @@ func (a *Agent) readPersistedServiceConfigs() (map[structs.ServiceID]*structs.Se
out := make(map[structs.ServiceID]*structs.ServiceConfigResponse)

configDir := filepath.Join(a.config.DataDir, serviceConfigDir)
files, err := ioutil.ReadDir(configDir)
files, err := os.ReadDir(configDir)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
Expand All @@ -2043,7 +2042,7 @@ func (a *Agent) readPersistedServiceConfigs() (map[structs.ServiceID]*structs.Se

// Read the contents into a buffer
file := filepath.Join(configDir, fi.Name())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("failed reading service config file %q: %w", file, err)
}
Expand Down Expand Up @@ -3223,7 +3222,7 @@ func (a *Agent) persistCheckState(check *checks.CheckTTL, status, output string)
tempFile := file + ".tmp"

// persistCheckState is called frequently, so don't use writeFileAtomic to avoid calling fsync here
if err := ioutil.WriteFile(tempFile, buf, 0600); err != nil {
if err := os.WriteFile(tempFile, buf, 0600); err != nil {
return fmt.Errorf("failed writing temp file %q: %s", tempFile, err)
}
if err := os.Rename(tempFile, file); err != nil {
Expand All @@ -3238,12 +3237,12 @@ func (a *Agent) loadCheckState(check *structs.HealthCheck) error {
cid := check.CompoundCheckID()
// Try to read the persisted state for this check
file := filepath.Join(a.config.DataDir, checkStateDir, cid.StringHashSHA256())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
// try the md5 based name. This can be removed once we no longer support upgrades from versions that use MD5 hashing
oldFile := filepath.Join(a.config.DataDir, checkStateDir, cid.StringHashMD5())
buf, err = ioutil.ReadFile(oldFile)
buf, err = os.ReadFile(oldFile)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand Down Expand Up @@ -3450,7 +3449,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig, snap map[structs.CheckI

// Load any persisted services
svcDir := filepath.Join(a.config.DataDir, servicesDir)
files, err := ioutil.ReadDir(svcDir)
files, err := os.ReadDir(svcDir)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand All @@ -3471,7 +3470,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig, snap map[structs.CheckI

// Read the contents into a buffer
file := filepath.Join(svcDir, fi.Name())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("failed reading service file %q: %w", file, err)
}
Expand Down Expand Up @@ -3618,7 +3617,7 @@ func (a *Agent) loadChecks(conf *config.RuntimeConfig, snap map[structs.CheckID]

// Load any persisted checks
checkDir := filepath.Join(a.config.DataDir, checksDir)
files, err := ioutil.ReadDir(checkDir)
files, err := os.ReadDir(checkDir)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand All @@ -3633,7 +3632,7 @@ func (a *Agent) loadChecks(conf *config.RuntimeConfig, snap map[structs.CheckID]

// Read the contents into a buffer
file := filepath.Join(checkDir, fi.Name())
buf, err := ioutil.ReadFile(file)
buf, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("failed reading check file %q: %w", file, err)
}
Expand Down
5 changes: 2 additions & 3 deletions agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -1741,7 +1740,7 @@ func TestAgent_ReloadDoesNotTriggerWatch(t *testing.T) {
}

dc1 := "dc1"
tmpFileRaw, err := ioutil.TempFile("", "rexec")
tmpFileRaw, err := os.CreateTemp("", "rexec")
require.NoError(t, err)
tmpFile := tmpFileRaw.Name()
defer os.Remove(tmpFile)
Expand Down Expand Up @@ -1780,7 +1779,7 @@ func TestAgent_ReloadDoesNotTriggerWatch(t *testing.T) {
contentsStr := ""
// Wait for watch to be populated
for i := 1; i < 7; i++ {
contents, err := ioutil.ReadFile(tmpFile)
contents, err := os.ReadFile(tmpFile)
if err != nil {
t.Fatalf("should be able to read file, but had: %#v", err)
}
Expand Down
Loading

0 comments on commit f4b321c

Please sign in to comment.