@@ -16,87 +16,24 @@ import (
1616 "github.com/Microsoft/hcsshim/pkg/ctrdtaskapi"
1717)
1818
19- type ConfidentialUVMOpt func (ctx context.Context , r * guestresource.LCOWConfidentialOptions ) error
19+ type ConfidentialUVMOpt func (ctx context.Context , r * guestresource.ConfidentialOptions ) error
2020
2121// WithSecurityPolicy sets the desired security policy for the resource.
2222func WithSecurityPolicy (policy string ) ConfidentialUVMOpt {
23- return func (ctx context.Context , r * guestresource.LCOWConfidentialOptions ) error {
23+ return func (ctx context.Context , r * guestresource.ConfidentialOptions ) error {
2424 r .EncodedSecurityPolicy = policy
2525 return nil
2626 }
2727}
2828
2929// WithSecurityPolicyEnforcer sets the desired enforcer type for the resource.
3030func WithSecurityPolicyEnforcer (enforcer string ) ConfidentialUVMOpt {
31- return func (ctx context.Context , r * guestresource.LCOWConfidentialOptions ) error {
31+ return func (ctx context.Context , r * guestresource.ConfidentialOptions ) error {
3232 r .EnforcerType = enforcer
3333 return nil
3434 }
3535}
3636
37- // TODO (Mahati): Move this block out later
38- type WCOWConfidentialUVMOpt func (ctx context.Context , r * guestresource.WCOWConfidentialOptions ) error
39-
40- // WithSecurityPolicy sets the desired security policy for the resource.
41- func WithWCOWSecurityPolicy (policy string ) WCOWConfidentialUVMOpt {
42- return func (ctx context.Context , r * guestresource.WCOWConfidentialOptions ) error {
43- r .EncodedSecurityPolicy = policy
44- return nil
45- }
46- }
47-
48- // WithSecurityPolicyEnforcer sets the desired enforcer type for the resource.
49- func WithWCOWSecurityPolicyEnforcer (enforcer string ) WCOWConfidentialUVMOpt {
50- return func (ctx context.Context , r * guestresource.WCOWConfidentialOptions ) error {
51- r .EnforcerType = enforcer
52- return nil
53- }
54- }
55-
56- // WithUVMReferenceInfo reads UVM reference info file and base64 encodes the
57- // content before setting it for the resource. This is no-op if the
58- // path is empty or the file doesn't exist.
59- func WithWCOWUVMReferenceInfo (path string ) WCOWConfidentialUVMOpt {
60- return func (ctx context.Context , r * guestresource.WCOWConfidentialOptions ) error {
61- encoded , err := base64EncodeFileContents (path )
62- if err != nil {
63- if os .IsNotExist (err ) {
64- log .G (ctx ).WithField ("filePath" , path ).Debug ("UVM reference info file not found" )
65- return nil
66- }
67- return fmt .Errorf ("failed to read UVM reference info file: %w" , err )
68- }
69- r .EncodedUVMReference = encoded
70- return nil
71- }
72- }
73-
74- func (uvm * UtilityVM ) SetWCOWConfidentialUVMOptions (ctx context.Context , opts ... WCOWConfidentialUVMOpt ) error {
75- if uvm .operatingSystem != "windows" {
76- return errNotSupported
77- }
78- uvm .m .Lock ()
79- defer uvm .m .Unlock ()
80- confOpts := & guestresource.WCOWConfidentialOptions {}
81- for _ , o := range opts {
82- if err := o (ctx , confOpts ); err != nil {
83- return err
84- }
85- }
86- modification := & hcsschema.ModifySettingRequest {
87- RequestType : guestrequest .RequestTypeAdd ,
88- GuestRequest : guestrequest.ModificationRequest {
89- ResourceType : guestresource .ResourceTypeSecurityPolicy ,
90- RequestType : guestrequest .RequestTypeAdd ,
91- Settings : * confOpts ,
92- },
93- }
94- if err := uvm .modify (ctx , modification ); err != nil {
95- return fmt .Errorf ("uvm::Policy: failed to modify utility VM configuration: %w" , err )
96- }
97- return nil
98- }
99-
10037func base64EncodeFileContents (filePath string ) (string , error ) {
10138 if filePath == "" {
10239 return "" , nil
@@ -112,7 +49,7 @@ func base64EncodeFileContents(filePath string) (string, error) {
11249// content before setting it for the resource. This is no-op if the
11350// `referenceName` is empty or the file doesn't exist.
11451func WithUVMReferenceInfo (referenceRoot string , referenceName string ) ConfidentialUVMOpt {
115- return func (ctx context.Context , r * guestresource.LCOWConfidentialOptions ) error {
52+ return func (ctx context.Context , r * guestresource.ConfidentialOptions ) error {
11653 if referenceName == "" {
11754 return nil
11855 }
@@ -137,14 +74,10 @@ func WithUVMReferenceInfo(referenceRoot string, referenceName string) Confidenti
13774// This has to happen before we start mounting things or generally changing
13875// the state of the UVM after is has been measured at startup
13976func (uvm * UtilityVM ) SetConfidentialUVMOptions (ctx context.Context , opts ... ConfidentialUVMOpt ) error {
140- if uvm .operatingSystem != "linux" {
141- return errNotSupported
142- }
143-
14477 uvm .m .Lock ()
14578 defer uvm .m .Unlock ()
14679
147- confOpts := & guestresource.LCOWConfidentialOptions {}
80+ confOpts := & guestresource.ConfidentialOptions {}
14881 for _ , o := range opts {
14982 if err := o (ctx , confOpts ); err != nil {
15083 return err
@@ -174,7 +107,7 @@ func (uvm *UtilityVM) InjectPolicyFragment(ctx context.Context, fragment *ctrdta
174107 GuestRequest : guestrequest.ModificationRequest {
175108 ResourceType : guestresource .ResourceTypePolicyFragment ,
176109 RequestType : guestrequest .RequestTypeAdd ,
177- Settings : guestresource.LCOWSecurityPolicyFragment {
110+ Settings : guestresource.SecurityPolicyFragment {
178111 Fragment : fragment .Fragment ,
179112 },
180113 },
0 commit comments