File: debugging.md

package info (click to toggle)
python-pyspnego 0.10.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,648 kB
  • sloc: python: 16,191; sh: 182; makefile: 11
file content (247 lines) | stat: -rw-r--r-- 5,501 bytes parent folder | download
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
# Debugging Tips

A lot of behaviour in this authentication process relies on functions in the KRB5 system libraries. This page aims to
document how to create a debuggable build of MIT KRB5.


## Debugging MIT KRB5

```bash
# docker run --rm -it fedora:34 /bin/bash

dnf install -y \
  autoconf \
  automake \
  byacc \
  diffutils \
  findutils \
  gcc \
  gettext \
  git \
  libtool \
  libunistring-devel \
  make \
  openssl-devel \
  python \
  python-devel \
  python-pip \
  zlib-devel

pushd /tmp
git clone https://github.com/krb5/krb5.git

pushd krb5/src
autoreconf -f -i
./configure CFLAGS=-g
make CFLAGS=-g
make install DESTDIR=/opt/krb5-src

export PATH=/opt/krb5-src/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/opt/krb5-src/usr/local/lib:$LD_LIBRARY_PATH

popd

git clone https://github.com/gssapi/gss-ntlmssp.git
pushd gss-ntlmssp

autoreconf -f -i

CFLAGS="-I/opt/krb5-src/usr/local/include -g" \
  LDFLAGS="-L/opt/krb5-src/usr/local/lib -Wl,-rpath=/opt/krb5-src/usr/local/lib" \
  ./configure \
  --prefix=/opt/gss-ntlmssp \
  --with-wbclient=no \
  --with-manpages=no

echo "gssntlmssp_v1    1.3.6.1.4.1.311.2.2.10    /opt/gss-ntlmssp/lib/gssntlmssp/gssntlmssp.so" > /tmp/krb-mechs.conf
export GSS_MECH_CONFIG=/tmp/krb-mechs.conf

git clone https://github.com/pythongssapi/python-gssapi.git
pushd python-gssapi

pip install Cython wheel
GSSAPI_LINKER_ARGS="-L/opt/krb5-src/usr/local/lib -L/usr/local/lib -Wl,--enable-new-dtags -Wl,-rpath -Wl,/opt/krb5-src/usr/local/lib -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err" \
  GSSAPI_COMPILER_ARGS="-I/opt/krb5-src/usr/local/include -I/usr/local/include -DHAS_GSSAPI_EXT_H" \
  python setup.py bdist_wheel
  
pip install dist/gssapi-*.whl

popd
popd
```


## Debugging Heimdal KRb5

```bash
# docker run --rm -it fedora:34 /bin/bash

dnf install -y \
  autoconf \
  automake \
  byacc \
  flex \
  libtool \
  make \
  ncurses-devel \
  perl-JSON \
  python \
  python-devel \
  python-pip \
  texinfo \
  git

pushd /tmp
git clone https://github.com/heimdal/heimdal.git

pushd heimdal
autoreconf -f -i
./configure CFLAGS=-g --prefix="/opt/heimdal-src" --disable-otp

# https://github.com/heimdal/heimdal/issues/794
cp ./lib/libedit/src/vis.h include/

make CFLAGS=-g
make install
popd

git clone https://github.com/pythongssapi/python-gssapi.git
pushd python-gssapi

pip install Cython wheel
GSSAPI_LINKER_ARGS="$(/opt/heimdal-src/bin/krb5-config --libs gssapi)" \
  GSSAPI_COMPILER_ARGS="$(/opt/heimdal-src/bin/krb5-config --cflags gssapi)" \
  GSSAPI_MAIN_LIB="/opt/heimdal-src/lib/libgssapi.so" \
  python setup.py bdist_wheel
pip install dist/gssapi-*.whl

popd
popd
```

## Setting up Linux KDC

Here are some commands to run to set up a KDC inside a docker container. This is mostly just a way to test out various
scenarios against the different packages. The username created is `admin@DOMAIN.LOCAL` with the password `password`.

### MIT KRB5

```bash
HOSTNAME=$(hostname)
REALM=domain.local
USERNAME=admin
PASSWORD=password

yum install -y epel-release
yum install -y \
  gcc \
  gssntlmssp \
  krb5-devel \
  krb5-server \
  krb5-workstation \
  python3 \
  python3-devel \
  python3-pip \
  vim

echo -e "127.0.0.1\t$HOSTNAME.$REALM" >> /etc/hosts

cat > /etc/krb5.conf <<EOL
[libdefaults]
  default_realm = ${REALM^^}
  dns_lookup_realm = false
  dns_lookup_kdc = false

[realms]
  ${REALM^^} = {
    kdc = ${HOSTNAME,,}.${REALM,,}
    admin_server = ${HOSTNAME,,}.${REALM,,}
  }

[domain_realm]
  .${REALM,,} = ${REALM^^}
  ${REALM,,} = ${REALM^^}
EOL

echo -e "*/*@${REALM^^}\t*" > /var/kerberos/krb5kdc/kadm5.acl

# Create the new realm
echo -e "$PASSWORD\n$PASSWORD" | /usr/sbin/kdb5_util create -r ${REALM^^}

# Create the user principal
kadmin.local -q "addprinc -pw $PASSWORD $USERNAME"

# Create the SPNs and add it to the /etc/krb5.keytab
kadmin.local -q "addprinc -randkey host/$HOSTNAME@${REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab host/$HOSTNAME@${REALM^^}"

kadmin.local -q "addprinc -randkey host/${HOSTNAME^^}@${REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab host/${HOSTNAME^^}@${REALM^^}"

# Start the KDC service
/usr/sbin/krb5kdc

pip3 install gssapi
```

### Heimdal

```bash
HOSTNAME=$(hostname)
REALM=domain.local
USERNAME=admin
PASSWORD=password

yum install -y epel-release
yum install -y \
  gcc \
  heimdal-devel \
  heimdal-libs \
  heimdal-path \
  heimdal-server \
  heimdal-workstation \
  python3 \
  python3-devel \
  python3-pip \
  vim
source /etc/profile  # Ensure the Heimdal binaries are in the PATH

echo -e "127.0.0.1\t$HOSTNAME.$REALM" >> /etc/hosts

cat > /etc/krb5.conf <<EOL
[libdefaults]
  default_realm = ${REALM^^}
  dns_lookup_realm = false
  dns_lookup_kdc = false

[realms]
  ${REALM^^} = {
    kdc = ${HOSTNAME,,}.${REALM,,}
    admin_server = ${HOSTNAME,,}.${REALM,,}
  }

[domain_realm]
  .${REALM,,} = ${REALM^^}
  ${REALM,,} = ${REALM^^}
EOL

echo -e "*/*@${REALM^^}\t*" > /var/heimdal/kadmind.acl

# Create the new realm
echo -e "\n\n" | kadmin -l init ${REALM^^}

# Create the user principal
kadmin -l add --use-defaults --password=$PASSWORD $USERNAME

# Create the SPNs and add it to the /etc/krb5.keytab
kadmin -l add --random-key --use-defaults host/$HOSTNAME@${REALM^^}
kadmin -l ext --keytab=/etc/krb5.keytab host/$HOSTNAME@${REALM^^}

kadmin -l add --random-key --use-defaults host/${HOSTNAME^^}@${REALM^^}
kadmin -l ext --keytab=/etc/krb5.keytab host/${HOSTNAME^^}@${REALM^^}

# Start the KDC service
/usr/libexec/kdc --detach

pip3 install gssapi
```