Skip to content

Commit

Permalink
WIP: Implement ResourceTypeSecurityPolicy
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Jan 7, 2025
1 parent 9f47d92 commit 44871d8
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 74 deletions.
60 changes: 41 additions & 19 deletions cmd/gcs-sidecar/internal/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"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 @@ -33,6 +34,19 @@ type responseMessage interface {
Base() *responseBase
}

type messageHeader struct {
Type uint32
Size uint32
ID int64
}

type bridgeResponse struct {
// 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,27 @@ type Bridge struct {
// waitCh chan struct{}

quitChan chan error

securityPolicyEnforcer 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),
}
}

// TODO: rename request to bridgeMessage
Expand Down Expand Up @@ -98,17 +133,6 @@ type request struct {
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 +208,6 @@ func (b *Bridge) AssignHandlers() {
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 +291,14 @@ func (b *Bridge) ListenAndServeShimRequests() error {
// 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 Down Expand Up @@ -349,6 +367,10 @@ func (b *Bridge) ListenAndServeShimRequests() error {
}
}

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

0 comments on commit 44871d8

Please sign in to comment.