Skip to content

Commit 332ecc9

Browse files
kiashokMahatiC
authored andcommitted
WIP: Implement ResourceTypeSecurityPolicy
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
1 parent 6ea2844 commit 332ecc9

File tree

9 files changed

+443
-119
lines changed

9 files changed

+443
-119
lines changed

cmd/gcs-sidecar/internal/bridge/bridge.go

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/pkg/errors"
1616
"golang.org/x/sys/windows"
1717

18+
"github.com/Microsoft/hcsshim/cmd/gcs-sidecar/internal/windowssecuritypolicy"
1819
"github.com/Microsoft/hcsshim/internal/guest/gcserr"
1920
)
2021

@@ -33,6 +34,19 @@ type responseMessage interface {
3334
Base() *responseBase
3435
}
3536

37+
type messageHeader struct {
38+
Type uint32
39+
Size uint32
40+
ID int64
41+
}
42+
43+
type bridgeResponse struct {
44+
// ctx is the context created on request read
45+
// ctx context.Context
46+
header *messageHeader
47+
response interface{}
48+
}
49+
3650
/*
3751
// rpc represents an outstanding rpc request to the guest
3852
type rpc struct {
@@ -69,6 +83,34 @@ type Bridge struct {
6983
// waitCh chan struct{}
7084

7185
quitChan chan error
86+
87+
PolicyEnforcer *SecurityPoliyEnforcer
88+
}
89+
90+
type SecurityPoliyEnforcer struct {
91+
// state required for the security policy enforcement
92+
policyMutex sync.Mutex
93+
securityPolicyEnforcer windowssecuritypolicy.SecurityPolicyEnforcer
94+
securityPolicyEnforcerSet bool
95+
uvmReferenceInfo string
96+
}
97+
98+
func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser) *Bridge {
99+
return &Bridge{
100+
shimConn: shimConn,
101+
inboxGCSConn: inboxGCSConn,
102+
handlerList: make(map[rpcProc]HandlerFunc),
103+
sendToGCSChan: make(chan request),
104+
sendToShimCh: make(chan request),
105+
quitChan: make(chan error),
106+
}
107+
}
108+
109+
func NewPolicyEnforcer(initialEnforcer windowssecuritypolicy.SecurityPolicyEnforcer) *SecurityPoliyEnforcer {
110+
return &SecurityPoliyEnforcer{
111+
securityPolicyEnforcerSet: false,
112+
securityPolicyEnforcer: initialEnforcer,
113+
}
72114
}
73115

74116
// TODO: rename request to bridgeMessage
@@ -98,17 +140,6 @@ type request struct {
98140
message []byte
99141
}
100142

101-
func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser) *Bridge {
102-
return &Bridge{
103-
shimConn: shimConn,
104-
inboxGCSConn: inboxGCSConn,
105-
handlerList: make(map[rpcProc]HandlerFunc),
106-
sendToGCSChan: make(chan request),
107-
sendToShimCh: make(chan request),
108-
quitChan: make(chan error),
109-
}
110-
}
111-
112143
// UnknownMessage represents the default handler logic for an unmatched request
113144
// type sent from the bridge.
114145
func UnknownMessage(r *request) error {
@@ -184,12 +215,6 @@ func (b *Bridge) AssignHandlers() {
184215
b.HandleFunc(rpcLifecycleNotification, b.lifecycleNotification) // TODO: Validate this request as well?
185216
}
186217

187-
type messageHeader struct {
188-
Type uint32
189-
Size uint32
190-
ID int64
191-
}
192-
193218
func readMessage(r io.Reader) (request, error) {
194219
var h [hdrSize]byte
195220
_, err := io.ReadFull(r, h[:])
@@ -273,14 +298,14 @@ func (b *Bridge) ListenAndServeShimRequests() error {
273298
// 2. Code cleanup on error
274299
// ? b.close(err)
275300
// b.quitCh <- true // give few seconds delay and close connections?
276-
b.close(err)
277301
return
278302
}
279303

280304
// If we are here, means that the requested operation is allowed.
281305
// Forward message to GCS. We handle responses from GCS separately.
306+
282307
log.Printf("hcsshim receive message redirect")
283-
b.sendToGCSChan <- req
308+
// b.sendToGCSChan <- req
284309
}(req)
285310
}
286311
}()
@@ -289,7 +314,7 @@ func (b *Bridge) ListenAndServeShimRequests() error {
289314
for req := range b.sendToGCSChan {
290315
// reconstruct message and forward to gcs
291316
var buf bytes.Buffer
292-
log.Printf("bridge send to gcs")
317+
log.Printf("bridge send to gcs, req %v", req)
293318
if b.prepareMessageAndSend(req.header, req.message, &buf, b.inboxGCSConn) != nil {
294319
// kill bridge?
295320
log.Printf("err sending message to ")
@@ -349,6 +374,10 @@ func (b *Bridge) ListenAndServeShimRequests() error {
349374
}
350375
}
351376

377+
func (b *Bridge) forwardMessageToGCS(req request) {
378+
b.sendToGCSChan <- req
379+
}
380+
352381
func (b *Bridge) close(err error) {
353382
// TODO: Fail outstanding rpc requests before closing bridge and other channels
354383
// This is important to do as valid errors need to be recorded by callers and fail

0 commit comments

Comments
 (0)