mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-19 06:01:48 +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/structpb"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
@ -371,7 +372,8 @@ func NewAuditLogEntry(
|
||||||
func GetCalledServiceNameFromRequest(request *Request, fallbackName string) string {
|
func GetCalledServiceNameFromRequest(request *Request, fallbackName string) string {
|
||||||
var calledServiceName = fallbackName
|
var calledServiceName = fallbackName
|
||||||
host := request.Host
|
host := request.Host
|
||||||
if !strings.Contains(host, "localhost") {
|
ip := net.ParseIP(host)
|
||||||
|
if ip == nil && !strings.Contains(host, "localhost") {
|
||||||
dotIdx := strings.Index(host, ".")
|
dotIdx := strings.Index(host, ".")
|
||||||
if dotIdx != -1 {
|
if dotIdx != -1 {
|
||||||
calledServiceName = host[0:dotIdx]
|
calledServiceName = host[0:dotIdx]
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,22 @@ func Test_GetCalledServiceNameFromRequest(t *testing.T) {
|
||||||
serviceName := GetCalledServiceNameFromRequest(&request, "resource-manager")
|
serviceName := GetCalledServiceNameFromRequest(&request, "resource-manager")
|
||||||
assert.Equal(t, "resource-manager", serviceName)
|
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) {
|
func Test_NewPbInt64Value(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue