Skip to content

Commit

Permalink
Default to deny all security policy.
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 <maksiman@microsoft.com>
  • Loading branch information
anmaxvl committed Mar 10, 2022
1 parent 5f4ec16 commit ff9a733
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 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
1 change: 0 additions & 1 deletion internal/tools/securitypolicy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,3 @@ isn't in the TOML configuration.
If the version of the pause container changes from 3.1, you will need to update
the hardcoded root hash by running the `dmverity-vhd` to compute the root hash
for the new container and update this tool accordingly.

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 ff9a733

Please sign in to comment.