Skip to content

Commit 8c5053a

Browse files
Christian LindigKonstantina Chremmou
authored andcommitted
CP-308455 VM.sysprep declare XML content as SecretString
Desclare the string parameter holding unattend.xml as secret to avoid logging it. Signed-off-by: Christian Lindig <[email protected]> # Conflicts: # ocaml/idl/datamodel_vm.ml # ocaml/xapi/vm_sysprep.mli # ocaml/xapi/xapi_vm.mli
1 parent 59f2751 commit 8c5053a

File tree

7 files changed

+11
-7
lines changed

7 files changed

+11
-7
lines changed

ocaml/idl/datamodel_vm.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ let sysprep =
23752375
~params:
23762376
[
23772377
(Ref _vm, "self", "The VM")
2378-
; (String, "unattend", "XML content passed to sysprep")
2378+
; (SecretString, "unattend", "XML content passed to sysprep")
23792379
; (Float, "timeout", "timeout in seconds for expected reboot")
23802380
]
23812381
~doc:

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3602,7 +3602,7 @@ let vm_sysprep fd printer rpc session_id params =
36023602
let unattend =
36033603
match get_client_file fd filename with
36043604
| Some xml ->
3605-
xml
3605+
xml |> SecretString.of_string
36063606
| None ->
36073607
marshal fd (Command (PrintStderr "Failed to read file.\n")) ;
36083608
raise (ExitWithError 1)

ocaml/xapi-types/secretString.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ let write_to_channel c s = output_string c s
2424

2525
let equal = String.equal
2626

27+
let length = String.length
28+
2729
let pool_secret = "pool_secret"
2830

2931
let with_cookie t cookies = (pool_secret, t) :: cookies

ocaml/xapi-types/secretString.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ val of_string : string -> t
2525

2626
val equal : t -> t -> bool
2727

28+
val length : t -> int
29+
2830
val json_rpc_of_t : t -> Rpc.t
2931

3032
val t_of_rpc : Rpc.t -> t

ocaml/xapi/vm_sysprep.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ let make_iso ~vm_uuid ~unattend =
140140
Xapi_stdext_unix.Unixext.mkdir_rec SR.dir 0o755 ;
141141
with_temp_dir ~dir:"/var/tmp/xapi" "sysprep-" "-iso" (fun temp_dir ->
142142
let path = temp_dir // "unattend.xml" in
143-
Unixext.write_string_to_file path unattend ;
143+
SecretString.write_to_file path unattend ;
144144
debug "%s: written to %s" __FUNCTION__ path ;
145145
let args = ["-r"; "-J"; "-o"; iso; temp_dir] in
146146
Forkhelpers.execute_command_get_output genisoimage args |> ignore ;
@@ -262,7 +262,7 @@ let sysprep ~__context ~vm ~unattend ~timeout =
262262
let control = Printf.sprintf "/local/domain/%Ld/control" domid in
263263
if domid <= 0L then
264264
fail VM_not_running ;
265-
if String.length unattend > 32 * 1024 then
265+
if SecretString.length unattend > 32 * 1024 then
266266
fail XML_too_large ;
267267
Ezxenstore_core.Xenstore.with_xs (fun xs ->
268268
let open Ezxenstore_core.Xenstore in

ocaml/xapi/vm_sysprep.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ val on_startup : __context:Context.t -> unit
3232
val sysprep :
3333
__context:Context.t
3434
-> vm:API.ref_VM
35-
-> unattend:string
35+
-> unattend:SecretString.t
3636
-> timeout:float
3737
-> unit
3838
(** Execute sysprep on [vm] using script [unattend]. This requires
39-
driver support from the VM and is checked. [unattend:string] must
39+
driver support from the VM and is checked. [unattend] must
4040
not exceed 32kb. Raised [Failure] that must be handled, *)

ocaml/xapi/xapi_vm.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,6 @@ val remove_from_blocked_operations :
454454
val sysprep :
455455
__context:Context.t
456456
-> self:API.ref_VM
457-
-> unattend:string
457+
-> unattend:SecretString.t
458458
-> timeout:float
459459
-> unit

0 commit comments

Comments
 (0)