Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync varstore certificates in XAPI with those on disks #4659

Merged

Conversation

benjamreis
Copy link
Contributor

@benjamreis benjamreis commented Mar 24, 2022

  • Pool.set_uefi_certificates is implemented and calls Host.set_uefi_certificates on all hosts
  • Host.set_uefi_certificates writes certificates on disks
  • On XAPI startup certificates stored in XAPI's Host.uefi_certificates are written on disks
  • When a host joins the pool Host.set_uefi_certificates is called with the certificates stored in XAPI's Pool.uefi_certificates

This means:

  • At every XAPI startup the certificates in host disks are synced with XAPI's Host.uefi_certificates
  • When Pool.set_uefi_certificates is called all hosts are synced in XAPi and disks with XAPI's Pool.uefi_certificates
  • When Host.set_uefi_certificates is called the host certificates on disk are synced with XAPI's Host.uefi_certificates

Also: Host.set_uefi_certificates no longer calls Pool.set_uefi_certificates, this requires changes
in external libs (varstored, uefistored, etc) to set the pool's certificates: call Pool.set_uefi_certificates.

See: #4647

Signed-off-by: BenjiReis benjamin.reis@vates.fr

@psafont psafont marked this pull request as draft March 24, 2022 10:54
~params:
[
(Ref _pool, "self", "The pool")
; (String, "value", "The certificates to apply to the pool anbd its hosts")
Copy link
Contributor

@lindig lindig Mar 24, 2022

Choose a reason for hiding this comment

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

Typo in and. Is the string the certificate (encoded?) or a reference to it, like a path? It would be good to make this clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like for Host.set_uefi_certificates it's the tarball.

let extract_certificate_file name =
if String.contains name '/' then
(* Internal error: tarfile not created correctly *)
failwith ("Invalid path in certificate tarball: " ^ name) ;
Copy link
Contributor

Choose a reason for hiding this comment

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

The error could be read as referring to a path in a tar file but it refers to the path of the tar file itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it references the path inside the tarball to an .auth file.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could make this more specific: Path in certificate tarball %s contains /

List.iter
(fun name ->
let path = Filename.concat !Xapi_globs.varstore_dir name in
debug "*** BRS: Remove UEFI cert %s" path ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove BRS:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This are temporary logs for my tests :)
Should I let them once I'm done? (without the *** BRS: of course)

debug "*** BRS: Remove UEFI cert %s" path ;
try Sys.remove path
with
| Sys_error e
Copy link
Contributor

Choose a reason for hiding this comment

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

Matching the string seems to me like a poor way to detect this problem. Use a different function to remove a file that uses a better interface for errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not aware of another lib to remove a file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unix.unlink

()
)
["PK.auth"; "KEK.auth"; "db.auth"; "dbx.auth"] ;
if contents <> "" then (
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the empty string special? Might want to log this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the string is empty it means there's no certificates in XAPI to extract on the host disk.

@@ -479,6 +479,9 @@ val nvidia_vf_setup :
val allocate_resources_for_vm :
__context:Context.t -> self:API.ref_host -> vm:API.ref_VM -> live:bool -> unit

val save_uefi_certificates_to_dir :
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the name confusing? It has dir in its name but not in the parameter list.

@benjamreis
Copy link
Contributor Author

benjamreis commented Mar 25, 2022

I was wondering: how would you feel to remove the host.{set/get}_uefi_certificates? For now it can be deprecated and call the Pool ones and be removed in the future.

It seems this API and field are useless (unless there is a usecase where a host needs to have different certificates than the others in the pool but I can't think of one).

What do you think?

path

let with_temp_file_contents ~contents f =
let filename, out = Filename.open_temp_file "xapi_uefi_certificates" "tar" in
Copy link
Contributor

Choose a reason for hiding this comment

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

It's more common to use a dash (-) in file names than the underscore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It comes from already existing code, but I can change that 👍

@benjamreis
Copy link
Contributor Author

Latest commit is an implementation of what is proposed in my previous comment, and @stormi 's one in the issue.

Deprecate Host.uefi_certificates in favor of Pool API:

  • It means an host can't have different certs than the pool ones
  • No need to update certificate on a joining hosts since it will be synched after its toolstack is restarted
  • Host.set_uefi_certificates now calls Pool.set_uefi_certificates to update all pool's hosts' certificates
  • Host.uefi_certificates can be empty if the Pool API is used

I think it's the right way to go since having different certs on pool's hosts seems really dangerous to me.

@benjamreis benjamreis force-pushed the synch-varstored-between-hosts branch 8 times, most recently from 28722de to 8dc49ff Compare March 29, 2022 18:29
let write_uefi_certificates_to_disk =
call ~name:"write_uefi_certificates_to_disk"
~lifecycle:[(Published, rel_next, "")]
~doc:"Writes the UEFI certificates on a host disk"
Copy link
Contributor

Choose a reason for hiding this comment

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

"writes to"?

let set_uefi_certificates =
call ~name:"set_uefi_certificates"
~lifecycle:[(Published, rel_next, "")]
~doc:"Sets the UEFI certificates on a pool and all its hosts"
Copy link
Contributor

Choose a reason for hiding this comment

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

"Sets .. for a pool"?

let extract_certificate_file name =
if String.contains name '/' then
(* Internal error: tarfile not created correctly *)
failwith ("Invalid path in certificate tarball: " ^ name) ;
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make this more specific: Path in certificate tarball %s contains /

@benjamreis benjamreis force-pushed the synch-varstored-between-hosts branch from 8dc49ff to 4140850 Compare March 30, 2022 09:33
@benjamreis benjamreis marked this pull request as ready for review March 31, 2022 09:18
@benjamreis benjamreis changed the title [WIP] Sync varstore certificates in XAPI with those on disks Sync varstore certificates in XAPI with those on disks Mar 31, 2022
@benjamreis
Copy link
Contributor Author

I'll rebase and rework the commit message once the code stop changing before the merge. :)

benjamreis added a commit to xcp-ng/uefistored that referenced this pull request Apr 1, 2022
See: xapi-project/xen-api#4659

`Host` API is deprecated in favor of `Pool` API

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/uefistored that referenced this pull request Apr 1, 2022
See: xapi-project/xen-api#4659

`Host` API is deprecated in favor of `Pool` API

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-tests that referenced this pull request Apr 5, 2022
For XCP-ng > 8.2.1 there is a new behavior regarding SB certs management
See: xapi-project/xen-api#4659

Keep previous behavior for XCP-ng <= 8.2.1

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-tests that referenced this pull request Apr 6, 2022
For XCP-ng > 8.2.1 there is a new behavior regarding SB certs management
See: xapi-project/xen-api#4659

Keep previous behavior for XCP-ng <= 8.2.1

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-tests that referenced this pull request Apr 6, 2022
For XCP-ng > 8.2.1 there is a new behavior regarding SB certs management
See: xapi-project/xen-api#4659

Keep previous behavior for XCP-ng <= 8.2.1

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-tests that referenced this pull request Apr 6, 2022
For XCP-ng > 8.2.1 there is a new behavior regarding SB certs management
See: xapi-project/xen-api#4659

Keep previous behavior for XCP-ng <= 8.2.1

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
- `Pool.set_uefi_certificates` is implemented and writes the certificates
on all its hosts' disks

- `Host.set_uefi_certificates` is now deprecated and transmit the call to the pool method
- `Host.uefi_certificates` is deprecated as well as it's getter, the value is not updated.

- On XAPI startup certificates stored in XAPI's `Pool.uefi_certificates`
are written on disks

- When a host joins the pool's certificates are written on its disk.

This means:
	- At every XAPI startup the certificates in host disks are synced with
XAPI's `Pool.uefi_certificates`

	- When `Pool.set_uefi_certificates` is called all hosts are synced on their disks
with XAPI's `Pool.uefi_certificates`.

Also: `Host.set_uefi_certificates` calls should be replaced by `Pool.set_uefi_certificates`, this requires changes
in external libs (varstored, uefistored, etc) to set the pool's certificates: call `Pool.set_uefi_certificates`.

See: xapi-project#4647

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
@benjamreis benjamreis force-pushed the synch-varstored-between-hosts branch from e73b8df to 53d656b Compare April 7, 2022 08:28
@benjamreis
Copy link
Contributor Author

Hi!

I rebased the code into one commit with a (hopefully) clear commit message.
I wrote tests for this in our test repo and they're successful so everything good on our side. :)
Plus my manual testing also showed the expected behavior.

benjamreis added a commit to xcp-ng/xcp-ng-tests that referenced this pull request Apr 7, 2022
For XCP-ng > 8.2.1 there is a new behavior regarding SB certs management
See: xapi-project/xen-api#4659

Keep previous behavior for XCP-ng <= 8.2.1

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
@edwintorok edwintorok merged commit 85fdc21 into xapi-project:master Apr 13, 2022
@psafont psafont deleted the synch-varstored-between-hosts branch April 13, 2022 13:06
@psafont psafont restored the synch-varstored-between-hosts branch April 13, 2022 13:06
@benjamreis benjamreis deleted the synch-varstored-between-hosts branch April 13, 2022 16:29
psafont added a commit to psafont/xen-api that referenced this pull request Apr 13, 2022
Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
psafont added a commit to psafont/xen-api that referenced this pull request Apr 13, 2022
Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
psafont added a commit to psafont/xen-api that referenced this pull request Apr 14, 2022
Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
benjamreis added a commit to xcp-ng/xcp-ng-tests that referenced this pull request Apr 14, 2022
For XCP-ng > 8.2.1 there is a new behavior regarding SB certs management
See: xapi-project/xen-api#4659

Keep previous behavior for XCP-ng <= 8.2.1

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/uefistored that referenced this pull request Apr 14, 2022
See: xapi-project/xen-api#4659

`Host` API is deprecated in favor of `Pool` API

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/uefistored that referenced this pull request Apr 14, 2022
See: xapi-project/xen-api#4659

`Host` API is deprecated in favor of `Pool` API

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-org that referenced this pull request Apr 19, 2022
Starting from next release, the host disk certificate will be updated
by the pool ones at XAPI startup instead of when a VM starts.

See: xapi-project/xen-api#4659

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-org that referenced this pull request Apr 19, 2022
Starting from next release, the host disk certificate will be updated
by the pool ones at XAPI startup instead of when a VM starts.

See: xapi-project/xen-api#4659

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-org that referenced this pull request Apr 19, 2022
Starting from next release, the host disk certificate will be updated
by the pool ones at XAPI startup instead of when a VM starts.

See: xapi-project/xen-api#4659

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
benjamreis added a commit to xcp-ng/xcp-ng-org that referenced this pull request Apr 19, 2022
Starting from next release, the host disk certificate will be updated
by the pool ones at XAPI startup instead of when a VM starts.

See: xapi-project/xen-api#4659

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants