Skip to content

Commit f3b2f2c

Browse files
committed
C-WCOW: Runtime logging enforcement, misc cleanup
Signed-off-by: Mahati Chamarthy <mchamarthy@microsoft.com>
1 parent a590753 commit f3b2f2c

File tree

7 files changed

+173
-239
lines changed

7 files changed

+173
-239
lines changed

cmd/gcs-sidecar/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"flag"
99
"fmt"
10+
"io"
1011
"net"
1112
"os"
1213
"time"
@@ -150,7 +151,6 @@ func main() {
150151
logrus.Fatal(err)
151152
}
152153
logrus.SetLevel(level)
153-
logrus.SetOutput(logFileHandle)
154154
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
155155
trace.RegisterExporter(&oc.LogrusExporter{})
156156

@@ -225,15 +225,17 @@ func main() {
225225
case "allow":
226226
initialEnforcer = &securitypolicy.OpenDoorSecurityPolicyEnforcer{}
227227
logrus.Tracef("initial-policy-stance: allow")
228+
logrus.SetOutput(logFileHandle)
228229
case "deny":
229230
initialEnforcer = &securitypolicy.ClosedDoorSecurityPolicyEnforcer{}
230231
logrus.Tracef("initial-policy-stance: deny")
232+
logrus.SetOutput(io.Discard)
231233
default:
232234
logrus.Error("unknown initial-policy-stance")
233235
}
234236

235237
// 3. Create bridge and initializa
236-
brdg := sidecar.NewBridge(shimCon, gcsCon, initialEnforcer)
238+
brdg := sidecar.NewBridge(shimCon, gcsCon, initialEnforcer, logFileHandle)
237239
brdg.AssignHandlers()
238240

239241
// 3. Listen and serve for hcsshim requests.

internal/gcs-sidecar/bridge.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type Bridge struct {
4747
// and send responses back to hcsshim respectively.
4848
sendToGCSCh chan request
4949
sendToShimCh chan bridgeResponse
50+
51+
// logging target
52+
logWriter io.Writer
5053
}
5154

5255
// SequenceID is used to correlate requests and responses.
@@ -77,7 +80,7 @@ type request struct {
7780
message []byte
7881
}
7982

80-
func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser, initialEnforcer securitypolicy.SecurityPolicyEnforcer) *Bridge {
83+
func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser, initialEnforcer securitypolicy.SecurityPolicyEnforcer, logWriter io.Writer) *Bridge {
8184
hostState := NewHost(initialEnforcer)
8285
return &Bridge{
8386
pending: make(map[sequenceID]*prot.ContainerExecuteProcessResponse),
@@ -87,6 +90,7 @@ func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser, ini
8790
inboxGCSConn: inboxGCSConn,
8891
sendToGCSCh: make(chan request),
8992
sendToShimCh: make(chan bridgeResponse),
93+
logWriter: logWriter,
9094
}
9195
}
9296

0 commit comments

Comments
 (0)