Skip to content

Commit

Permalink
Default to deny all security policy. (#1320)
Browse files Browse the repository at this point in the history
When bringing up the UVM default to closed door security policy
to reject any modification requests prior to security policy is set
inside GCS.
When security policy is empty, default to open door policy.

Signed-off-by: Maksim An <[email protected]>
  • Loading branch information
anmaxvl authored Mar 16, 2022
1 parent abf92f5 commit cf6b2c9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/guest/runtime/hcsv2/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"syscall"
"time"

shellwords "github.com/mattn/go-shellwords"
"github.com/mattn/go-shellwords"
"github.com/pkg/errors"

"github.com/Microsoft/hcsshim/internal/guest/gcserr"
Expand Down Expand Up @@ -66,7 +66,7 @@ func NewHost(rtime runtime.Runtime, vsock transport.Transport) *Host {
rtime: rtime,
vsock: vsock,
securityPolicyEnforcerSet: false,
securityPolicyEnforcer: &securitypolicy.OpenDoorSecurityPolicyEnforcer{},
securityPolicyEnforcer: &securitypolicy.ClosedDoorSecurityPolicyEnforcer{},
}
}

Expand Down
7 changes: 6 additions & 1 deletion internal/uvm/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ func (uvm *UtilityVM) SetSecurityPolicy(ctx context.Context, policy string) erro
}

if policy == "" {
return nil
openDoorPolicy := securitypolicy.NewOpenDoorPolicy()
policyString, err := openDoorPolicy.EncodeToString()
if err != nil {
return err
}
policy = policyString
}

uvm.m.Lock()
Expand Down
5 changes: 3 additions & 2 deletions pkg/securitypolicy/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ type SecurityPolicy struct {
Containers Containers `json:"containers"`
}

// EncodeToString returns base64 encoded string representation of SecurityPolicy.
func (sp *SecurityPolicy) EncodeToString() (string, error) {
j, err := json.Marshal(sp)
jsn, err := json.Marshal(sp)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(j), nil
return base64.StdEncoding.EncodeToString(jsn), nil
}

type Containers struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf6b2c9

Please sign in to comment.