Skip to content

Commit c3c8e64

Browse files
author
Manish Ranjan Mahanta
committed
Making the default sources and map in native go, remvoing unreferenced methods and addressing review comments
Signed-off-by: Manish Ranjan Mahanta <mmahanta@microsoft.com>
1 parent 2eac7bb commit c3c8e64

9 files changed

Lines changed: 1704 additions & 5015 deletions

File tree

internal/gcs-sidecar/handlers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func (b *Bridge) modifyServiceSettings(req *request) (err error) {
530530
settings.Settings = allowedLogSources
531531
}
532532
default:
533-
log.G(req.ctx).Tracef("modifyServiceSettings for LogForwardService with RPCType: %v, skipping policy enforcement", settings.RPCType)
533+
log.G(req.ctx).Warningf("modifyServiceSettings for LogForwardService with RPCType: %v, skipping policy enforcement", settings.RPCType)
534534
}
535535
modifyRequest.Settings = settings
536536
buf, err := json.Marshal(modifyRequest)
@@ -544,10 +544,10 @@ func (b *Bridge) modifyServiceSettings(req *request) (err error) {
544544
newRequest.message = buf
545545
req = &newRequest
546546
} else {
547-
log.G(req.ctx).Tracef("modifyServiceSettings for LogForwardService with empty settings, skipping policy enforcement")
547+
log.G(req.ctx).Warningf("modifyServiceSettings for LogForwardService with empty settings, skipping policy enforcement")
548548
}
549549
default:
550-
log.G(req.ctx).Tracef("modifyServiceSettings with PropertyType: %v, skipping policy enforcement", modifyRequest.PropertyType)
550+
log.G(req.ctx).Warningf("modifyServiceSettings with PropertyType: %v, skipping policy enforcement", modifyRequest.PropertyType)
551551
}
552552
b.forwardRequestToGcs(req)
553553
return nil

internal/vm/vmutils/etw/default-logsources.json

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package etw
2+
3+
// defaultLogSourcesInfo is the native Go representation of the default-logsources.json file.
4+
var defaultLogSourcesInfo = LogSourcesInfo{
5+
LogConfig: LogConfig{
6+
Sources: []Source{
7+
{
8+
Type: "ETW",
9+
Providers: []EtwProvider{
10+
{
11+
ProviderName: "microsoft.windows.hyperv.compute",
12+
Level: "Information",
13+
},
14+
{
15+
ProviderName: "microsoft-windows-guest-network-service",
16+
Level: "Information",
17+
},
18+
{
19+
ProviderName: "microsoft.windows.filesystem.cimfs",
20+
Level: "Information",
21+
},
22+
{
23+
ProviderName: "microsoft.windows.filesystem.unionfs",
24+
Level: "Information",
25+
},
26+
{
27+
ProviderName: "microsoft-windows-bitlocker-driver",
28+
Level: "Information",
29+
},
30+
{
31+
ProviderName: "microsoft-windows-bitlocker-api",
32+
Level: "Information",
33+
},
34+
{
35+
ProviderName: "microsoft.windows.security.keyguard",
36+
Level: "Information",
37+
},
38+
{
39+
ProviderName: "microsoft.windows.security.keyguard.attestation.verify",
40+
Level: "Information",
41+
},
42+
{
43+
ProviderName: "microsoft.windows.containers.setup",
44+
Level: "Information",
45+
},
46+
{
47+
ProviderName: "microsoft.windows.containers.storage",
48+
Level: "Information",
49+
},
50+
{
51+
ProviderName: "microsoft.windows.containers.library",
52+
Level: "Information",
53+
},
54+
{
55+
ProviderName: "microsoft.windows.containers.dynamicimage",
56+
Level: "Information",
57+
},
58+
{
59+
ProviderName: "microsoft.windows.logforwardservice.provider",
60+
Level: "Information",
61+
},
62+
},
63+
},
64+
},
65+
},
66+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package etw
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestDefaultSources_ETWProvidersExistInETWMap(t *testing.T) {
9+
if len(etwNameToGuidMap) == 0 {
10+
t.Fatal("etwNameToGuidMap is empty")
11+
}
12+
13+
for si, src := range defaultLogSourcesInfo.LogConfig.Sources {
14+
// Only ETW sources should be validated against etwNameToGuidMap.
15+
if !strings.EqualFold(src.Type, "ETW") {
16+
continue
17+
}
18+
19+
for pi, p := range src.Providers {
20+
if p.ProviderName == "" {
21+
t.Fatalf("empty ProviderName at source index %d provider index %d", si, pi)
22+
}
23+
24+
key := strings.ToLower(p.ProviderName)
25+
if _, ok := etwNameToGuidMap[key]; !ok {
26+
t.Fatalf(
27+
"provider not found in etwNameToGuidMap: source index=%d provider index=%d provider=%q lookup key=%q",
28+
si, pi, p.ProviderName, key,
29+
)
30+
}
31+
}
32+
}
33+
}
34+
func TestDefaultSources_NoDuplicateProviders(t *testing.T) {
35+
providerSet := make(map[string]struct{})
36+
37+
for si, src := range defaultLogSourcesInfo.LogConfig.Sources {
38+
if !strings.EqualFold(src.Type, "ETW") {
39+
continue
40+
}
41+
for pi, p := range src.Providers {
42+
key := strings.ToLower(p.ProviderName)
43+
if _, exists := providerSet[key]; exists {
44+
t.Fatalf("duplicate provider found: source index=%d provider index=%d provider=%q", si, pi, p.ProviderName)
45+
}
46+
providerSet[key] = struct{}{}
47+
}
48+
}
49+
}
50+
51+
func TestDefaultSources_NoProviderGUIDProvided(t *testing.T) {
52+
for si, src := range defaultLogSourcesInfo.LogConfig.Sources {
53+
if !strings.EqualFold(src.Type, "ETW") {
54+
continue
55+
}
56+
for pi, p := range src.Providers {
57+
if p.ProviderGUID != "" {
58+
t.Fatalf("ProviderGUID should not be provided: source index=%d provider index=%d provider=%q guid=%q", si, pi, p.ProviderName, p.ProviderGUID)
59+
}
60+
}
61+
}
62+
}
63+
64+
func TestDefaultSources_AtLeastOneETWSource(t *testing.T) {
65+
found := false
66+
for _, src := range defaultLogSourcesInfo.LogConfig.Sources {
67+
if strings.EqualFold(src.Type, "ETW") {
68+
found = true
69+
break
70+
}
71+
}
72+
if !found {
73+
t.Fatal("no ETW source found in defaultLogSourcesInfo")
74+
}
75+
}

0 commit comments

Comments
 (0)