Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions cmd/gcs-sidecar/internal/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"github.com/pkg/errors"
"golang.org/x/sys/windows"

"github.com/Microsoft/hcsshim/cmd/gcs-sidecar/internal/windowssecuritypolicy"
"github.com/Microsoft/hcsshim/internal/guest/gcserr"
)

Expand All @@ -25,14 +26,27 @@
// - cherry pick commit to add annotations for securityPolicy
// - shimdiag.exe exec uvmID
// TODO: Do we need to support schema1 request types?
type requestMessage interface {

Check failure on line 29 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `requestMessage` is unused (unused)

Check failure on line 29 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `requestMessage` is unused (unused)
Base() *requestBase
}

type responseMessage interface {

Check failure on line 33 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `responseMessage` is unused (unused)

Check failure on line 33 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `responseMessage` is unused (unused)
Base() *responseBase
}

type messageHeader struct {
Type uint32
Size uint32
ID int64
}

type bridgeResponse struct {

Check failure on line 43 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `bridgeResponse` is unused (unused)

Check failure on line 43 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `bridgeResponse` is unused (unused)
// ctx is the context created on request read
// ctx context.Context
header *messageHeader
response interface{}
}

/*
// rpc represents an outstanding rpc request to the guest
type rpc struct {
Expand Down Expand Up @@ -69,6 +83,34 @@
// waitCh chan struct{}

quitChan chan error

PolicyEnforcer *SecurityPoliyEnforcer
}

type SecurityPoliyEnforcer struct {
// state required for the security policy enforcement
policyMutex sync.Mutex
securityPolicyEnforcer windowssecuritypolicy.SecurityPolicyEnforcer
securityPolicyEnforcerSet bool
uvmReferenceInfo string
}

func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser) *Bridge {
return &Bridge{
shimConn: shimConn,
inboxGCSConn: inboxGCSConn,
handlerList: make(map[rpcProc]HandlerFunc),
sendToGCSChan: make(chan request),
sendToShimCh: make(chan request),
quitChan: make(chan error),
}
}

func NewPolicyEnforcer(initialEnforcer windowssecuritypolicy.SecurityPolicyEnforcer) *SecurityPoliyEnforcer {
return &SecurityPoliyEnforcer{
securityPolicyEnforcerSet: false,
securityPolicyEnforcer: initialEnforcer,
}
}

// TODO: rename request to bridgeMessage
Expand Down Expand Up @@ -98,17 +140,6 @@
message []byte
}

func NewBridge(shimConn io.ReadWriteCloser, inboxGCSConn io.ReadWriteCloser) *Bridge {
return &Bridge{
shimConn: shimConn,
inboxGCSConn: inboxGCSConn,
handlerList: make(map[rpcProc]HandlerFunc),
sendToGCSChan: make(chan request),
sendToShimCh: make(chan request),
quitChan: make(chan error),
}
}

// UnknownMessage represents the default handler logic for an unmatched request
// type sent from the bridge.
func UnknownMessage(r *request) error {
Expand Down Expand Up @@ -184,12 +215,6 @@
b.HandleFunc(rpcLifecycleNotification, b.lifecycleNotification) // TODO: Validate this request as well?
}

type messageHeader struct {
Type uint32
Size uint32
ID int64
}

func readMessage(r io.Reader) (request, error) {
var h [hdrSize]byte
_, err := io.ReadFull(r, h[:])
Expand Down Expand Up @@ -273,14 +298,14 @@
// 2. Code cleanup on error
// ? b.close(err)
// b.quitCh <- true // give few seconds delay and close connections?
b.close(err)
return
}

// If we are here, means that the requested operation is allowed.
// Forward message to GCS. We handle responses from GCS separately.

log.Printf("hcsshim receive message redirect")
b.sendToGCSChan <- req
// b.sendToGCSChan <- req
}(req)
}
}()
Expand All @@ -289,7 +314,7 @@
for req := range b.sendToGCSChan {
// reconstruct message and forward to gcs
var buf bytes.Buffer
log.Printf("bridge send to gcs")
log.Printf("bridge send to gcs, req %v", req)
if b.prepareMessageAndSend(req.header, req.message, &buf, b.inboxGCSConn) != nil {
// kill bridge?
log.Printf("err sending message to ")
Expand Down Expand Up @@ -349,6 +374,10 @@
}
}

func (b *Bridge) forwardMessageToGCS(req request) {
b.sendToGCSChan <- req
}

func (b *Bridge) close(err error) {
// TODO: Fail outstanding rpc requests before closing bridge and other channels
// This is important to do as valid errors need to be recorded by callers and fail
Expand Down
Loading
Loading