Skip to content

Commit e822cfd

Browse files
gaborgsomogyiMartijnVisser
authored andcommitted
[FLINK-30024][tests] Build local test KDC docker image
1 parent e5762a5 commit e822cfd

File tree

19 files changed

+154
-65
lines changed

19 files changed

+154
-65
lines changed

flink-end-to-end-tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test-scripts/temp-test-directory*
2+
test-scripts/docker-hadoop-secure-cluster/hadoop/hadoop.tar.gz

flink-end-to-end-tests/test-scripts/common_yarn_docker.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,10 @@ function build_image() {
100100
echo "Pre-downloading Hadoop tarball"
101101
local cache_path
102102
cache_path=$(get_artifact "http://archive.apache.org/dist/hadoop/common/hadoop-2.8.5/hadoop-2.8.5.tar.gz")
103-
ln "${cache_path}" "${END_TO_END_DIR}/test-scripts/docker-hadoop-secure-cluster/hadoop-2.8.5.tar.gz"
103+
ln "${cache_path}" "${END_TO_END_DIR}/test-scripts/docker-hadoop-secure-cluster/hadoop/hadoop.tar.gz"
104104

105105
echo "Building Hadoop Docker container"
106-
docker build --build-arg HADOOP_VERSION=2.8.5 \
107-
-f "${END_TO_END_DIR}/test-scripts/docker-hadoop-secure-cluster/Dockerfile" \
108-
-t flink/docker-hadoop-secure-cluster:latest \
109-
"${END_TO_END_DIR}/test-scripts/docker-hadoop-secure-cluster/"
106+
docker-compose -f "${END_TO_END_DIR}/test-scripts/docker-hadoop-secure-cluster/docker-compose.yml" build
110107
}
111108

112109
function start_hadoop_cluster_and_prepare_flink() {

flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/README.md

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
# Apache Hadoop Docker image with Kerberos enabled
22

3-
This image is modified version of Knappek/docker-hadoop-secure
4-
* Knappek/docker-hadoop-secure <https://github.com/Knappek/docker-hadoop-secure>
5-
6-
With bits and pieces added from Lewuathe/docker-hadoop-cluster to extend it to start a proper kerberized Hadoop cluster:
7-
* Lewuathe/docker-hadoop-cluster <https://github.com/Lewuathe/docker-hadoop-cluster>
8-
9-
And a lot of added stuff for making this an actual, properly configured, kerberized cluster with proper user/permissions structure.
10-
11-
Versions
12-
--------
3+
Required versions
4+
-----------------
135

146
* JDK8
157
* Hadoop 2.8.5
168

179
Default Environment Variables
1810
-----------------------------
1911

20-
| Name | Value | Description |
21-
| ---- | ---- | ---- |
22-
| `KRB_REALM` | `EXAMPLE.COM` | The Kerberos Realm, more information [here](https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html#) |
23-
| `DOMAIN_REALM` | `example.com` | The Kerberos Domain Realm, more information [here](https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html#) |
24-
| `KERBEROS_ADMIN` | `admin/admin` | The KDC admin user |
25-
| `KERBEROS_ADMIN_PASSWORD` | `admin` | The KDC admin password |
12+
| Name | Value | Description |
13+
|---------------------------| ---- |-------------------------------------------------------------------------------------------------------------------------------------------------|
14+
| `KRB_REALM` | `EXAMPLE.COM` | The Kerberos Realm, more information [here](https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html#) |
15+
| `DOMAIN_REALM` | `example.com` | The Kerberos Domain Realm, more information [here](https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html#) |
16+
| `KERB_MASTER_KEY` | `masterkey` | The Kerberos master database password, more information [here](https://web.mit.edu/kerberos/krb5-1.12/doc/admin/admin_commands/kdb5_util.html#) |
17+
| `KERBEROS_ADMIN_USER` | `admin/admin` | The KDC admin user |
18+
| `KERBEROS_ADMIN_PASSWORD` | `admin` | The KDC admin password |
2619

2720
You can simply define these variables in the `docker-compose.yml`.
2821

2922
Run image
3023
---------
3124

32-
Clone the [project](https://git-wip-us.apache.org/repos/asf/flink.git) and run
33-
3425
```
26+
cd flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster
27+
wget -O hadoop/hadoop.tar.gz https://archive.apache.org/dist/hadoop/common/hadoop-2.8.5/hadoop-2.8.5.tar.gz
28+
docker-compose build
3529
docker-compose up
3630
```
3731

@@ -44,7 +38,6 @@ Get the container name with `docker ps` and login to the container with
4438
docker exec -it <container-name> /bin/bash
4539
```
4640

47-
4841
To obtain a Kerberos ticket, execute
4942

5043
```
@@ -57,7 +50,6 @@ Afterwards you can use `hdfs` CLI like
5750
hdfs dfs -ls /
5851
```
5952

60-
6153
Known issues
6254
------------
6355

@@ -74,17 +66,6 @@ Login failure for nn/[email protected] from keytab /etc/security/key
7466

7567
Stop the containers with `docker-compose down` and start again with `docker-compose up -d`.
7668

77-
78-
### JDK 8
79-
80-
Make sure you use download a JDK version that is still available. Old versions can be deprecated by Oracle and thus the download link won't be able anymore.
81-
82-
Get the latest JDK8 Download URL with
83-
84-
```
85-
curl -s https://lv.binarybabel.org/catalog-api/java/jdk8.json
86-
```
87-
8869
### Java Keystore
8970

9071
If the Keystore has been expired, then create a new `keystore.jks`:

flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/docker-compose.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ networks:
2323

2424
services:
2525
kdc:
26+
build: kdc
2627
container_name: "kdc"
2728
hostname: kdc.kerberos.com
28-
image: sequenceiq/kerberos
29+
image: flink/test-kdc:latest
2930
networks:
3031
- docker-hadoop-cluster-network
3132
environment:
3233
REALM: EXAMPLE.COM
3334
DOMAIN_REALM: kdc.kerberos.com
3435

3536
master:
36-
image: ${DOCKER_HADOOP_IMAGE_NAME:-flink/docker-hadoop-secure-cluster:latest}
37+
build: hadoop
38+
image: ${DOCKER_HADOOP_IMAGE_NAME:-flink/test-hadoop:latest}
3739
command: master
3840
depends_on:
3941
- kdc
@@ -46,7 +48,8 @@ services:
4648
DOMAIN_REALM: kdc.kerberos.com
4749

4850
worker1:
49-
image: ${DOCKER_HADOOP_IMAGE_NAME:-flink/docker-hadoop-secure-cluster:latest}
51+
build: hadoop
52+
image: ${DOCKER_HADOOP_IMAGE_NAME:-flink/test-hadoop:latest}
5053
command: worker
5154
depends_on:
5255
- kdc
@@ -60,7 +63,8 @@ services:
6063
DOMAIN_REALM: kdc.kerberos.com
6164

6265
worker2:
63-
image: ${DOCKER_HADOOP_IMAGE_NAME:-flink/docker-hadoop-secure-cluster:latest}
66+
build: hadoop
67+
image: ${DOCKER_HADOOP_IMAGE_NAME:-flink/test-hadoop:latest}
6468
command: worker
6569
depends_on:
6670
- kdc

flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/Dockerfile renamed to flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/hadoop/Dockerfile

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ RUN set -x \
5353

5454
RUN sed -i 's/^#crypto.policy=unlimited/crypto.policy=unlimited/' $JAVA_HOME/jre/lib/security/java.security
5555

56-
ARG HADOOP_VERSION=2.8.5
57-
58-
COPY hadoop-${HADOOP_VERSION}.tar.gz /tmp/hadoop.tar.gz
56+
COPY hadoop.tar.gz /tmp/hadoop.tar.gz
5957

6058
RUN set -x \
61-
&& tar -xf /tmp/hadoop.tar.gz -C /usr/local/ \
59+
&& mkdir -p /usr/local/hadoop \
60+
&& tar -xf /tmp/hadoop.tar.gz --strip-components=1 -C /usr/local/hadoop \
6261
&& rm /tmp/hadoop.tar.gz*
6362

6463
WORKDIR /usr/local
6564
RUN set -x \
66-
&& ln -s /usr/local/hadoop-${HADOOP_VERSION} /usr/local/hadoop \
67-
&& chown root:root -R /usr/local/hadoop-${HADOOP_VERSION}/ \
6865
&& chown root:root -R /usr/local/hadoop/ \
6966
&& chown root:yarn /usr/local/hadoop/bin/container-executor \
7067
&& chmod 6050 /usr/local/hadoop/bin/container-executor \
@@ -90,7 +87,7 @@ ENV PATH $PATH:$HADOOP_BIN_HOME
9087

9188
ENV KRB_REALM EXAMPLE.COM
9289
ENV DOMAIN_REALM example.com
93-
ENV KERBEROS_ADMIN admin/admin
90+
ENV KERBEROS_ADMIN_USER admin/admin
9491
ENV KERBEROS_ADMIN_PASSWORD admin
9592
ENV KEYTAB_DIR /etc/security/keytabs
9693

@@ -136,11 +133,9 @@ EXPOSE 8030 8031 8032 8033 8040 8042 8088 8188
136133
# Other ports
137134
EXPOSE 49707 2122
138135

139-
ADD bootstrap.sh /etc/bootstrap.sh
140-
RUN chown root:root /etc/bootstrap.sh
141-
RUN chmod 700 /etc/bootstrap.sh
142-
143-
ENV BOOTSTRAP /etc/bootstrap.sh
136+
ADD entrypoint.sh /entrypoint.sh
137+
RUN chown root:root /entrypoint.sh
138+
RUN chmod 700 /entrypoint.sh
144139

145-
ENTRYPOINT ["/etc/bootstrap.sh"]
140+
ENTRYPOINT ["/entrypoint.sh"]
146141
CMD ["-h"]

flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/bootstrap.sh renamed to flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/hadoop/entrypoint.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ sed -i "s#/usr/local/hadoop/bin/container-executor#${NM_CONTAINER_EXECUTOR_PATH}
5353
# we retry the first call because it can happen that Kerberos is not ready in
5454
# time
5555
start_time=$(date +%s)
56-
until kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey hdfs/$(hostname -f)@${KRB_REALM}"; do
56+
until kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey hdfs/$(hostname -f)@${KRB_REALM}"; do
5757
current_time=$(date +%s)
5858
time_diff=$((current_time - start_time))
5959

@@ -66,13 +66,13 @@ until kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -ra
6666
fi
6767
done
6868

69-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey mapred/$(hostname -f)@${KRB_REALM}"
70-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey yarn/$(hostname -f)@${KRB_REALM}"
71-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey HTTP/$(hostname -f)@${KRB_REALM}"
69+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey mapred/$(hostname -f)@${KRB_REALM}"
70+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey yarn/$(hostname -f)@${KRB_REALM}"
71+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey HTTP/$(hostname -f)@${KRB_REALM}"
7272

73-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k hdfs.keytab hdfs/$(hostname -f) HTTP/$(hostname -f)"
74-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k mapred.keytab mapred/$(hostname -f) HTTP/$(hostname -f)"
75-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k yarn.keytab yarn/$(hostname -f) HTTP/$(hostname -f)"
73+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k hdfs.keytab hdfs/$(hostname -f) HTTP/$(hostname -f)"
74+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k mapred.keytab mapred/$(hostname -f) HTTP/$(hostname -f)"
75+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k yarn.keytab yarn/$(hostname -f) HTTP/$(hostname -f)"
7676

7777
mkdir -p ${KEYTAB_DIR}
7878
mv hdfs.keytab ${KEYTAB_DIR}
@@ -104,11 +104,11 @@ elif [ "$1" == "master" ]; then
104104
nohup sudo -E -u mapred $HADOOP_PREFIX/bin/mapred historyserver 2>> /var/log/hadoop/historyserver.err >> /var/log/hadoop/historyserver.out &
105105

106106

107-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey root@${KRB_REALM}"
108-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k /root/root.keytab root"
107+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -randkey root@${KRB_REALM}"
108+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k /root/root.keytab root"
109109

110-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -pw hadoop-user hadoop-user@${KRB_REALM}"
111-
kadmin -p ${KERBEROS_ADMIN} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k /home/hadoop-user/hadoop-user.keytab hadoop-user"
110+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "addprinc -pw hadoop-user hadoop-user@${KRB_REALM}"
111+
kadmin -p ${KERBEROS_ADMIN_USER} -w ${KERBEROS_ADMIN_PASSWORD} -q "xst -k /home/hadoop-user/hadoop-user.keytab hadoop-user"
112112
chown hadoop-user:hadoop-user /home/hadoop-user/hadoop-user.keytab
113113

114114
kinit -kt /root/root.keytab root
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
################################################################################
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
################################################################################
18+
19+
FROM debian:bullseye
20+
21+
ENV DEBIAN_FRONTEND noninteractive
22+
# The -qq implies --yes
23+
RUN apt-get -qq update
24+
RUN apt-get -qq install locales krb5-kdc krb5-admin-server
25+
RUN apt-get -qq clean
26+
27+
RUN locale-gen "en_US.UTF-8"
28+
RUN echo "LC_ALL=\"en_US.UTF-8\"" >> /etc/default/locale
29+
30+
EXPOSE 88 749
31+
32+
ADD entrypoint.sh /entrypoint.sh
33+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash -x
2+
################################################################################
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
################################################################################
19+
20+
: "${KRB_REALM:=EXAMPLE.COM}"
21+
: "${DOMAIN_REALM:=example.com}"
22+
: "${KERB_MASTER_KEY:=masterkey}"
23+
: "${KERB_ADMIN_USER:=admin}"
24+
: "${KERB_ADMIN_PASS:=admin}"
25+
26+
create_config() {
27+
: "${KDC_ADDRESS:=$(hostname -f)}"
28+
29+
cat>/etc/krb5.conf<<EOF
30+
[logging]
31+
default = FILE:/var/log/kerberos/krb5libs.log
32+
kdc = FILE:/var/log/kerberos/krb5kdc.log
33+
admin_server = FILE:/var/log/kerberos/kadmind.log
34+
35+
[libdefaults]
36+
default_realm = ${KRB_REALM}
37+
dns_lookup_realm = false
38+
dns_lookup_kdc = false
39+
ticket_lifetime = 24h
40+
renew_lifetime = 7d
41+
forwardable = true
42+
43+
[realms]
44+
${KRB_REALM} = {
45+
kdc = ${KDC_ADDRESS}
46+
admin_server = ${KDC_ADDRESS}
47+
}
48+
49+
[domain_realm]
50+
.$DOMAIN_REALM = ${KRB_REALM}
51+
$DOMAIN_REALM = ${KRB_REALM}
52+
EOF
53+
}
54+
55+
create_db() {
56+
/usr/sbin/kdb5_util -P ${KERB_MASTER_KEY} -r ${KRB_REALM} create -s
57+
}
58+
59+
create_admin_user() {
60+
kadmin.local -q "addprinc -pw ${KERB_ADMIN_PASS} ${KERB_ADMIN_USER}/admin"
61+
echo "*/admin@${KRB_REALM} *" > /etc/krb5kdc/kadm5.acl
62+
}
63+
64+
start_kdc() {
65+
/usr/sbin/krb5kdc
66+
/usr/sbin/kadmind
67+
}
68+
69+
main() {
70+
mkdir -p /var/log/kerberos
71+
create_config
72+
create_db
73+
create_admin_user
74+
start_kdc
75+
tail -F /var/log/kerberos/krb5kdc.log
76+
}
77+
78+
main "$@"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ under the License.
14891489
<exclude>flink-table/flink-table-planner/src/test/resources/json/*.json</exclude>
14901490
<exclude>flink-yarn/src/test/resources/krb5.keytab</exclude>
14911491
<exclude>flink-end-to-end-tests/test-scripts/test-data/**</exclude>
1492-
<exclude>flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/config/keystore.jks</exclude>
1492+
<exclude>flink-end-to-end-tests/test-scripts/docker-hadoop-secure-cluster/hadoop/config/keystore.jks</exclude>
14931493
<exclude>flink-connectors/flink-connector-kafka/src/test/resources/**</exclude>
14941494
<exclude>flink-connectors/flink-connector-hive/src/test/resources/**</exclude>
14951495
<exclude>flink-end-to-end-tests/flink-tpcds-test/tpcds-tool/answer_set/*</exclude>

0 commit comments

Comments
 (0)