You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	[chore] Add gosec via golangci-lint (#4645)
This commit is contained in:
		
							
								
								
									
										27
									
								
								.github/workflows/gosec.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										27
									
								
								.github/workflows/gosec.yml
									
									
									
									
										vendored
									
									
								
							| @@ -1,27 +0,0 @@ | ||||
| name: Run Gosec | ||||
| on: | ||||
|   workflow_dispatch: | ||||
|   schedule: | ||||
|     #        ┌───────────── minute (0 - 59) | ||||
|     #        │  ┌───────────── hour (0 - 23) | ||||
|     #        │  │ ┌───────────── day of the month (1 - 31) | ||||
|     #        │  │ │ ┌───────────── month (1 - 12 or JAN-DEC) | ||||
|     #        │  │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) | ||||
|     #        │  │ │ │ │ | ||||
|     #        │  │ │ │ │ | ||||
|     #        │  │ │ │ │ | ||||
|     #        *  * * * * | ||||
|     - cron: '30 2 * * *' | ||||
| jobs: | ||||
|   tests: | ||||
|     runs-on: ubuntu-latest | ||||
|     env: | ||||
|       GO111MODULE: on | ||||
|     steps: | ||||
|       - name: Checkout Source | ||||
|         uses: actions/checkout@v4 | ||||
|       - name: Run Gosec Security Scanner | ||||
|         uses: securego/gosec@master | ||||
|         with: | ||||
|           args: ./... | ||||
|  | ||||
| @@ -14,6 +14,7 @@ linters: | ||||
|     - godot | ||||
|     - gofumpt | ||||
|     - goimports | ||||
|     - gosec | ||||
|     - gosimple | ||||
|     - govet | ||||
|     - ineffassign | ||||
| @@ -53,6 +54,20 @@ issues: | ||||
|       text: "calls to (.+) only in main[(][)] or init[(][)] functions" | ||||
|       linters: | ||||
|         - revive | ||||
|     # It's okay to not run gosec in a test. | ||||
|     - path: _test\.go | ||||
|       linters: | ||||
|         - gosec | ||||
|     # Igonoring gosec G404: Use of weak random number generator (math/rand instead of crypto/rand) | ||||
|     # as we commonly use it in tests and examples. | ||||
|     - text: "G404:" | ||||
|       linters: | ||||
|         - gosec | ||||
|     # Igonoring gosec G402: TLS MinVersion too low | ||||
|     # as the https://pkg.go.dev/crypto/tls#Config handles MinVersion default well. | ||||
|     - text: "G402: TLS MinVersion too low." | ||||
|       linters: | ||||
|         - gosec | ||||
|   include: | ||||
|     # revive exported should have comment or be unexported. | ||||
|     - EXC0012 | ||||
|   | ||||
| @@ -91,7 +91,7 @@ func main() { | ||||
| func serveMetrics() { | ||||
| 	log.Printf("serving metrics at localhost:2223/metrics") | ||||
| 	http.Handle("/metrics", promhttp.Handler()) | ||||
| 	err := http.ListenAndServe(":2223", nil) | ||||
| 	err := http.ListenAndServe(":2223", nil) //nolint:gosec // Ignoring G114: Use of net/http serve function that has no support for setting timeouts. | ||||
| 	if err != nil { | ||||
| 		fmt.Printf("error serving http: %v", err) | ||||
| 		return | ||||
|   | ||||
| @@ -90,7 +90,7 @@ func main() { | ||||
| func serveMetrics() { | ||||
| 	log.Printf("serving metrics at localhost:2222/metrics") | ||||
| 	http.Handle("/metrics", promhttp.Handler()) | ||||
| 	err := http.ListenAndServe(":2222", nil) | ||||
| 	err := http.ListenAndServe(":2222", nil) //nolint:gosec // Ignoring G114: Use of net/http serve function that has no support for setting timeouts. | ||||
| 	if err != nil { | ||||
| 		fmt.Printf("error serving http: %v", err) | ||||
| 		return | ||||
|   | ||||
| @@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle | ||||
|  | ||||
| 	mux := http.NewServeMux() | ||||
| 	mux.Handle(u.Path, http.HandlerFunc(c.handler)) | ||||
| 	c.srv = &http.Server{Handler: mux} | ||||
| 	c.srv = &http.Server{ | ||||
| 		Handler:      mux, | ||||
| 		ReadTimeout:  10 * time.Second, | ||||
| 		WriteTimeout: 10 * time.Second, | ||||
| 	} | ||||
| 	if u.Scheme == "https" { | ||||
| 		cert, err := weakCertificate() | ||||
| 		if err != nil { | ||||
|   | ||||
| @@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle | ||||
|  | ||||
| 	mux := http.NewServeMux() | ||||
| 	mux.Handle(u.Path, http.HandlerFunc(c.handler)) | ||||
| 	c.srv = &http.Server{Handler: mux} | ||||
| 	c.srv = &http.Server{ | ||||
| 		Handler:      mux, | ||||
| 		ReadTimeout:  10 * time.Second, | ||||
| 		WriteTimeout: 10 * time.Second, | ||||
| 	} | ||||
| 	if u.Scheme == "https" { | ||||
| 		cert, err := weakCertificate() | ||||
| 		if err != nil { | ||||
|   | ||||
| @@ -25,6 +25,7 @@ import ( | ||||
| 	"net/http" | ||||
| 	"sync" | ||||
| 	"testing" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| @@ -241,7 +242,9 @@ func runMockCollector(t *testing.T, cfg mockCollectorConfig) *mockCollector { | ||||
| 	mux := http.NewServeMux() | ||||
| 	mux.Handle(cfg.TracesURLPath, http.HandlerFunc(m.serveTraces)) | ||||
| 	server := &http.Server{ | ||||
| 		Handler: mux, | ||||
| 		Handler:      mux, | ||||
| 		ReadTimeout:  10 * time.Second, | ||||
| 		WriteTimeout: 10 * time.Second, | ||||
| 	} | ||||
| 	if cfg.WithTLS { | ||||
| 		pem, err := generateWeakCertificate() | ||||
|   | ||||
| @@ -120,7 +120,9 @@ func startMockZipkinCollector(t *testing.T) *mockZipkinCollector { | ||||
| 	require.NoError(t, err) | ||||
| 	collector.url = fmt.Sprintf("http://%s", listener.Addr().String()) | ||||
| 	server := &http.Server{ | ||||
| 		Handler: http.HandlerFunc(collector.handler), | ||||
| 		Handler:      http.HandlerFunc(collector.handler), | ||||
| 		ReadTimeout:  10 * time.Second, | ||||
| 		WriteTimeout: 10 * time.Second, | ||||
| 	} | ||||
| 	collector.server = server | ||||
| 	wg := &sync.WaitGroup{} | ||||
|   | ||||
| @@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle | ||||
|  | ||||
| 	mux := http.NewServeMux() | ||||
| 	mux.Handle(u.Path, http.HandlerFunc(c.handler)) | ||||
| 	c.srv = &http.Server{Handler: mux} | ||||
| 	c.srv = &http.Server{ | ||||
| 		Handler:      mux, | ||||
| 		ReadTimeout:  10 * time.Second, | ||||
| 		WriteTimeout: 10 * time.Second, | ||||
| 	} | ||||
| 	if u.Scheme == "https" { | ||||
| 		cert, err := weakCertificate() | ||||
| 		if err != nil { | ||||
|   | ||||
| @@ -28,7 +28,7 @@ import ( | ||||
|  | ||||
| const ( | ||||
| 	// resourceAttrKey is the environment variable name OpenTelemetry Resource information will be read from. | ||||
| 	resourceAttrKey = "OTEL_RESOURCE_ATTRIBUTES" | ||||
| 	resourceAttrKey = "OTEL_RESOURCE_ATTRIBUTES" //nolint:gosec // False positive G101: Potential hardcoded credentials | ||||
|  | ||||
| 	// svcNameKey is the environment variable name that Service Name information will be read from. | ||||
| 	svcNameKey = "OTEL_SERVICE_NAME" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user