forked from cloudera-ps/prereq-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprereq-check.sh
executable file
·1952 lines (1716 loc) · 61.6 KB
/
prereq-check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# =====================================================
# prereq-check.sh: Cloudera Manager & CDH prereq check
# =====================================================
#
# Copyright 2015-2017 Cloudera, Inc.
#
# Display relevant system information and run installation prerequisite checks
# for Cloudera Manager & CDH. For details, see README.md and
# http://www.cloudera.com/content/www/en-us/documentation/enterprise/latest/topics/installation_reqts.html.
#
# DISCLAIMER
#
# Please note: This script is released for use "AS IS" without any warranties
# of any kind, including, but not limited to their installation, use, or
# performance. We disclaim any and all warranties, either express or implied,
# including but not limited to any warranty of noninfringement,
# merchantability, and/ or fitness for a particular purpose. We do not warrant
# that the technology will meet your requirements, that the operation thereof
# will be uninterrupted or error-free, or that any errors will be corrected.
#
# Any use of these scripts and tools is at your own risk. There is no guarantee
# that they have been through thorough testing in a comparable environment and
# we are not responsible for any damage or data loss incurred with their use.
#
# You are responsible for reviewing and testing any scripts you run thoroughly
# before use in any non-testing environment.
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -u
VER=1.5.4
if [ "$(uname)" = 'Darwin' ]; then
echo -e "\nThis tool runs on Linux only, not Mac OS."
exit 1
fi
function cleanup {
rm -f /tmp/prereq-checks-cldap.pl
}
trap cleanup EXIT
# Latest version at:
# https://raw.githubusercontent.com/cloudera-ps/prereq-checks/master/prereq-check.sh
# cldap.pl ------------------------------------------------
cat << 'EOF' > /tmp/prereq-checks-cldap.pl
#!/usr/bin/perl -w
# Copyright (C) Guenther Deschner <gd@samba.org> 2006
# From https://github.com/samba-team/samba/blob/master/examples/misc/cldap.pl
use strict;
use IO::Socket;
use Convert::ASN1 qw(:debug);
use Getopt::Long;
# TODO: timeout handling, user CLDAP query
##################################
my $server = "";
my $domain = "";
my $host = "";
##################################
my (
$opt_debug,
$opt_domain,
$opt_help,
$opt_host,
$opt_server,
);
my %cldap_flags = (
ADS_PDC => 0x00000001, # DC is PDC
ADS_GC => 0x00000004, # DC is a GC of forest
ADS_LDAP => 0x00000008, # DC is an LDAP server
ADS_DS => 0x00000010, # DC supports DS
ADS_KDC => 0x00000020, # DC is running KDC
ADS_TIMESERV => 0x00000040, # DC is running time services
ADS_CLOSEST => 0x00000080, # DC is closest to client
ADS_WRITABLE => 0x00000100, # DC has writable DS
ADS_GOOD_TIMESERV => 0x00000200, # DC has hardware clock (and running time)
ADS_NDNC => 0x00000400, # DomainName is non-domain NC serviced by LDAP server
);
my %cldap_samlogon_types = (
SAMLOGON_AD_UNK_R => 23,
SAMLOGON_AD_R => 25,
);
my $MAX_DNS_LABEL = 255 + 1;
my %cldap_netlogon_reply = (
type => 0,
flags => 0x0,
guid => 0,
forest => undef,
domain => undef,
hostname => undef,
netbios_domain => undef,
netbios_hostname => undef,
unk => undef,
user_name => undef,
server_site_name => undef,
client_site_name => undef,
version => 0,
lmnt_token => 0x0,
lm20_token => 0x0,
);
sub usage {
print "usage: $0 [--domain|-d domain] [--help] [--host|-h host] [--server|-s server]\n\n";
}
sub connect_cldap ($) {
my $server = shift || return undef;
return IO::Socket::INET->new(
PeerAddr => $server,
PeerPort => 389,
Proto => 'udp',
Type => SOCK_DGRAM,
Timeout => 10,
);
}
sub send_cldap_netlogon ($$$$) {
my ($sock, $domain, $host, $ntver) = @_;
my $asn_cldap_req = Convert::ASN1->new;
$asn_cldap_req->prepare(q<
SEQUENCE {
msgid INTEGER,
[APPLICATION 3] SEQUENCE {
basedn OCTET STRING,
scope ENUMERATED,
dereference ENUMERATED,
sizelimit INTEGER,
timelimit INTEGER,
attronly BOOLEAN,
[CONTEXT 0] SEQUENCE {
[CONTEXT 3] SEQUENCE {
dnsdom_attr OCTET STRING,
dnsdom_val OCTET STRING
}
[CONTEXT 3] SEQUENCE {
host_attr OCTET STRING,
host_val OCTET STRING
}
[CONTEXT 3] SEQUENCE {
ntver_attr OCTET STRING,
ntver_val OCTET STRING
}
}
SEQUENCE {
netlogon OCTET STRING
}
}
}
>);
my $pdu_req = $asn_cldap_req->encode(
msgid => 0,
basedn => "",
scope => 0,
dereference => 0,
sizelimit => 0,
timelimit => 0,
attronly => 0,
dnsdom_attr => $domain ? 'DnsDomain' : "",
dnsdom_val => $domain ? $domain : "",
host_attr => 'Host',
host_val => $host,
ntver_attr => 'NtVer',
ntver_val => $ntver,
netlogon => 'NetLogon',
) || die "failed to encode pdu: $@";
if ($opt_debug) {
print"------------\n";
asn_dump($pdu_req);
print"------------\n";
}
return $sock->send($pdu_req) || die "no send: $@";
}
# from source/libads/cldap.c :
#
#/*
# These seem to be strings as described in RFC1035 4.1.4 and can be:
#
# - a sequence of labels ending in a zero octet
# - a pointer
# - a sequence of labels ending with a pointer
#
# A label is a byte where the first two bits must be zero and the remaining
# bits represent the length of the label followed by the label itself.
# Therefore, the length of a label is at max 64 bytes. Under RFC1035, a
# sequence of labels cannot exceed 255 bytes.
#
# A pointer consists of a 14 bit offset from the beginning of the data.
#
# struct ptr {
# unsigned ident:2; // must be 11
# unsigned offset:14; // from the beginning of data
# };
#
# This is used as a method to compress the packet by eliminated duplicate
# domain components. Since a UDP packet should probably be < 512 bytes and a
# DNS name can be up to 255 bytes, this actually makes a lot of sense.
#*/
sub pull_netlogon_string (\$$$) {
my ($ret, $ptr, $str) = @_;
my $pos = $ptr;
my $followed_ptr = 0;
my $ret_len = 0;
my $retp = pack("x$MAX_DNS_LABEL");
do {
$ptr = unpack("c", substr($str, $pos, 1));
$pos++;
if (($ptr & 0xc0) == 0xc0) {
my $len;
if (!$followed_ptr) {
$ret_len += 2;
$followed_ptr = 1;
}
my $tmp0 = $ptr; #unpack("c", substr($str, $pos-1, 1));
my $tmp1 = unpack("c", substr($str, $pos, 1));
if ($opt_debug) {
printf("tmp0: 0x%x\n", $tmp0);
printf("tmp1: 0x%x\n", $tmp1);
}
$len = (($tmp0 & 0x3f) << 8) | $tmp1;
$ptr = unpack("c", substr($str, $len, 1));
$pos = $len;
} elsif ($ptr) {
my $len = scalar $ptr;
if ($len + 1 > $MAX_DNS_LABEL) {
warn("invalid string size: %d", $len + 1);
return 0;
}
$ptr = unpack("a*", substr($str, $pos, $len));
$retp = sprintf("%s%s\.", $retp, $ptr);
$pos += $len;
if (!$followed_ptr) {
$ret_len += $len + 1;
}
}
} while ($ptr);
$retp =~ s/\.$//; #ugly hack...
$$ret = $retp;
return $followed_ptr ? $ret_len : $ret_len + 1;
}
sub dump_cldap_flags ($) {
my $flags = shift || return;
printf("Flags:\n".
"\tIs a PDC: %s\n".
"\tIs a GC of the forest: %s\n".
"\tIs an LDAP server: %s\n".
"\tSupports DS: %s\n".
"\tIs running a KDC: %s\n".
"\tIs running time services: %s\n".
"\tIs the closest DC: %s\n".
"\tIs writable: %s\n".
"\tHas a hardware clock: %s\n".
"\tIs a non-domain NC serviced by LDAP server: %s\n",
($flags & $cldap_flags{ADS_PDC}) ? "yes" : "no",
($flags & $cldap_flags{ADS_GC}) ? "yes" : "no",
($flags & $cldap_flags{ADS_LDAP}) ? "yes" : "no",
($flags & $cldap_flags{ADS_DS}) ? "yes" : "no",
($flags & $cldap_flags{ADS_KDC}) ? "yes" : "no",
($flags & $cldap_flags{ADS_TIMESERV}) ? "yes" : "no",
($flags & $cldap_flags{ADS_CLOSEST}) ? "yes" : "no",
($flags & $cldap_flags{ADS_WRITABLE}) ? "yes" : "no",
($flags & $cldap_flags{ADS_GOOD_TIMESERV}) ? "yes" : "no",
($flags & $cldap_flags{ADS_NDNC}) ? "yes" : "no");
}
sub guid_to_string ($) {
my $guid = shift || return undef;
if ((my $len = length $guid) != 16) {
printf("invalid length: %d\n", $len);
return undef;
}
my $string = sprintf "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
unpack("I", $guid),
unpack("S", substr($guid, 4, 2)),
unpack("S", substr($guid, 6, 2)),
unpack("C", substr($guid, 8, 1)),
unpack("C", substr($guid, 9, 1)),
unpack("C", substr($guid, 10, 1)),
unpack("C", substr($guid, 11, 1)),
unpack("C", substr($guid, 12, 1)),
unpack("C", substr($guid, 13, 1)),
unpack("C", substr($guid, 14, 1)),
unpack("C", substr($guid, 15, 1));
return lc($string);
}
sub recv_cldap_netlogon ($\$) {
my ($sock, $return_string) = @_;
my ($ret, $pdu_out);
$ret = $sock->recv($pdu_out, 8192) || die "failed to read from socket: $@";
#$ret = sysread($sock, $pdu_out, 8192);
if ($opt_debug) {
print"------------\n";
asn_dump($pdu_out);
print"------------\n";
}
my $asn_cldap_rep = Convert::ASN1->new;
my $asn_cldap_rep_fail = Convert::ASN1->new;
$asn_cldap_rep->prepare(q<
SEQUENCE {
msgid INTEGER,
[APPLICATION 4] SEQUENCE {
dn OCTET STRING,
SEQUENCE {
SEQUENCE {
attr OCTET STRING,
SET {
val OCTET STRING
}
}
}
}
}
SEQUENCE {
msgid2 INTEGER,
[APPLICATION 5] SEQUENCE {
error_code ENUMERATED,
matched_dn OCTET STRING,
error_message OCTET STRING
}
}
>);
$asn_cldap_rep_fail->prepare(q<
SEQUENCE {
msgid2 INTEGER,
[APPLICATION 5] SEQUENCE {
error_code ENUMERATED,
matched_dn OCTET STRING,
error_message OCTET STRING
}
}
>);
my $asn1_rep = $asn_cldap_rep->decode($pdu_out) ||
$asn_cldap_rep_fail->decode($pdu_out) ||
die "failed to decode pdu: $@";
if ($asn1_rep->{'error_code'} == 0) {
$$return_string = $asn1_rep->{'val'};
}
return $ret;
}
sub parse_cldap_reply ($) {
my $str = shift || return undef;
my %hash;
my $p = 0;
$hash{type} = unpack("L", substr($str, $p, 4)); $p += 4;
$hash{flags} = unpack("L", substr($str, $p, 4)); $p += 4;
$hash{guid} = unpack("a16", substr($str, $p, 16)); $p += 16;
$p += pull_netlogon_string($hash{forest}, $p, $str);
$p += pull_netlogon_string($hash{domain}, $p, $str);
$p += pull_netlogon_string($hash{hostname}, $p, $str);
$p += pull_netlogon_string($hash{netbios_domain}, $p, $str);
$p += pull_netlogon_string($hash{netbios_hostname}, $p, $str);
$p += pull_netlogon_string($hash{unk}, $p, $str);
if ($hash{type} == $cldap_samlogon_types{SAMLOGON_AD_R}) {
$p += pull_netlogon_string($hash{user_name}, $p, $str);
} else {
$hash{user_name} = "";
}
$p += pull_netlogon_string($hash{server_site_name}, $p, $str);
$p += pull_netlogon_string($hash{client_site_name}, $p, $str);
$hash{version} = unpack("L", substr($str, $p, 4)); $p += 4;
$hash{lmnt_token} = unpack("S", substr($str, $p, 2)); $p += 2;
$hash{lm20_token} = unpack("S", substr($str, $p, 2)); $p += 2;
return %hash;
}
sub display_cldap_reply {
my $server = shift;
my (%hash) = @_;
my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($server);
printf("Information for Domain Controller: %s\n\n", $name);
printf("Response Type: ");
if ($hash{type} == $cldap_samlogon_types{SAMLOGON_AD_R}) {
printf("SAMLOGON_USER\n");
} elsif ($hash{type} == $cldap_samlogon_types{SAMLOGON_AD_UNK_R}) {
printf("SAMLOGON\n");
} else {
printf("unknown type 0x%x, please report\n", $hash{type});
}
# guid
printf("GUID: %s\n", guid_to_string($hash{guid}));
# flags
dump_cldap_flags($hash{flags});
# strings
printf("Forest:\t\t\t%s\n", $hash{forest});
printf("Domain:\t\t\t%s\n", $hash{domain});
printf("Domain Controller:\t%s\n", $hash{hostname});
printf("Pre-Win2k Domain:\t%s\n", $hash{netbios_domain});
printf("Pre-Win2k Hostname:\t%s\n", $hash{netbios_hostname});
if ($hash{unk}) {
printf("Unk:\t\t\t%s\n", $hash{unk});
}
if ($hash{user_name}) {
printf("User name:\t%s\n", $hash{user_name});
}
printf("Server Site Name:\t%s\n", $hash{server_site_name});
printf("Client Site Name:\t%s\n", $hash{client_site_name});
# some more int
printf("NT Version:\t\t%d\n", $hash{version});
printf("LMNT Token:\t\t%.2x\n", $hash{lmnt_token});
printf("LM20 Token:\t\t%.2x\n", $hash{lm20_token});
}
sub main() {
my ($ret, $sock, $reply);
GetOptions(
'debug' => \$opt_debug,
'domain|d=s' => \$opt_domain,
'help' => \$opt_help,
'host|h=s' => \$opt_host,
'server|s=s' => \$opt_server,
);
$server = $server || $opt_server;
$domain = $domain || $opt_domain || undef;
$host = $host || $opt_host;
if (!$host) {
$host = `/bin/hostname`;
chomp($host);
}
if (!$server || !$host || $opt_help) {
usage();
exit 1;
}
my $ntver = sprintf("%c%c%c%c", 6,0,0,0);
$sock = connect_cldap($server);
if (!$sock) {
die("could not connect to $server");
}
$ret = send_cldap_netlogon($sock, $domain, $host, $ntver);
if (!$ret) {
close($sock);
die("failed to send CLDAP request to $server");
}
$ret = recv_cldap_netlogon($sock, $reply);
if (!$ret) {
close($sock);
die("failed to receive CLDAP reply from $server");
}
close($sock);
if (!$reply) {
printf("no 'NetLogon' attribute received\n");
exit 0;
}
%cldap_netlogon_reply = parse_cldap_reply($reply);
if (!%cldap_netlogon_reply) {
die("failed to parse CLDAP reply from $server");
}
display_cldap_reply($server, %cldap_netlogon_reply);
exit 0;
}
main();
EOF
# security-checks.sh ------------------------------------------------
#!/usr/bin/env bash
function check_addc() {
# the domainname passed by the caller, already checked to be non-empty
DOMAIN=$1
# the directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# the temp directory used, within $DIR
WORK_DIR=$(mktemp -d -p "${DIR}")
# check if tmp dir was created
if [[ ! ${WORK_DIR} || ! -d ${WORK_DIR} ]]; then
echo "Could not create temp dir"
exit 1
fi
function cleanup {
# FIXME This is dangerous!
rm -rf "${WORK_DIR}"
}
trap cleanup EXIT
dig -t SRV "_kerberos_tcp.${DOMAIN}" > "${WORK_DIR}/dig1.tmp"
AC=$(grep -c "AUTHORITY: 1" "${WORK_DIR}/dig1.tmp")
if [[ ${AC} -eq "1" ]]; then
AUTH=$(grep -A1 "AUTHORITY SECTION:" "${WORK_DIR}/dig1.tmp" | tail -n 1)
SOAQ=$(echo "${AUTH}" | grep -c SOA)
if [[ ${SOAQ} -eq "1" ]]; then
DC=$(echo "${AUTH}" | awk '{print $5}' | sed 's/.$//')
perl /tmp/prereq-checks-cldap.pl "${DOMAIN}" -s "${DC}" > "${WORK_DIR}/dc.tmp"
SITEN=$(grep --text "Server Site Name:" "${WORK_DIR}/dc.tmp" | awk '{print $NF}')
dig "@${DC}" -t SRV "_ldap._tcp.${SITEN}._sites.dc._msdcs.${DOMAIN}" > "${WORK_DIR}/dig2.tmp"
echo -e "AD Domain\t\t\t: ${DOMAIN}"
echo -e "Authoritative Domain Controller\t: ${DC}"
echo -e "Site Name\t\t\t: ${SITEN}"
echo -e "-----------------------------------------------------------------------------"
echo -e "# _service._proto.name.\t\tTTL\tclass\tSRV\tpriority\tweight\tport\ttarget."
grep -A 100 "ANSWER SECTION" "${WORK_DIR}/dig2.tmp" | grep -B 100 "Query time" | sed '1d' | sed '$d'
fi
else
echo "DOMAIN NOT FOUND"
fi
}
function check_privs() {
print_header "AD privilege checks"
### disable cert verification if using ldaps
export LDAPTLS_REQCERT=never
STDERR=$(ldapsearch -x -H "${ARG_LDAPURI}" -D "${ARG_BINDDN}" -b "${ARG_SEARCHBASE}" -L -w "${ARG_USERPSWD}" 2>&1 >/dev/zero)
SRCH_RESULT=$?
if [ $SRCH_RESULT -eq 0 ]; then
state "KDC Account Manager user exists" 0
RANDOM_CN=prereqchk01
ldapmodify -x -H "${ARG_LDAPURI}" -D "${ARG_BINDDN}" -w "${ARG_USERPSWD}" > /dev/zero 2> /dev/zero <<-%EOF
dn: CN=${RANDOM_CN},${ARG_SEARCHBASE}
changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
sAMAccountName: ${RANDOM_CN}
%EOF
ADD_RESULT=$?
if [ $ADD_RESULT -eq 0 ]; then
state "Create a new user principal in the OU" 0
ldapdelete -H "${ARG_LDAPURI}" -D "${ARG_BINDDN}" "CN=${RANDOM_CN},${ARG_SEARCHBASE}" -w "${ARG_USERPSWD}" > /dev/zero 2>/dev/zero
DEL_RESULT=$?
if [ $DEL_RESULT -eq 0 ]; then
state "Delete a user principal in the OU" 0
# continue on to perform Active Directory SPN uniqueness check impact
check_spn_uniqueness
else
state "Delete a user principal in the OU" 1
fi
elif [ $ADD_RESULT -eq 50 ]; then
state "Create a new user principal in the OU (reason: Insufficient access)" 1
elif [ $ADD_RESULT -eq 68 ]; then
state "Create a new user principal in the OU (reason: Already exists)" 1
else
state "Unexpected error creating a new user principal in the OU. LDAP error code = ${ADD_RESULT}" 1
fi
elif [ $SRCH_RESULT -eq 32 ]; then
state "Unable to find OU" 1
elif [ $SRCH_RESULT -eq 49 ]; then
state "Invalid KDC Account Manager credentials" 1
elif [ $SRCH_RESULT -eq 255 ]; then
state "Not able to find the LDAP server specified" 1
elif [ $SRCH_RESULT -eq 34 ]; then
state "Invalid OU DN" 1
else
state "Unexpected error contacting domain controller. LDAP error code = $SRCH_RESULT, LDAP error message: ${STDERR}" 1
fi
}
########################################################################################################
#### SPN uniqueness check - test if Cloudera will be affected by MS patch (KB5008382) for CVE-2021-42282
########################################################################################################
function check_spn_uniqueness() {
HOSTNAME=$(hostname -f)
RANDOM_CN=prereqchk03
SEARCHBASE=$(echo ${ARG_SEARCHBASE} | grep -io 'dc=.*')
ldapsearch -x -H "${ARG_LDAPURI}" -D "${ARG_BINDDN}" -w "${ARG_USERPSWD}" -b "${SEARCHBASE}" "servicePrincipalName=HTTP/${HOSTNAME}" | grep "^cn:" 2>&1 > /dev/null
SRCH_RESULT=$?
if [[ $SRCH_RESULT -eq 0 ]]; then
state "Error performing SPN alias uniqueness check. HTTP SPN already exists." 1
return
fi
ldapmodify -x -H "${ARG_LDAPURI}" -D "${ARG_BINDDN}" -w "${ARG_USERPSWD}" > /dev/zero 2>/dev/zero <<-%EOF
dn: CN=${RANDOM_CN},${ARG_SEARCHBASE}
changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
sAMAccountName: ${RANDOM_CN}
servicePrincipalName: HTTP/${HOSTNAME}
%EOF
ADD_RESULT=$?
if [ $ADD_RESULT -eq 0 ]; then
# creation of HTTP SPN succeeded
state "SPN alias uniqueness check impact (MS KB5008382 patch for CVE-2021-42282)" 0
elif [ $ADD_RESULT -eq 19 ]; then
state "SPN alias uniqueness check impact (MS KB5008382 patch for CVE-2021-42282)" 1
else
state "Unexpected error performing SPN alias uniqueness check. LDAP error code = $ADD_RESULT" 1
fi
ldapdelete -H "${ARG_LDAPURI}" -D "${ARG_BINDDN}" "CN=${RANDOM_CN},${ARG_SEARCHBASE}" -w "${ARG_USERPSWD}" > /dev/zero 2>/dev/zero
}
# cdsw-checks.sh ------------------------------------------------
#!/usr/bin/env bash
function check_localhost() {
if ! command -v dig 2&>/dev/null ; then
state "Network: 'dig' not found, skipping localhost check. Run 'sudo yum install bind-utils' to fix." 2
return
fi
ip=$(dig +short localhost)
if [[ $ip = '127.0.0.1' ]]; then
state "Network: localhost correctly resolves to 127.0.0.1" 0
else
state "Network: localhost does not resolve to 127.0.0.1" 1
fi
return
}
function check_iptable() {
NUM_RULES=$(iptables -n -L -v --line-numbers | grep -cE "^[0-9]")
state "System: iptables should not have any pre-existing rules" "$([ "$NUM_RULES" == 0 ] && echo "0" || echo "1")"
return
}
function check_wildcard_dns() {
if ! command -v dig 2&>/dev/null ; then
state "Network: 'dig' not found, skipping wildcard DNS checks. Run 'sudo yum install bind-utils' to fix." 2
return
fi
rand=$(openssl rand -hex 3)
ip=$(dig +short "$rand"."$ARG_CDSW_FQDN")
if [[ "$ip" == "$ARG_CDSW_MASTER_IP" ]]; then
state "Network: wildcard DNS correctly resolves to CDSW Master IP $ARG_CDSW_MASTER_IP" 0
else
state "Network: wildcard DNS does not resolve to the CDSW Master IP" 1
fi
return
}
function check_local_dns_port53() {
# Check if port 53 is in used by other service
if netstat -na | grep ":53 " | awk '{print $4}' | grep -qE '^(0.0.0.0|127.0.0.1)'; then
state "Network: port 53 should not be used by other service on CDSW master" 0
else
state "Network: port 53 should not be used by other service on CDSW master" 1
fi
}
function check_uid_8536() {
user=$(id -un 8536 2> /dev/null)
if [[ $? -eq 1 ]]; then
state "System: user id 8536 is not in use" 0
else
state "System: user id 8536 is used ($user)" 1
fi
return
}
function check_app_blk_dev() {
df=$(df |grep /var/lib/cdsw)
if [[ -z "$df" ]]; then
state "System: application block device for /var/lib/cdsw not found" 1
return
fi
appdev=$(echo "$df" | awk '{print $1}')
size=$(echo "$df" | awk '{print $2}')
if [[ $size -gt 1099511627776 ]]; then
state "System: found application block device $appdev with at least 1TB size mounted to /var/lib/cdsw" 0
else
state "System: found application block device $appdev but size is less than 1TB" 2
fi
return
}
function print_raw_blk_dev() {
echo "Block Devices:"
blkdev=$(lsblk -ndlp -o name,type | grep disk| awk '{print $1}')
for dev in $blkdev; do
if [[ $(lsblk -nlp "$dev" | wc -l) -gt 1 ]]; then
continue
else
# get size of device
size=$(lsblk -n -o size "$dev")
pad
# check if device has a GPT partition or MBR
output=$(blkid -o value "$dev")
if [[ $output == "dos" ]]; then
printf "%s\t%s\t%s\n" "$dev" "$size" "MBR"
elif [[ $output == "gpt" ]]; then
printf "%s\t%s\t%s\n" "$dev" "$size" "GPT"
else
printf "%s\t%s\t%s\n" "$dev" "$size" "None"
fi
fi
done
}
function check_root_vol() {
return
}
function check_cdsw() {
echo ""
echo "System information"
echo "------------------"
print_fqdn
print_os
print_cpu_and_ram
print_time
print_network
print_raw_blk_dev
echo ""
echo "CDSW prerequisite checks"
echo "------------------------"
check_uid_8536
check_app_blk_dev
check_iptable
check_localhost
check_wildcard_dns
check_local_dns_port53
return
}
# checks.sh ------------------------------------------------
#!/usr/bin/env bash
function check_jce() {
if "${1}"/bin/jrunscript -e 'exit (javax.crypto.Cipher.getMaxAllowedKeyLength("RC5") >= 256 ? 0 : 1);' > /dev/null 2>&1 ; then
state "Java: JCE Files are installed for Oracle Java: ""${candidate}""/bin/java" 0
else
state "Java: JCE Files are not installed for Oracle Java: ""${candidate}""/bin/java" 1
fi
}
function check_java() {
# The following candidate list is from CM agent:
# Starship/cmf/agents/cmf/service/common/cloudera-config.sh
local JAVA17_HOME_CANDIDATES=(
'/usr/java/jdk1.17'
'/usr/lib/jvm/jdk-17'
'/usr/lib/jvm/java-17-oracle'
)
local OPENJAVA17_HOME_CANDIDATES=(
'/usr/lib/jvm/java-17'
'/usr/lib/jvm/jdk-17'
'/usr/lib/jvm/jdk1.17'
'/usr/lib/jvm/zulu-17'
'/usr/lib/jvm/zulu17'
'/usr/lib64/jvm/java-17'
'/usr/lib64/jvm/jdk1.17'
)
local JAVA11_HOME_CANDIDATES=(
'/usr/java/jdk-11'
'/usr/lib/jvm/jdk-11'
'/usr/lib/jvm/java-11-oracle'
)
local OPENJAVA11_HOME_CANDIDATES=(
'/usr/lib/jvm/java-11'
'/usr/java/jdk-11'
'/usr/lib/jvm/jdk-11'
'/usr/lib64/jvm/jdk-11'
'/usr/lib/jvm/zulu-11'
'/usr/lib/jvm/zulu11'
'/usr/lib/jvm/java-11-zulu-openjdk'
)
local JAVA6_HOME_CANDIDATES=(
'/usr/lib/j2sdk1.6-sun'
'/usr/lib/jvm/java-6-sun'
'/usr/lib/jvm/java-1.6.0-sun-1.6.0'
'/usr/lib/jvm/j2sdk1.6-oracle'
'/usr/lib/jvm/j2sdk1.6-oracle/jre'
'/usr/java/jdk1.6'
'/usr/java/jre1.6'
)
local OPENJAVA6_HOME_CANDIDATES=(
'/usr/lib/jvm/java-1.6.0-openjdk'
'/usr/lib/jvm/jre-1.6.0-openjdk'
)
local JAVA7_HOME_CANDIDATES=(
'/usr/java/jdk1.7'
'/usr/java/jre1.7'
'/usr/lib/jvm/j2sdk1.7-oracle'
'/usr/lib/jvm/j2sdk1.7-oracle/jre'
'/usr/lib/jvm/java-7-oracle'
)
local OPENJAVA7_HOME_CANDIDATES=(
'/usr/lib/jvm/java-1.7.0-openjdk'
'/usr/lib/jvm/java-7-openjdk'
)
local JAVA8_HOME_CANDIDATES=(
'/usr/java/jdk1.8'
'/usr/java/jdk8'
'/usr/java/jre1.8'
'/usr/lib/jvm/j2sdk1.8-oracle'
'/usr/lib/jvm/j2sdk1.8-oracle/jre'
'/usr/lib/jvm/java-8-oracle'
)
local OPENJAVA8_HOME_CANDIDATES=(
'/usr/lib/jvm/java-1.8.0-openjdk'
'/usr/lib/jvm/java-8'
'/usr/lib64/jvm/java-1.8.0-openjdk'
'/usr/lib64/jvm/java-8-openjdk'
'/usr/lib/jvm/zulu-8'
'/usr/lib/jvm/zulu8'
'/usr/lib/jvm/java-8-zulu-openjdk'
)
local MISCJAVA_HOME_CANDIDATES=(
'/Library/Java/Home'
'/usr/java/default'
'/usr/lib/jvm/default-java'
'/usr/lib/jvm/java-openjdk'
'/usr/lib/jvm/jre-openjdk'
)
local JAVA_HOME_CANDIDATES=(
"${JAVA17_HOME_CANDIDATES[@]}"
"${JAVA11_HOME_CANDIDATES[@]}"
"${JAVA7_HOME_CANDIDATES[@]}"
"${JAVA8_HOME_CANDIDATES[@]}"
"${JAVA6_HOME_CANDIDATES[@]}"
"${MISCJAVA_HOME_CANDIDATES[@]}"
"${OPENJAVA17_HOME_CANDIDATES[@]}"
"${OPENJAVA11_HOME_CANDIDATES[@]}"
"${OPENJAVA7_HOME_CANDIDATES[@]}"
"${OPENJAVA8_HOME_CANDIDATES[@]}"
"${OPENJAVA6_HOME_CANDIDATES[@]}"
)
function get_jdk_type() {
java=$1
JDK_TYPE=$($java -version 2>&1 | head -2 | tail -1 | awk '{print $1}')
case $JDK_TYPE in
Java\(TM\) )
echo "Oracle";;
OpenJDK )
if [[ -z $($java -version 2>&1 | head -2 | tail -1 |grep Zulu) ]]; then
echo "OpenJDK"
else
echo "Azul"
fi
;;
* )
echo "Unknown";;
esac
}
# https://docs.cloudera.com/cdp-private-cloud-base/7.1.9/installation/topics/cdpdc-java-requirements.html
# JDK 8 minimum required version is 1.8u181
# OpenJDK 8 minimum required version is 1.8u232
# Azul JDK 8 minimum required version is 8.56.0.21
java_found=false
for candidate_regex in "${JAVA_HOME_CANDIDATES[@]}"; do
# shellcheck disable=SC2045,SC2086
for candidate in $(ls -rvd ${candidate_regex}* 2>/dev/null); do
if [ -x "$candidate/bin/java" ]; then
java_found=true
JDK_VERSION=$($candidate/bin/java -version 2>&1 | head -1 | awk '{print $3}' | tr -d '"')
JDK_VERSION_REGEX='(1|11)\.([0-9])\.([0-9_]*)'
JDK_8_MINOR_VERSION_REGEX='1\.8\.0_([0-9]*)'
JDK_TYPE=$(get_jdk_type "$candidate/bin/java")
support=true
if [[ $JDK_VERSION =~ $JDK_VERSION_REGEX ]]; then
if [[ ${BASH_REMATCH[1]} -eq 1 ]]; then
if [[ ${BASH_REMATCH[2]} -eq 8 ]]; then
if [[ $JDK_TYPE == "Azul" ]]; then
# Azul JDK 1.8.0_XXX
# Azul JDK uses a different build versioning convention
AZUL_BUILD=$($candidate/bin/java -version 2>&1 | head -2 | tail -1 | awk '{print $5}' | cut -d'-' -f1)
AZUL_BUILD_REGEX='8\.([0-9]*)\.([0-9]*)\.([0-9]*)'
if [[ $AZUL_BUILD =~ $AZUL_BUILD_REGEX ]]; then
# Check if Azul build is lower than 8.56.0.21 which is the minimum required version
if [[ ${BASH_REMATCH[1]} -lt 56 ]]; then
support=false
elif [[ ${BASH_REMATCH[1]} -eq 56 ]] && [[ ${BASH_REMATCH[3]} -lt 21 ]]; then
support=false
else
support=true
fi
else
support=false
fi
else
# Oracle or OpenJDK 1.8.0_XXX
if [[ $JDK_VERSION =~ $JDK_8_MINOR_VERSION_REGEX ]]; then
if [[ $JDK_TYPE == "Oracle" ]] && [[ ${BASH_REMATCH[1]} -lt 181 ]]; then
support=false
elif [[ $JDK_TYPE == "OpenJDK" ]] && [[ ${BASH_REMATCH[1]} -lt 232 ]]; then
support=false
else
support=true
fi
else
support=false
fi
fi
else