Skip to content

Commit 4a2fa3a

Browse files
author
lev
committed
Parameterized the component test to work with an external Kerberos DC
Now run.sh requires the following variables: REUSE_DOCKER_IMAGES use cached images, only rebuild .go files SERVICE_LOG_FILTER exclude ACCESS records from the service log EXT_KDC_IP external KDC IP EXT_KDC_PORT external KDC port KEYTAB_FILE path to keytab to use for the service SERVICE_NAME name to use for the service REALM_NAME realm for the service and the user DOMAIN_NAME domain name USER_NAME username (client) USER_PASSWORD password (used for both client and service) CLIENT_IN_CONTAINER force running the client in a container, even on OS X
1 parent 47e8520 commit 4a2fa3a

13 files changed

+210
-114
lines changed

component_test/docker/client/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ RUN apt-get -y install \
1010
RUN (cd /tmp && wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz && tar xvf go1.4.1.linux-amd64.tar.gz && mv go/ /opt)
1111
ENV GOROOT="/opt/go"
1212

13-
ADD krb5.conf.template /opt/go-gssapi-test-client/krb5.conf.template
14-
ENV KRB5_CONFIG_TEMPLATE /opt/go-gssapi-test-client/krb5.conf.template
13+
ADD krb5.conf.template /tmp/krb5.conf.template
14+
ENV KRB5_CONFIG_TEMPLATE /tmp/krb5.conf.template
1515
ENV KRB5_CONFIG /opt/go-gssapi-test-client/krb5.conf
1616
ENV GSSAPI_PATH=/usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2
1717
ENV TEST_DIR=/opt/go-gssapi-test-client

component_test/docker/client/entrypoint.sh

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -eu
1+
#!/bin/bash -eu
22

33
# This script is used in the context of a docker VM when runnning the linux
44
# client test, and in the context of OS X when running on the Macintosh. The
@@ -21,26 +21,30 @@
2121
#
2222
# TEST_DIR
2323
# The directory to build the client test app in
24+
#
25+
# SERVICE_NAME
26+
# REALM_NAME
27+
# DOMAIN_NAME
28+
# USER_NAME
29+
# USER_PASSWORD
2430

2531
export PATH=$PATH:$GOROOT/bin
2632

27-
sed -e "s/KDC_ADDRESS/$KDC_PORT_88_TCP_ADDR:$KDC_PORT_88_TCP_PORT/g" \
28-
$KRB5_CONFIG_TEMPLATE > $KRB5_CONFIG
33+
cat $KRB5_CONFIG_TEMPLATE \
34+
| sed -e "s/KDC_ADDRESS/$KDC_PORT_88_TCP_ADDR:$KDC_PORT_88_TCP_PORT/g" \
35+
| sed -e "s/DOMAIN_NAME/${DOMAIN_NAME}/g" \
36+
| sed -e "s/REALM_NAME/${REALM_NAME}/g" \
37+
> $KRB5_CONFIG
2938

30-
echo P@ssword! | kinit [email protected] >/dev/null
39+
echo ${USER_PASSWORD} | kinit -V ${USER_NAME}@${REALM_NAME} >/dev/null
3140

3241
(cd $TEST_DIR && go test -c github.com/apcera/gssapi/component_test/client)
3342

34-
while ! echo exit | nc $SERVICE_PORT_80_TCP_ADDR $SERVICE_PORT_80_TCP_PORT >/dev/null; do
35-
echo "Waiting for service to start"
36-
sleep 1
37-
done
38-
43+
# --test.bench=.
44+
#--test.benchtime=2s
3945
$TEST_DIR/client.test \
40-
--test.bench=. \
4146
--test.v=false \
42-
--test.benchtime=2s \
43-
--service-name=HTTP/[email protected] \
47+
--service-name=$SERVICE_NAME \
4448
--service-address=$SERVICE_PORT_80_TCP_ADDR:$SERVICE_PORT_80_TCP_PORT \
4549
--krb5-config=$KRB5_CONFIG \
4650
--gssapi-path=$GSSAPI_PATH \
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[libdefaults]
2-
default_realm = TEST.GOGSSAPI.COM
2+
default_realm = REALM_NAME
33
noaddresses = true
44

55
[realms]
6-
TEST.GOGSSAPI.COM = {
6+
REALM_NAME = {
77
# will be replaced by the script
88
kdc = KDC_ADDRESS
99
}
1010

1111
[domain_realm]
12-
c.gogssapi.com = TEST.GOGSSAPI.COM
13-
.c.gogssapi.com = TEST.GOGSSAPI.COM
12+
DOMAIN_NAME = REALM_NAME
13+
.DOMAIN_NAME = REALM_NAME

component_test/docker/kdc/Dockerfile

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
FROM ubuntu:14.04
2+
ADD krb5.conf /etc/krb5.conf
23

34
RUN apt-get -y update
4-
ADD krb5.conf /etc/krb5.conf
55
RUN apt-get -y install heimdal-kdc
66

7+
ADD entrypoint.sh /etc/docker-kdc/entrypoint.sh
78
EXPOSE 88
8-
9-
# Create keytab folder.
10-
RUN mkdir /etc/docker-kdc
11-
12-
# Add kerberos principal/s.
13-
RUN /bin/echo -e '\n\n\n\n\n\nP@ssword!\nP@ssword!\n' | kadmin -l add HTTP/[email protected]
14-
RUN /bin/echo -e '\n\n\n\n\n\nP@ssword!\nP@ssword!\n' | kadmin -l add [email protected]
15-
16-
# Export keytab.
17-
RUN kadmin -l ext_keytab -k /etc/docker-kdc/krb5.keytab HTTP/[email protected]
18-
19-
# KDC daemon startup.
20-
#TODO -- what's in this config? Need to provide my own?
21-
ENTRYPOINT ["/usr/lib/heimdal-servers/kdc", "--config-file=/etc/heimdal-kdc/kdc.conf", "-P 88"]
9+
ENTRYPOINT /etc/docker-kdc/entrypoint.sh
2210

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash -eu
2+
3+
# Add kerberos principal/s.
4+
echo -e "\n\n\n\n\n\n${USER_PASSWORD}\n${USER_PASSWORD}\n" | kadmin -l add ${SERVICE_NAME}@${REALM_NAME}
5+
echo -e "\n\n\n\n\n\n${USER_PASSWORD}\n${USER_PASSWORD}\n" | kadmin -l add ${USER_NAME}@${REALM_NAME}
6+
kadmin -l list ${USER_NAME}@${REALM_NAME}
7+
kadmin -l list ${SERVICE_NAME}@${REALM_NAME}
8+
9+
# Export keytab.
10+
kadmin -l ext_keytab -k /etc/docker-kdc/krb5.keytab ${SERVICE_NAME}@${REALM_NAME}
11+
12+
# KDC daemon startup.
13+
#TODO -- what's relevant in this config? Need to provide my own?
14+
exec /usr/lib/heimdal-servers/kdc --config-file=/etc/heimdal-kdc/kdc.conf -P 88
15+
16+

component_test/docker/kdc/krb5.conf

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[libdefaults]
2+
default_realm = REALM_NAME
3+
noaddresses = true
4+
5+
[realms]
6+
REALM_NAME = {
7+
# will be replaced by the script
8+
kdc = KDC_ADDRESS
9+
}
10+
11+
[domain_realm]
12+
DOMAIN_NAME = REALM_NAME
13+
.DOMAIN_NAME = REALM_NAME

component_test/docker/service/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ RUN apt-get -y install \
1010
RUN (cd /tmp && wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz && tar xvf go1.4.1.linux-amd64.tar.gz && mv go/ /opt)
1111
ENV GOROOT="/opt/go"
1212
ADD krb5.keytab /opt/go-gssapi-test-service/krb5.keytab
13-
ADD krb5.conf.template /opt/go-gssapi-test-service/krb5.conf.template
13+
ADD krb5.conf.template /tmp/krb5.conf.template
1414
ADD entrypoint.sh /opt/go-gssapi-test-service/entrypoint.sh
15+
1516
EXPOSE 80
1617
ENTRYPOINT /opt/go-gssapi-test-service/entrypoint.sh

component_test/docker/service/entrypoint.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#!/bin/sh -eu
1+
#!/bin/bash -eu
22

33
export PATH=$PATH:$GOROOT/bin
44

5-
sed -e "s/KDC_ADDRESS/$KDC_PORT_88_TCP_ADDR:$KDC_PORT_88_TCP_PORT/g" \
6-
/opt/go-gssapi-test-service/krb5.conf.template \
5+
cat /tmp/krb5.conf.template \
6+
| sed -e "s/KDC_ADDRESS/$KDC_PORT_88_TCP_ADDR:$KDC_PORT_88_TCP_PORT/g" \
7+
| sed -e "s/DOMAIN_NAME/${DOMAIN_NAME}/g" \
8+
| sed -e "s/REALM_NAME/${REALM_NAME}/g" \
79
> /opt/go-gssapi-test-service/krb5.conf
810

911
(cd /opt/go-gssapi-test-service && go build github.com/apcera/gssapi/component_test/service)
1012

1113
exec /opt/go-gssapi-test-service/service \
12-
-service-name=HTTP/service.s.gogssapi.com \
14+
-service-name=${SERVICE_NAME} \
1315
-service-address=:80 \
1416
-gssapi-path=/usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 \
1517
-krb5-config=/opt/go-gssapi-test-service/krb5.conf \
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[libdefaults]
2-
default_realm = TEST.GOGSSAPI.COM
2+
default_realm = REALM_NAME
33
noaddresses = true
44

55
[realms]
6-
TEST.GOGSSAPI.COM = {
6+
REALM_NAME = {
7+
# will be replaced by the script
78
kdc = KDC_ADDRESS
89
}
910

1011
[domain_realm]
11-
s.gogssapi.com = TEST.GOGSSAPI.COM
12-
.s.gogssapi.com = TEST.GOGSSAPI.COM
12+
DOMAIN_NAME = REALM_NAME
13+
.DOMAIN_NAME = REALM_NAME

component_test/run-heimdal.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash -eu
2+
3+
REUSE_DOCKER_IMAGES="1" \
4+
SERVICE_LOG_FILTER="true" \
5+
EXT_KDC_IP="" \
6+
EXT_KDC_PORT="" \
7+
KEYTAB_FILE="" \
8+
SERVICE_NAME="HTTP/auth.www.levtest.net" \
9+
REALM_NAME="APSARA.IO" \
10+
DOMAIN_NAME="www.levtest.net" \
11+
USER_NAME="testuser" \
12+
USER_PASSWORD="P@ssword!" \
13+
CLIENT_IN_CONTAINER="" \
14+
./run.sh
15+
16+

0 commit comments

Comments
 (0)