mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-08 00:57:24 +00:00
Filter out ip adresses in service name detection
This commit is contained in:
parent
be23f50c5a
commit
fc895948bb
2 changed files with 19 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
|
|
@ -371,7 +372,8 @@ func NewAuditLogEntry(
|
|||
func GetCalledServiceNameFromRequest(request *Request, fallbackName string) string {
|
||||
var calledServiceName = fallbackName
|
||||
host := request.Host
|
||||
if !strings.Contains(host, "localhost") {
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil && !strings.Contains(host, "localhost") {
|
||||
dotIdx := strings.Index(host, ".")
|
||||
if dotIdx != -1 {
|
||||
calledServiceName = host[0:dotIdx]
|
||||
|
|
|
|||
|
|
@ -86,6 +86,22 @@ func Test_GetCalledServiceNameFromRequest(t *testing.T) {
|
|||
serviceName := GetCalledServiceNameFromRequest(&request, "resource-manager")
|
||||
assert.Equal(t, "resource-manager", serviceName)
|
||||
})
|
||||
|
||||
t.Run(
|
||||
"ip", func(t *testing.T) {
|
||||
request := Request{Host: "127.0.0.1"}
|
||||
serviceName := GetCalledServiceNameFromRequest(&request, "resource-manager")
|
||||
assert.Equal(t, "resource-manager", serviceName)
|
||||
},
|
||||
)
|
||||
|
||||
t.Run(
|
||||
"ip short", func(t *testing.T) {
|
||||
request := Request{Host: "::1"}
|
||||
serviceName := GetCalledServiceNameFromRequest(&request, "resource-manager")
|
||||
assert.Equal(t, "resource-manager", serviceName)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func Test_NewPbInt64Value(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue