Skip to content

Commit 27b41c5

Browse files
authored
Merge pull request xapi-project#4440 from lindig/private/christianlin/CP-36098
Cert Refresh
2 parents 0086899 + ae8cf8b commit 27b41c5

18 files changed

+257
-12
lines changed

ocaml/idl/datamodel_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Datamodel_roles
88
When introducing a new release, bump the schema minor version to the next hundred
99
to leave a gap for potential hotfixes needing to increment the schema version.*)
1010
let schema_major_vsn = 5
11-
let schema_minor_vsn = 703
11+
let schema_minor_vsn = 704
1212

1313
(* Historical schema versions just in case this is useful later *)
1414
let rio_schema_major_vsn = 5

ocaml/idl/datamodel_host.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,14 @@ let host_query_ha = call ~flags:[`Session]
10291029
~allowed_roles:_R_READ_ONLY
10301030
()
10311031

1032+
let refresh_server_certificate = call
1033+
~lifecycle:[Published, rel_next, ""]
1034+
~name:"refresh_server_certificate"
1035+
~doc:"Replace the internal self-signed host certficate with a new one."
1036+
~params:[Ref _host, "host", "The host"]
1037+
~allowed_roles:_R_POOL_ADMIN
1038+
()
1039+
10321040
let display =
10331041
Enum ("host_display", [
10341042
"enabled", "This host is outputting its console to a physical display device";
@@ -1544,6 +1552,7 @@ let host_query_ha = call ~flags:[`Session]
15441552
crl_list;
15451553
certificate_sync;
15461554
get_server_certificate;
1555+
refresh_server_certificate;
15471556
install_server_certificate;
15481557
emergency_reset_server_certificate;
15491558
reset_server_certificate;

ocaml/idl/datamodel_pool.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ open Datamodel_types
1313
"sync_updates", "Indicates this pool is in the process of syncing updates";
1414
"get_updates", "Indicates this pool is in the process of getting updates";
1515
"apply_updates", "Indicates this pool is in the process of applying updates";
16+
"cert_refresh", "A certificate refresh and distribution is in progress";
1617
])
1718

1819
let enable_ha = call

ocaml/idl/schematest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let hash x = Digest.string x |> Digest.to_hex
22

33
(* BEWARE: if this changes, check that schema has been bumped accordingly *)
4-
let last_known_schema_hash = "633a99b46dda090677598aad3a830f76"
4+
let last_known_schema_hash = "632046e456380e732bb9faadde0ecb9e"
55

66
let current_schema_hash : string =
77
let open Datamodel_types in

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,15 @@ let rec cmdtable_data : (string * cmd_spec) list =
30713071
; flags= [Host_selectors]
30723072
}
30733073
)
3074+
; ( "host-refresh-server-certificate"
3075+
, {
3076+
reqd= ["host"]
3077+
; optn= []
3078+
; help= "Refresh internal server certificate of host"
3079+
; implementation= No_fd Cli_operations.host_refresh_server_certificate
3080+
; flags= [Host_selectors]
3081+
}
3082+
)
30743083
; ( "host-server-certificate-install"
30753084
, {
30763085
reqd= ["certificate"; "private-key"]

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,16 @@ let host_get_server_certificate printer rpc session_id params =
35043504
params []
35053505
)
35063506

3507+
let host_refresh_server_certificate printer rpc session_id params =
3508+
ignore
3509+
(do_host_op rpc session_id ~multiple:false
3510+
(fun _ host ->
3511+
let host = host.getref () in
3512+
Client.Host.refresh_server_certificate rpc session_id host
3513+
)
3514+
params []
3515+
)
3516+
35073517
let host_install_server_certificate fd printer rpc session_id params =
35083518
let certificate =
35093519
List.assoc "certificate" params |> get_file_or_fail fd "certificate"

ocaml/xapi-cli-server/record_util.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ let pool_operation_to_string = function
164164
"get_updates"
165165
| `apply_updates ->
166166
"apply_updates"
167+
| `cert_refresh ->
168+
"cert_refresh"
167169

168170
let host_operation_to_string = function
169171
| `provision ->

ocaml/xapi-consts/api_errors.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,8 @@ let pool_secret_rotation_pending = "POOL_SECRET_ROTATION_PENDING"
12211221

12221222
let tls_verification_enable_in_progress = "TLS_VERIFICATION_ENABLE_IN_PROGRESS"
12231223

1224+
let cert_refresh_in_progress = "CERT_REFRESH_IN_PROGRESS"
1225+
12241226
let configure_repositories_in_progress = "CONFIGURE_REPOSITORIES_IN_PROGRESS"
12251227

12261228
let invalid_base_url = "INVALID_BASE_URL"

ocaml/xapi/cert_distrib.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,17 @@ let import_joining_pool_ca_certificates ~__context ~ca_certs =
457457
Worker.local_write_cert_fs ~__context ApplianceCertificate Merge
458458
appliance_certs ;
459459
Worker.local_regen_bundle ~__context
460+
461+
let distribute_new_host_cert ~__context ~host ~content =
462+
let hosts = Db.Host.get_all ~__context in
463+
let uuid = Db.Host.get_uuid ~__context ~self:host in
464+
let file =
465+
WireProtocol.{filename= Printf.sprintf "%s.new.pem" uuid; content}
466+
in
467+
let job rpc session_id host =
468+
Worker.remote_write_certs_fs HostPoolCertificate Merge [file] host rpc
469+
session_id
470+
in
471+
Helpers.call_api_functions ~__context @@ fun rpc session_id ->
472+
List.iter (fun host -> job rpc session_id host) hosts ;
473+
List.iter (fun host -> Worker.remote_regen_bundle host rpc session_id) hosts

ocaml/xapi/cert_distrib.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ val import_joining_pool_ca_certificates :
5050
This parameter must be the result of
5151
[exchange_ca_certificates_with_joiner]. This function was designed
5252
as part of pool join and is unlikely to be useful elsewhere. *)
53+
54+
val distribute_new_host_cert :
55+
__context:Context.t -> host:[`host] API.Ref.t -> content:string -> unit
56+
(** distribute a new (additional) certificate for [host] in the pool *)

0 commit comments

Comments
 (0)