Skip to content

Commit 711e79b

Browse files
author
Lin Liu
committed
CP-309847: Make HTTP/80 configurable
- Introduce https_only argument for Host.create - Set https_only from configuration for installation - Keep https_only from joining host during pool join Signed-off-by: Lin Liu <[email protected]>
1 parent 9de38ef commit 711e79b

File tree

8 files changed

+28
-7
lines changed

8 files changed

+28
-7
lines changed

ocaml/idl/datamodel_host.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,14 @@ let create_params =
13981398
; param_release= numbered_release "25.32.0-next"
13991399
; param_default= Some (VMap [])
14001400
}
1401+
; {
1402+
param_type= Bool
1403+
; param_name= "https_only"
1404+
; param_doc=
1405+
"updates firewall to open or close port 80 depending on the value"
1406+
; param_release= numbered_release "25.38.0"
1407+
; param_default= Some (VBool false)
1408+
}
14011409
]
14021410

14031411
let create =
@@ -1416,6 +1424,7 @@ let create =
14161424
--console_idle_timeout --ssh_auto_mode options to allow them to be \
14171425
configured for new host"
14181426
)
1427+
; (Changed, "25.38.0", "Added --https_only to disable http")
14191428
]
14201429
~versioned_params:create_params ~doc:"Create a new host record"
14211430
~result:(Ref _host, "Reference to the newly created host object.")

ocaml/tests/common/test_common.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
175175
?(last_software_update = Date.epoch) ?(last_update_hash = "")
176176
?(ssh_enabled = true) ?(ssh_enabled_timeout = 0L) ?(ssh_expiry = Date.epoch)
177177
?(console_idle_timeout = 0L) ?(ssh_auto_mode = false) ?(secure_boot = false)
178-
() =
178+
?(https_only = false) () =
179179
let host =
180180
Xapi_host.create ~__context ~uuid ~name_label ~name_description ~hostname
181181
~address ~external_auth_type ~external_auth_service_name
@@ -184,6 +184,7 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
184184
~last_update_hash ~ssh_enabled ~ssh_enabled_timeout ~ssh_expiry
185185
~console_idle_timeout ~ssh_auto_mode ~secure_boot
186186
~software_version:(Xapi_globs.software_version ())
187+
~https_only
187188
in
188189
Db.Host.set_cpu_info ~__context ~self:host ~value:default_cpu_info ;
189190
host
@@ -194,15 +195,14 @@ let make_host2 ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
194195
?(external_auth_type = "") ?(external_auth_service_name = "")
195196
?(external_auth_configuration = []) ?(license_params = [])
196197
?(edition = "free") ?(license_server = []) ?(local_cache_sr = Ref.null)
197-
?(chipset_info = []) ?(ssl_legacy = false) () =
198+
?(chipset_info = []) ?(ssl_legacy = false) ?(https_only = false) () =
198199
let pool = Helpers.get_pool ~__context in
199200
let tls_verification_enabled =
200201
Db.Pool.get_tls_verification_enabled ~__context ~self:pool
201202
in
202203
Db.Host.create ~__context ~ref ~current_operations:[] ~allowed_operations:[]
203204
~software_version:(Xapi_globs.software_version ())
204-
~https_only:false ~enabled:false
205-
~aPI_version_major:Datamodel_common.api_version_major
205+
~enabled:false ~aPI_version_major:Datamodel_common.api_version_major
206206
~aPI_version_minor:Datamodel_common.api_version_minor
207207
~aPI_version_vendor:Datamodel_common.api_version_vendor
208208
~aPI_version_vendor_implementation:
@@ -224,7 +224,7 @@ let make_host2 ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
224224
~pending_guidances_recommended:[] ~pending_guidances_full:[]
225225
~last_update_hash:"" ~ssh_enabled:true ~ssh_enabled_timeout:0L
226226
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ~ssh_auto_mode:false
227-
~secure_boot:false ;
227+
~secure_boot:false ~https_only ;
228228
ref
229229

230230
let make_pif ~__context ~network ~host ?(device = "eth0")

ocaml/tests/test_host.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let add_host __context name =
2727
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Clock.Date.epoch
2828
~console_idle_timeout:0L ~ssh_auto_mode:false ~secure_boot:false
2929
~software_version:(Xapi_globs.software_version ())
30+
~https_only:false
3031
)
3132

3233
(* Creates an unlicensed pool with the maximum number of hosts *)

ocaml/xapi/dbsync_slave.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ let create_localhost ~__context info =
6666
~console_idle_timeout:Constants.default_console_idle_timeout
6767
~ssh_auto_mode:!Xapi_globs.ssh_auto_mode_default
6868
~secure_boot:false ~software_version:[]
69+
~https_only:!Xapi_globs.https_only
6970
in
7071
()
7172

ocaml/xapi/xapi_globs.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,8 @@ let xapi_requests_cgroup =
11331133

11341134
let genisoimage_path = ref "/usr/bin/genisoimage"
11351135

1136+
let https_only = ref false
1137+
11361138
(* Event.{from,next} batching delays *)
11371139
let make_batching name ~delay_before ~delay_between =
11381140
let name = Printf.sprintf "%s_delay" name in
@@ -1834,6 +1836,11 @@ let other_options =
18341836
, (fun () -> string_of_int !max_span_depth)
18351837
, "The maximum depth to which spans are recorded in a trace in Tracing"
18361838
)
1839+
; ( "https-only-default"
1840+
, Arg.Set https_only
1841+
, (fun () -> string_of_bool !https_only)
1842+
, "Only expose HTTPS service, disable HTTP/80 in firewall when set to true"
1843+
)
18371844
; ( "firewall-backend"
18381845
, Arg.String
18391846
(fun s ->

ocaml/xapi/xapi_host.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10291029
~license_params ~edition ~license_server ~local_cache_sr ~chipset_info
10301030
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled
10311031
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode
1032-
~secure_boot ~software_version =
1032+
~secure_boot ~software_version ~https_only =
10331033
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent
10341034
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during
10351035
the initial setup of the database *)
@@ -1064,7 +1064,7 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10641064
(* no or multiple pools *)
10651065
in
10661066
Db.Host.create ~__context ~ref:host ~current_operations:[]
1067-
~allowed_operations:[] ~https_only:false ~software_version ~enabled:false
1067+
~allowed_operations:[] ~https_only ~software_version ~enabled:false
10681068
~aPI_version_major:Datamodel_common.api_version_major
10691069
~aPI_version_minor:Datamodel_common.api_version_minor
10701070
~aPI_version_vendor:Datamodel_common.api_version_vendor

ocaml/xapi/xapi_host.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ val create :
138138
-> ssh_auto_mode:bool
139139
-> secure_boot:bool
140140
-> software_version:(string * string) list
141+
-> https_only:bool
141142
-> [`host] Ref.t
142143

143144
val destroy : __context:Context.t -> self:API.ref_host -> unit

ocaml/xapi/xapi_pool.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
10331033
create_or_get_sr_on_master __context rpc session_id
10341034
(my_local_cache_sr, my_local_cache_sr_rec)
10351035
in
1036+
10361037
debug "Creating host object on master" ;
10371038
let ref =
10381039
Client.Host.create ~rpc ~session_id ~uuid:my_uuid
@@ -1060,6 +1061,7 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
10601061
~ssh_auto_mode:host.API.host_ssh_auto_mode
10611062
~secure_boot:host.API.host_secure_boot
10621063
~software_version:host.API.host_software_version
1064+
~https_only:host.API.host_https_only
10631065
in
10641066
(* Copy other-config into newly created host record: *)
10651067
no_exn

0 commit comments

Comments
 (0)