You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
[chore] Add gosec via golangci-lint (#4645)
This commit is contained in:
@@ -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
|
- godot
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goimports
|
- goimports
|
||||||
|
- gosec
|
||||||
- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
@@ -53,6 +54,20 @@ issues:
|
|||||||
text: "calls to (.+) only in main[(][)] or init[(][)] functions"
|
text: "calls to (.+) only in main[(][)] or init[(][)] functions"
|
||||||
linters:
|
linters:
|
||||||
- revive
|
- 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:
|
include:
|
||||||
# revive exported should have comment or be unexported.
|
# revive exported should have comment or be unexported.
|
||||||
- EXC0012
|
- EXC0012
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func main() {
|
|||||||
func serveMetrics() {
|
func serveMetrics() {
|
||||||
log.Printf("serving metrics at localhost:2223/metrics")
|
log.Printf("serving metrics at localhost:2223/metrics")
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
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 {
|
if err != nil {
|
||||||
fmt.Printf("error serving http: %v", err)
|
fmt.Printf("error serving http: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func main() {
|
|||||||
func serveMetrics() {
|
func serveMetrics() {
|
||||||
log.Printf("serving metrics at localhost:2222/metrics")
|
log.Printf("serving metrics at localhost:2222/metrics")
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
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 {
|
if err != nil {
|
||||||
fmt.Printf("error serving http: %v", err)
|
fmt.Printf("error serving http: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle
|
|||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle(u.Path, http.HandlerFunc(c.handler))
|
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" {
|
if u.Scheme == "https" {
|
||||||
cert, err := weakCertificate()
|
cert, err := weakCertificate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle
|
|||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle(u.Path, http.HandlerFunc(c.handler))
|
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" {
|
if u.Scheme == "https" {
|
||||||
cert, err := weakCertificate()
|
cert, err := weakCertificate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -241,7 +242,9 @@ func runMockCollector(t *testing.T, cfg mockCollectorConfig) *mockCollector {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle(cfg.TracesURLPath, http.HandlerFunc(m.serveTraces))
|
mux.Handle(cfg.TracesURLPath, http.HandlerFunc(m.serveTraces))
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
|
ReadTimeout: 10 * time.Second,
|
||||||
|
WriteTimeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
if cfg.WithTLS {
|
if cfg.WithTLS {
|
||||||
pem, err := generateWeakCertificate()
|
pem, err := generateWeakCertificate()
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ func startMockZipkinCollector(t *testing.T) *mockZipkinCollector {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
collector.url = fmt.Sprintf("http://%s", listener.Addr().String())
|
collector.url = fmt.Sprintf("http://%s", listener.Addr().String())
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Handler: http.HandlerFunc(collector.handler),
|
Handler: http.HandlerFunc(collector.handler),
|
||||||
|
ReadTimeout: 10 * time.Second,
|
||||||
|
WriteTimeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
collector.server = server
|
collector.server = server
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
|
|||||||
@@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle
|
|||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle(u.Path, http.HandlerFunc(c.handler))
|
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" {
|
if u.Scheme == "https" {
|
||||||
cert, err := weakCertificate()
|
cert, err := weakCertificate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// resourceAttrKey is the environment variable name OpenTelemetry Resource information will be read from.
|
// 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 is the environment variable name that Service Name information will be read from.
|
||||||
svcNameKey = "OTEL_SERVICE_NAME"
|
svcNameKey = "OTEL_SERVICE_NAME"
|
||||||
|
|||||||
Reference in New Issue
Block a user