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
21 changes: 21 additions & 0 deletions internal/tools/uvmboot/conf_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package main

import (
"context"
"fmt"
"os"

"github.com/containerd/console"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"

"github.com/Microsoft/hcsshim/internal/cmd"
Expand All @@ -19,6 +21,9 @@ const (
vmgsFilePathArgName = "vmgs-path"
disableSBArgName = "disable-secure-boot"
isolationTypeArgName = "isolation-type"

// default policy (that allows all operations) used when no policy is provided
allowAllPolicy = "cGFja2FnZSBwb2xpY3kKCmFwaV92ZXJzaW9uIDo9ICIwLjExLjAiCmZyYW1ld29ya192ZXJzaW9uIDo9ICIwLjQuMCIKCm1vdW50X2NpbXMgOj0geyJhbGxvd2VkIjogdHJ1ZX0KbW91bnRfZGV2aWNlIDo9IHsiYWxsb3dlZCI6IHRydWV9Cm1vdW50X292ZXJsYXkgOj0geyJhbGxvd2VkIjogdHJ1ZX0KY3JlYXRlX2NvbnRhaW5lciA6PSB7ImFsbG93ZWQiOiB0cnVlLCAiZW52X2xpc3QiOiBudWxsLCAiYWxsb3dfc3RkaW9fYWNjZXNzIjogdHJ1ZX0KdW5tb3VudF9kZXZpY2UgOj0geyJhbGxvd2VkIjogdHJ1ZX0KdW5tb3VudF9vdmVybGF5IDo9IHsiYWxsb3dlZCI6IHRydWV9CmV4ZWNfaW5fY29udGFpbmVyIDo9IHsiYWxsb3dlZCI6IHRydWUsICJlbnZfbGlzdCI6IG51bGx9CmV4ZWNfZXh0ZXJuYWwgOj0geyJhbGxvd2VkIjogdHJ1ZSwgImVudl9saXN0IjogbnVsbCwgImFsbG93X3N0ZGlvX2FjY2VzcyI6IHRydWV9CnNodXRkb3duX2NvbnRhaW5lciA6PSB7ImFsbG93ZWQiOiB0cnVlfQpzaWduYWxfY29udGFpbmVyX3Byb2Nlc3MgOj0geyJhbGxvd2VkIjogdHJ1ZX0KcGxhbjlfbW91bnQgOj0geyJhbGxvd2VkIjogdHJ1ZX0KcGxhbjlfdW5tb3VudCA6PSB7ImFsbG93ZWQiOiB0cnVlfQpnZXRfcHJvcGVydGllcyA6PSB7ImFsbG93ZWQiOiB0cnVlfQpkdW1wX3N0YWNrcyA6PSB7ImFsbG93ZWQiOiB0cnVlfQpydW50aW1lX2xvZ2dpbmcgOj0geyJhbGxvd2VkIjogdHJ1ZX0KbG9hZF9mcmFnbWVudCA6PSB7ImFsbG93ZWQiOiB0cnVlfQpzY3JhdGNoX21vdW50IDo9IHsiYWxsb3dlZCI6IHRydWV9CnNjcmF0Y2hfdW5tb3VudCA6PSB7ImFsbG93ZWQiOiB0cnVlfQo="

Copilot AI Aug 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The base64-encoded policy string is extremely long and hard to read. Consider storing this in a separate file or using a multiline string with proper formatting for better maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +26

Copilot AI Aug 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an 'allow all' security policy as the default poses security risks in production environments. Consider making the security policy mandatory or using a more restrictive default policy.

Suggested change
// default policy (that allows all operations) used when no policy is provided
allowAllPolicy = "cGFja2FnZSBwb2xpY3kKCmFwaV92ZXJzaW9uIDo9ICIwLjExLjAiCmZyYW1ld29ya192ZXJzaW9uIDo9ICIwLjQuMCIKCm1vdW50X2NpbXMgOj0geyJhbGxvd2VkIjogdHJ1ZX0KbW91bnRfZGV2aWNlIDo9IHsiYWxsb3dlZCI6IHRydWV9Cm1vdW50X292ZXJsYXkgOj0geyJhbGxvd2VkIjogdHJ1ZX0KY3JlYXRlX2NvbnRhaW5lciA6PSB7ImFsbG93ZWQiOiB0cnVlLCAiZW52X2xpc3QiOiBudWxsLCAiYWxsb3dfc3RkaW9fYWNjZXNzIjogdHJ1ZX0KdW5tb3VudF9kZXZpY2UgOj0geyJhbGxvd2VkIjogdHJ1ZX0KdW5tb3VudF9vdmVybGF5IDo9IHsiYWxsb3dlZCI6IHRydWV9CmV4ZWNfaW5fY29udGFpbmVyIDo9IHsiYWxsb3dlZCI6IHRydWUsICJlbnZfbGlzdCI6IG51bGx9CmV4ZWNfZXh0ZXJuYWwgOj0geyJhbGxvd2VkIjogdHJ1ZSwgImVudl9saXN0IjogbnVsbCwgImFsbG93X3N0ZGlvX2FjY2VzcyI6IHRydWV9CnNodXRkb3duX2NvbnRhaW5lciA6PSB7ImFsbG93ZWQiOiB0cnVlfQpzaWduYWxfY29udGFpbmVyX3Byb2Nlc3MgOj0geyJhbGxvd2VkIjogdHJ1ZX0KcGxhbjlfbW91bnQgOj0geyJhbGxvd2VkIjogdHJ1ZX0KcGxhbjlfdW5tb3VudCA6PSB7ImFsbG93ZWQiOiB0cnVlfQpnZXRfcHJvcGVydGllcyA6PSB7ImFsbG93ZWQiOiB0cnVlfQpkdW1wX3N0YWNrcyA6PSB7ImFsbG93ZWQiOiB0cnVlfQpydW50aW1lX2xvZ2dpbmcgOj0geyJhbGxvd2VkIjogdHJ1ZX0KbG9hZF9mcmFnbWVudCA6PSB7ImFsbG93ZWQiOiB0cnVlfQpzY3JhdGNoX21vdW50IDo9IHsiYWxsb3dlZCI6IHRydWV9CnNjcmF0Y2hfdW5tb3VudCA6PSB7ImFsbG93ZWQiOiB0cnVlfQo="
// Security policy must be provided by the user; no default policy is set for safety.

Copilot uses AI. Check for mistakes.
)

var (
Expand All @@ -28,6 +33,7 @@ var (
cwcowVMGSPath string
cwcowDisableSecureBoot bool
cwcowIsolationMode string
cwcowSecurityPolicy string
)

var cwcowCommand = cli.Command{
Expand Down Expand Up @@ -79,6 +85,12 @@ var cwcowCommand = cli.Command{
Destination: &cwcowIsolationMode,
Required: true,
},
cli.StringFlag{
Name: securityPolicyArgName,

Copilot AI Aug 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant securityPolicyArgName is referenced but not defined in this file. This will cause a compilation error.

Copilot uses AI. Check for mistakes.
Usage: "Security policy that should be enforced inside the UVM. If none is provided, default policy that allows all operations will be used.",
Destination: &cwcowSecurityPolicy,
Value: allowAllPolicy,
},
},
Action: func(c *cli.Context) error {
runMany(c, func(id string) error {
Expand All @@ -91,6 +103,7 @@ var cwcowCommand = cli.Command{

// confidential specific options
options.SecurityPolicyEnabled = true
options.SecurityPolicy = cwcowSecurityPolicy
options.DisableSecureBoot = cwcowDisableSecureBoot
options.GuestStateFilePath = cwcowVMGSPath
options.IsolationType = cwcowIsolationMode
Expand Down Expand Up @@ -129,6 +142,14 @@ var cwcowCommand = cli.Command{
cmd.Stdout = os.Stdout
con, err := console.ConsoleFromFile(os.Stdin)
if err == nil {
csz, err := con.Size()
if err != nil {
return fmt.Errorf("failed to get console size: %w", err)
}
cmd.Spec.ConsoleSize = &specs.Box{
Height: uint(csz.Height),
Width: uint(csz.Width),
}
err = con.SetRaw()
if err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions internal/tools/uvmboot/lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ package main

import (
"context"
"fmt"
"io"
"os"
"strings"

"github.com/containerd/console"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"

"github.com/Microsoft/hcsshim/internal/cmd"
Expand Down Expand Up @@ -306,6 +308,14 @@ func execViaGCS(ctx context.Context, vm *uvm.UtilityVM, cCtx *cli.Context) error
if err != nil {
log.G(ctx).WithError(err).Warn("could not create console from stdin")
} else {
csz, err := con.Size()
if err != nil {
return fmt.Errorf("failed to get console size: %w", err)
}
c.Spec.ConsoleSize = &specs.Box{
Height: uint(csz.Height),
Width: uint(csz.Width),
}
if err := con.SetRaw(); err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions internal/tools/uvmboot/wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/containerd/console"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"

"github.com/Microsoft/hcsshim/internal/cmd"
Expand Down Expand Up @@ -101,6 +102,14 @@ var wcowCommand = cli.Command{
cmd.Stdout = os.Stdout
con, err := console.ConsoleFromFile(os.Stdin)
if err == nil {
csz, err := con.Size()
if err != nil {
return fmt.Errorf("failed to get console size: %w", err)
}
cmd.Spec.ConsoleSize = &specs.Box{
Height: uint(csz.Height),
Width: uint(csz.Width),
}
err = con.SetRaw()
if err != nil {
return err
Expand Down
Loading