Skip to content

Commit 4c85f42

Browse files
author
Manish Ranjan Mahanta
committed
Addressing review comments
1 parent c3c8e64 commit 4c85f42

13 files changed

Lines changed: 198 additions & 217 deletions

File tree

internal/gcs-sidecar/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (b *Bridge) modifyServiceSettings(req *request) (err error) {
500500
// Todo: Add policy enforcement for modifying service settings
501501
modifyRequest, err := unmarshalModifyServiceSettings(req)
502502
if err != nil {
503-
return err
503+
return fmt.Errorf("failed to unmarshal modifyServiceSettings request: %w", err)
504504
}
505505

506506
switch modifyRequest.PropertyType {

internal/oci/uvm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
419419
if err := handleWCOWSecurityPolicy(ctx, s.Annotations, wopts); err != nil {
420420
return nil, err
421421
}
422-
// If security policy is enable, wopts.DisableLogForwarding default value should be true (CWCOW should not allow log forwarding by default)
422+
// If security policy is enable, wopts.LogForwardingEnabled default value should be false (CWCOW should not allow log forwarding by default)
423423
if wopts.SecurityPolicyEnabled {
424-
wopts.DisableLogForwarding = true
424+
wopts.LogForwardingEnabled = false
425425
}
426426
wopts.LogSources = ParseAnnotationsString(s.Annotations, annotations.LogSources, wopts.LogSources)
427-
wopts.DisableLogForwarding = ParseAnnotationsBool(ctx, s.Annotations, annotations.DisableForwardLogs, wopts.DisableLogForwarding)
428-
wopts.DisableDefaultLogSources = ParseAnnotationsBool(ctx, s.Annotations, annotations.DisableDefaultLogSources, wopts.DisableDefaultLogSources)
427+
wopts.LogForwardingEnabled = ParseAnnotationsBool(ctx, s.Annotations, annotations.LogForwardingEnabled, wopts.LogForwardingEnabled)
428+
wopts.DefaultLogSourcesEnabled = ParseAnnotationsBool(ctx, s.Annotations, annotations.DefaultLogSourcesEnabled, wopts.DefaultLogSourcesEnabled)
429429

430430
return wopts, nil
431431
}

internal/uvm/create_wcow.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ type OptionsWCOW struct {
7272

7373
OutputHandlerCreator vmutils.OutputHandlerCreator // Creates an [OutputHandler] that controls how output received over HVSocket from the UVM is handled. Defaults to parsing output as ETW Log events
7474
LogSources string // ETW providers to be set for the logging service
75-
DisableLogForwarding bool // Whether to disable forwarding of logs to the host or not
76-
DisableDefaultLogSources bool // Whether to disable using default log sources
75+
LogForwardingEnabled bool // Whether to enable forwarding of logs to the host or not
76+
DefaultLogSourcesEnabled bool // Whether to enable using default log sources
7777
}
7878

7979
func defaultConfidentialWCOWOSBootFilesPath() string {
@@ -113,8 +113,8 @@ func NewDefaultOptionsWCOW(id, owner string) *OptionsWCOW {
113113
},
114114
},
115115
OutputHandlerCreator: vmutils.ParseGCSLogrus,
116-
DisableLogForwarding: false, // Default to true for WCOW, and set to false for CWCOW in internal/oci/uvm.go SpecToUVMCreateOpts
117-
DisableDefaultLogSources: false,
116+
LogForwardingEnabled: true, // Default to true for WCOW, and set to false for CWCOW in internal/oci/uvm.go SpecToUVMCreateOpts
117+
DefaultLogSourcesEnabled: true,
118118
LogSources: "",
119119
}
120120
}
@@ -293,7 +293,7 @@ func prepareCommonConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWC
293293
}
294294

295295
maps.Copy(doc.VirtualMachine.Devices.HvSocket.HvSocketConfig.ServiceTable, opts.AdditionalHyperVConfig)
296-
if !opts.DisableLogForwarding {
296+
if opts.LogForwardingEnabled {
297297
key := prot.WindowsLoggingHvsockServiceID.String()
298298
doc.VirtualMachine.Devices.HvSocket.HvSocketConfig.ServiceTable[key] = hcsschema.HvSocketServiceConfig{
299299
AllowWildcardBinds: true,
@@ -579,8 +579,8 @@ func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error
579579
createOpts: opts,
580580
blockCIMMounts: make(map[string]*UVMMountedBlockCIMs),
581581
logSources: opts.LogSources,
582-
forwardLogs: !opts.DisableLogForwarding,
583-
disableDefaultLogSources: opts.DisableDefaultLogSources,
582+
logForwardingEnabled: opts.LogForwardingEnabled,
583+
defaultLogSourcesEnabled: opts.DefaultLogSourcesEnabled,
584584
}
585585

586586
defer func() {
@@ -620,7 +620,7 @@ func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error
620620
return nil, fmt.Errorf("error while creating the compute system: %w", err)
621621
}
622622

623-
if !opts.DisableLogForwarding {
623+
if opts.LogForwardingEnabled {
624624
// Create a socket that the executed program can send to. This is usually
625625
// used by Log Forward Service to send log data.
626626
uvm.outputHandler = opts.OutputHandlerCreator(opts.ID)

internal/uvm/log_wcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (uvm *UtilityVM) SetLogSources(ctx context.Context) error {
6969
// For confidential WCOw, we skip the adding guids to the log sources as the sidecar-GCS will verify the
7070
// allowed log sources against policy and append the necessary GUIDs to the ones allowed. Rest are dropped.
7171
// For non-confidential WCOW, we include the GUIDs in the log sources as the hcsshim communicates directly with the inboxGCS.
72-
settings := etw.UpdateLogSources(ctx, uvm.logSources, !uvm.disableDefaultLogSources, !uvm.HasConfidentialPolicy())
72+
settings := etw.UpdateLogSources(ctx, uvm.logSources, uvm.defaultLogSourcesEnabled, !uvm.HasConfidentialPolicy())
7373

7474
req := guestrequest.LogForwardServiceRPCRequest{
7575
RPCType: guestrequest.RPCModifyServiceSettings,

internal/uvm/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) {
285285
}
286286
}
287287

288-
if uvm.OS() == "windows" && uvm.forwardLogs {
288+
if uvm.OS() == "windows" && uvm.logForwardingEnabled {
289289
// If the UVM is Windows and log forwarding is enabled, set the log sources
290290
// and start the log forwarding service.
291291
if err := uvm.SetLogSources(ctx); err != nil {

internal/uvm/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ type UtilityVM struct {
144144
blockCIMMounts map[string]*UVMMountedBlockCIMs
145145
blockCIMMountLock sync.Mutex
146146

147-
forwardLogs bool // Indicates whether to forward logs from the UVM to the host
148-
disableDefaultLogSources bool // Specifies whether addition of default list of ETW providers should be disabled
147+
logForwardingEnabled bool // Indicates whether to forward logs from the UVM to the host
148+
defaultLogSourcesEnabled bool // Specifies whether addition of default list of ETW providers should be disabled
149149
logSources string // ETW providers to enable for log forwarding
150150
}
151151

internal/vm/vmutils/etw/default-sources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package etw
22

3-
// defaultLogSourcesInfo is the native Go representation of the default-logsources.json file.
3+
// defaultLogSourcesInfo defines the list of trusted ETW providers
44
var defaultLogSourcesInfo = LogSourcesInfo{
55
LogConfig: LogConfig{
66
Sources: []Source{

internal/vm/vmutils/etw/default-sources_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
)
77

88
func TestDefaultSources_ETWProvidersExistInETWMap(t *testing.T) {
9-
if len(etwNameToGuidMap) == 0 {
10-
t.Fatal("etwNameToGuidMap is empty")
9+
if len(etwNameToGUIDMap) == 0 {
10+
t.Fatal("etwNameToGUIDMap is empty")
1111
}
1212

1313
for si, src := range defaultLogSourcesInfo.LogConfig.Sources {
14-
// Only ETW sources should be validated against etwNameToGuidMap.
14+
// Only ETW sources should be validated against etwNameToGUIDMap.
1515
if !strings.EqualFold(src.Type, "ETW") {
1616
continue
1717
}
@@ -22,9 +22,9 @@ func TestDefaultSources_ETWProvidersExistInETWMap(t *testing.T) {
2222
}
2323

2424
key := strings.ToLower(p.ProviderName)
25-
if _, ok := etwNameToGuidMap[key]; !ok {
25+
if _, ok := etwNameToGUIDMap[key]; !ok {
2626
t.Fatalf(
27-
"provider not found in etwNameToGuidMap: source index=%d provider index=%d provider=%q lookup key=%q",
27+
"provider not found in etwNameToGUIDMap: source index=%d provider index=%d provider=%q lookup key=%q",
2828
si, pi, p.ProviderName, key,
2929
)
3030
}

internal/vm/vmutils/etw/etw_map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package etw
22

33
// LOWERCASE ONLY keys for easier lookups and case-insensitive matching.
4-
var etwNameToGuidMap = map[string]string{
4+
var etwNameToGUIDMap = map[string]string{
55
"microsoft.windows.containers.setup": "22267b1c-b979-5c81-9e24-0db386a62dd1",
66
"microsoft.windows.containers.storage": "2551390d-5927-5c84-6f0a-027a7e78d38d",
77
"microsoft.windows.containers.library": "67eb0417-9297-42ae-a1d9-98bfeb359059",

internal/vm/vmutils/etw/etw_map_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"testing"
66
)
77

8-
func TestETWNameToGuidMap_AllKeysAndValuesAreLowercase(t *testing.T) {
9-
if len(etwNameToGuidMap) == 0 {
10-
t.Fatal("etwNameToGuidMap is empty")
8+
func TestETWNameToGUIDMap_AllKeysAndValuesAreLowercase(t *testing.T) {
9+
if len(etwNameToGUIDMap) == 0 {
10+
t.Fatal("etwNameToGUIDMap is empty")
1111
}
1212

13-
for key, value := range etwNameToGuidMap {
13+
for key, value := range etwNameToGUIDMap {
1414
if key != strings.ToLower(key) {
1515
t.Fatalf("map key is not lowercase: key=%q value=%q", key, value)
1616
}
@@ -20,7 +20,7 @@ func TestETWNameToGuidMap_AllKeysAndValuesAreLowercase(t *testing.T) {
2020
}
2121
}
2222

23-
func isValidGuid(guid string) bool {
23+
func isValidGUID(guid string) bool {
2424
// GUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12 hex digits)
2525
if len(guid) != 36 {
2626
return false
@@ -40,24 +40,24 @@ func isValidGuid(guid string) bool {
4040
return true
4141
}
4242

43-
func TestETWNameToGuidMap_AllGuidsAreValid(t *testing.T) {
44-
for key, guid := range etwNameToGuidMap {
45-
if !isValidGuid(guid) {
43+
func TestETWNameToGUIDMap_AllGUIDsAreValid(t *testing.T) {
44+
for key, guid := range etwNameToGUIDMap {
45+
if !isValidGUID(guid) {
4646
t.Fatalf("invalid GUID format: key=%q guid=%q", key, guid)
4747
}
4848
}
4949
}
5050

51-
func TestETWNameToGuidMap_KeysAreNonEmpty(t *testing.T) {
52-
for key := range etwNameToGuidMap {
51+
func TestETWNameToGUIDMap_KeysAreNonEmpty(t *testing.T) {
52+
for key := range etwNameToGUIDMap {
5353
if strings.TrimSpace(key) == "" {
54-
t.Fatal("found empty key in etwNameToGuidMap")
54+
t.Fatal("found empty key in etwNameToGUIDMap")
5555
}
5656
}
5757
}
5858

59-
func TestETWNameToGuidMap_ValuesAreNonEmpty(t *testing.T) {
60-
for key, value := range etwNameToGuidMap {
59+
func TestETWNameToGUIDMap_ValuesAreNonEmpty(t *testing.T) {
60+
for key, value := range etwNameToGUIDMap {
6161
if strings.TrimSpace(value) == "" {
6262
t.Fatalf("found empty value for key=%q", key)
6363
}

0 commit comments

Comments
 (0)