Skip to content

Commit 726c764

Browse files
committed
CA-408843: XSI-1852: Set encryption type of machine account
According to https://techcommunity.microsoft.com/blog/coreinfrastructureandsecurityblog/decrypting-the-selection-of-supported-kerberos-encryption-types/1628797 msDS-SupportedEncryptionTypes of machine account help to decide Service Ticket encryption type Some customer IT teams have strict encryption types limitation in their domains This commit add winbind_set_machine_account_kerberos_encryption_type and default to false. When enabled, xapi set the machine account encryption types consistent with the samba client Signed-off-by: Lin Liu <[email protected]>
1 parent 0441299 commit 726c764

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

ocaml/xapi-aux/kerberos_encryption_types.ml

+38
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
module Winbind = struct
2121
type t = Strong | Legacy | All
2222

23+
(*
24+
* [X] 0x00000001 DES-CBC-CRC
25+
* [X] 0x00000002 DES-CBC-MD5
26+
* [X] 0x00000004 RC4-HMAC
27+
* [X] 0x00000008 AES128-CTS-HMAC-SHA1-96
28+
* [X] 0x00000010 AES256-CTS-HMAC-SHA1-96
29+
* *)
30+
31+
let des_cbc_crc = 0x1
32+
33+
let des_cbc_md5 = 0x2
34+
35+
let rc4_hmac = 0x4
36+
37+
let aes128_cts_hmac_sha1_96 = 0x8
38+
39+
let aes256_cts_hmac_sha1_96 = 0x10
40+
2341
let to_string = function
2442
| Strong ->
2543
"strong"
@@ -28,6 +46,26 @@ module Winbind = struct
2846
| All ->
2947
"all"
3048

49+
let add x y = x lor y
50+
51+
let to_encoding = function
52+
(*
53+
* 0x00000001 DES-CBC-CRC
54+
* 0x00000002 DES-CBC-MD5
55+
* 0x00000004 RC4-HMAC
56+
* 0x00000008 AES128-CTS-HMAC-SHA1-96
57+
* 0x00000010 AES256-CTS-HMAC-SHA1-96
58+
* *)
59+
| Strong ->
60+
add aes128_cts_hmac_sha1_96 aes256_cts_hmac_sha1_96
61+
| Legacy ->
62+
rc4_hmac
63+
| All ->
64+
add des_cbc_crc des_cbc_md5
65+
|> add rc4_hmac
66+
|> add aes128_cts_hmac_sha1_96
67+
|> add aes256_cts_hmac_sha1_96
68+
3169
let of_string = function
3270
| "all" ->
3371
Some All

ocaml/xapi-aux/kerberos_encryption_types.mli

+2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ module Winbind : sig
1717

1818
val to_string : t -> string
1919

20+
val to_encoding : t -> int
21+
2022
val of_string : string -> t option
2123
end

ocaml/xapi/extauth_plugin_ADwinbind.ml

+31-1
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,35 @@ module Winbind = struct
10851085
netbios_name
10861086
) else
10871087
hostname
1088+
1089+
let set_machine_account_encryption_type netbios_name =
1090+
match !Xapi_globs.winbind_set_machine_account_kerberos_encryption_type with
1091+
| true -> (
1092+
let args =
1093+
[
1094+
"ads"
1095+
; "enctypes"
1096+
; "set"
1097+
; "--machine-pass"
1098+
; "-d"
1099+
; debug_level ()
1100+
; Printf.sprintf "%s$" netbios_name
1101+
; Printf.sprintf "%d"
1102+
(Kerberos_encryption_types.Winbind.to_encoding
1103+
!Xapi_globs.winbind_kerberos_encryption_type
1104+
)
1105+
]
1106+
in
1107+
try
1108+
Helpers.call_script
1109+
~timeout:Mtime.Span.(5 * s)
1110+
!Xapi_globs.net_cmd args
1111+
|> ignore
1112+
with _ ->
1113+
warn "Failed to set machine account encryption type, ignoring"
1114+
)
1115+
| false ->
1116+
debug "Skip setting machine account encryption type to DC"
10881117
end
10891118

10901119
module ClosestKdc = struct
@@ -1688,10 +1717,11 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
16881717
~ou_conf ~workgroup:(Some workgroup)
16891718
~machine_pwd_last_change_time:(Some machine_pwd_last_change_time)
16901719
~netbios_name:(Some netbios_name) ;
1720+
(* Trigger right now *)
16911721
ClosestKdc.trigger_update ~start:0. ;
16921722
RotateMachinePassword.trigger_rotate ~start:0. ;
16931723
ConfigHosts.join ~domain:service_name ~name:netbios_name ;
1694-
(* Trigger right now *)
1724+
Winbind.set_machine_account_encryption_type netbios_name ;
16951725
debug "Succeed to join domain %s" service_name
16961726
with
16971727
| Forkhelpers.Spawn_internal_error (_, stdout, _) ->

ocaml/xapi/xapi_globs.ml

+10
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,8 @@ let winbind_update_closest_kdc_interval = ref (3600. *. 22.)
10041004

10051005
let winbind_kerberos_encryption_type = ref Kerberos_encryption_types.Winbind.All
10061006

1007+
let winbind_set_machine_account_kerberos_encryption_type = ref false
1008+
10071009
let winbind_allow_kerberos_auth_fallback = ref false
10081010

10091011
let winbind_keep_configuration = ref false
@@ -1546,6 +1548,14 @@ let other_options =
15461548
, "Encryption types to use when operating as Kerberos client \
15471549
[strong|legacy|all]"
15481550
)
1551+
; ( "winbind_set_machine_account_kerberos_encryption_type"
1552+
, Arg.Set winbind_set_machine_account_kerberos_encryption_type
1553+
, (fun () ->
1554+
string_of_bool !winbind_set_machine_account_kerberos_encryption_type
1555+
)
1556+
, "Whether set machine account encryption type \
1557+
(msDS-SupportedEncryptionTypes) on domain controller"
1558+
)
15491559
; ( "winbind_allow_kerberos_auth_fallback"
15501560
, Arg.Set winbind_allow_kerberos_auth_fallback
15511561
, (fun () -> string_of_bool !winbind_allow_kerberos_auth_fallback)

0 commit comments

Comments
 (0)