Skip to content

Commit a729c9e

Browse files
authored
Merge pull request #192 from inbo/kerberos
Updates in Kerberos tutorial
2 parents 1c40ff5 + ae9d1fb commit a729c9e

1 file changed

Lines changed: 100 additions & 67 deletions

File tree

  • content/installation/user/user_install_kerberos

content/installation/user/user_install_kerberos/index.md

Lines changed: 100 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: "Using Kerberos authentication for database connection"
3-
description: "Kerberos authentication on linux"
3+
description: "Kerberos authentication on Linux"
44
author: "Jo Loos, Floris Vanderhaeghe, Stijn Van Hoey"
5-
date: 2018-01-03
5+
date: 2020-09-07
66
categories: ["installation"]
77
tags: ["database", "data", "installation"]
88
---
@@ -19,70 +19,26 @@ Hence, we can use the protocol to have an OS independent solution for authentica
1919

2020
## Installation
2121

22-
### Libraries for authentication
22+
### Kerberos client
2323

2424
For debian/ubuntu users (make sure you belong to the `sudo` group):
2525

26+
```bash
27+
sudo apt-get install krb5-user
28+
sudo apt-get install openssl # if not yet available on your system (it probably is)
2629
```
27-
sudo apt-get install krb5-user libpam-krb5 libpam-ccreds auth-client-config
28-
sudo apt-get install openssl
29-
```
30-
31-
These libraries will be used later on. The following section is for interaction with MS SQL databases.
32-
33-
Modern Linux distributions use PAM to handle the authentication tasks of applications (services) on the system (PAM stands for _Pluggable Authentication Modules_, see `man PAM`). However we do not need that here.
34-
The above installation may have led to inserting a line into PAM configuration file `/etc/pam.d/common-auth`. The line looks like this (note the defining part `pam_krb5.so`):
35-
36-
```
37-
auth [success=4 default=ignore] pam_krb5.so minimum_uid=1000
38-
```
39-
40-
This line makes every application that needs authentication on the system (like sudo, screensaver unlock, update manager, ...) first try the Kerberos connection to authenticate.
41-
This is overkill as we don't want to use Kerberos that way, and it can significantly slow down all other system authentications.
42-
Therefore, you should _comment out_ the above line in `/etc/pam.d/common-auth`.
43-
44-
### MS SQL Server tools
45-
46-
As most of the databases at INBO are SQL Server, an appropriate driver and the command line toolset is required to fully support database connections to SQL Server.
47-
48-
#### ODBC driver
49-
50-
Download and install the [Microsoft ODBC Driver for SQL Server](https://www.microsoft.com/en-us/download/details.aspx?id=53339). The installation instructions for different Linux flavours can be downloaded together with the ODBC driver. For `Ubuntu 16.04` (and most distributions based on it), following instructions apply:
51-
52-
```
53-
sudo su
54-
apt-get install curl
55-
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
56-
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssqlrelease.list
57-
exit
58-
sudo apt-get update
59-
sudo ACCEPT_EULA=Y apt-get install msodbcsql=13.1.4.0-1
60-
sudo apt-get install unixodbc-dev
61-
```
62-
63-
#### mssql-tools
64-
65-
Install the MS SQL tools as well:
66-
67-
* **sqlcmd**: Command-line query utility.
68-
* **bcp**: Bulk import-export utility.
69-
70-
The instructions for different platforms are explained [here](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools). In order to test the SQL connection later in this tutorial, add `/opt/mssql-tools/bin/` to your PATH environment variable.
7130

72-
You could also decide to go for the binaries: download [the debian package of mssql-tools](https://apt-mo.trafficmanager.net/repos/mssql-ubuntu-xenial-release/pool/main/m/mssql-tools/mssql-tools_14.0.1.246-1_amd64.deb) and install with:
31+
During installation, you may be asked for extra configuration input.
32+
To answer that, see next section: [Configure Kerberos client](#configure-kerberos-client).
7333

74-
```
75-
sudo apt-get install libgss3
76-
sudo dpkg -i mssql-tools_14.0.1.246-1_amd64.deb
77-
```
7834

7935
### Configure Kerberos client
8036

8137
*(again, the commands assume root privileges)*
8238

83-
Start with the kerberos configuration dialogue:
39+
Start with the Kerberos configuration dialogue:
8440

85-
```
41+
```bash
8642
dpkg-reconfigure krb5-config
8743
```
8844
Use `INBO.BE` as the realm (this is the realm of the kerberos servers):
@@ -118,15 +74,82 @@ Next, adapt the `krb5.conf`, probably available in the `/etc` directory. Add th
11874
forwardable= true
11975
```
12076

121-
Inbo staff can download a preconfigured krb5.conf file here:"https://drive.google.com/a/inbo.be/file/d/1q4MOWl3i-DDy1s3vwOeqPkpToa1S-3zE/view?usp=sharing".
122-
In order to sync the timing of the domain controller server and client side, install `ntp`:
77+
INBO staff can download a preconfigured `krb5.conf` file here:
78+
<https://drive.google.com/a/inbo.be/file/d/1q4MOWl3i-DDy1s3vwOeqPkpToa1S-3zE/view?usp=sharing>.
79+
80+
### Time synchronization
81+
82+
This is needed in order to sync the timing of the domain controller server and client side.
83+
84+
Check whether the `systemd-timesyncd` daemon is already active on your system:
12385

86+
```bash
87+
$ systemctl status time-sync.target
88+
● time-sync.target - System Time Synchronized
89+
Loaded: loaded (/lib/systemd/system/time-sync.target; static; vendor preset: disabled)
90+
Active: active since Mon 2020-09-07 08:27:03 CEST; 59min ago
91+
Docs: man:systemd.special(7)
92+
93+
$ timedatectl status
94+
Local time: ma 2020-09-07 09:27:00 CEST
95+
Universal time: ma 2020-09-07 07:27:00 UTC
96+
RTC time: ma 2020-09-07 07:27:00
97+
Time zone: Europe/Brussels (CEST, +0200)
98+
System clock synchronized: yes
99+
NTP service: active
100+
RTC in local TZ: no
124101
```
102+
103+
Note the line `NTP service: active`.
104+
105+
If you do have the `systemd-timesyncd` package but the unit is _not_ active, run `systemctl enable --now time-sync.target`.
106+
Further information can be found [here](https://wiki.archlinux.org/index.php/Systemd-timesyncd).
107+
108+
Only if you **don't** have the `systemd-timesyncd` package, install `ntp` instead:
109+
110+
```bash
125111
sudo apt-get install ntp
126112
```
127-
After installation, check if the following two files do exist:
113+
114+
_If_ you installed `ntp`, check whether the following two files do exist:
115+
128116
* `/etc/ntp.conf`
129-
* `/etc/ntp.conf.dhcp` (empty file, just amke sure there is a file)
117+
* `/etc/ntp.conf.dhcp` (empty file, just make sure there is a file)
118+
119+
### MS SQL Server ODBC driver and tools
120+
121+
As most of the databases at INBO are SQL Server, an appropriate driver and the command line toolset is required to fully support database connections to SQL Server.
122+
123+
Apart from the ODBC driver, we will also install following tools:
124+
125+
* **sqlcmd**: Command-line query utility.
126+
* **bcp**: Bulk import-export utility.
127+
128+
For Linux, follow [these installation instructions](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server).[^installnotes]
129+
130+
Also follow the 'optional' instructions, as these will install the tools.
131+
132+
Hence, for Ubuntu 20.04 or Linux Mint 20 you would do:
133+
134+
```bash
135+
sudo su
136+
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
137+
#Ubuntu 20.04
138+
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
139+
exit
140+
sudo apt-get update
141+
sudo ACCEPT_EULA=Y apt-get install msodbcsql17 mssql-tools
142+
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
143+
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
144+
source ~/.bashrc
145+
sudo apt-get install unixodbc-dev
146+
```
147+
148+
On Ubuntu 20.04, if installing `msodbcsql17` and `mssql-tools` fails because of incompatible `unixodbc` version, you can first try `apt install unixodbc=2.3.6-0.1build1 unixodbc-dev=2.3.6-0.1build1`.
149+
150+
[^installnotes]: You can also find the debian packages of Microsoft ODBC Driver for SQL Server [here](https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server).
151+
You can find separate installation instructions for `sqlcmd`, `bcp` and `unixodbc-dev` [here](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools).
152+
130153

131154
## Test installation
132155

@@ -164,36 +187,46 @@ sqlcmd -S DBServerName -E
164187
2> Go
165188
```
166189

190+
On Ubuntu 20.04, you may get an error:
191+
192+
```
193+
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.
194+
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
195+
```
196+
197+
If you are in that case, have a look at working solutions in [this GitHub issue](https://github.com/microsoft/azuredatastudio/issues/10337).
167198

168199
## SQL ODBC connections
169200

170201
To support database connections from other applications (e.g. GUI environments, but also R, Python,...), the configuration of database drivers and connections should be provided in the `/etc/odbc.ini` and `/etc/odbcinst.ini`.
171202

172203
Make sure the ODBC driver for SQL Server is available with a recognizable name in the `/etc/odbcinst.ini` file:
173204
```
174-
[ODBC Driver 13 for SQL Server]
175-
Description=Microsoft ODBC Driver 13 for SQL Server
176-
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.4.0
177-
UsageCount=2
205+
[ODBC Driver 17 for SQL Server]
206+
Description=Microsoft ODBC Driver 17 for SQL Server
207+
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1
208+
UsageCount=1
178209
```
179210

180211
### Connecting by explicitly providing the SQL connection string to ODBC libraries/packages
181212

182-
Inbo staff can consult a list of connection strings [here](https://docs.google.com/spreadsheets/d/1Wu7GmWm-NyHLHYWwuu74aQuugkDKGnLF-8XFFPz_F_M/edit?usp=sharing)
213+
INBO staff can consult a list of connection strings [here](https://docs.google.com/spreadsheets/d/1Wu7GmWm-NyHLHYWwuu74aQuugkDKGnLF-8XFFPz_F_M/edit?usp=sharing).
183214
At this moment, you can actually connect using typical ODBC libraries/packages provided by R or Python:
184215

185-
```{r eval = FALSE}
216+
```r
186217
library(DBI)
187218
connection <- dbConnect(
188219
odbc::odbc(),
189-
.connection_string = "Driver={ODBC Driver 13 for SQL Server};Server=DBServername;Database=DBName;Trusted_Connection=yes;"
220+
.connection_string = "Driver={ODBC Driver 17 for SQL Server};Server=DBServername;Database=DBName;Trusted_Connection=yes;"
190221
)
191222
dbListTables(connection)
192223
```
193224

225+
However, most recommended for INBO staff using R is the use of the [inbodb](https://inbo.github.io/inbodb/) package, most notably the [`connect_inbo_dbase()`](https://inbo.github.io/inbodb/reference/connect_inbo_dbase.html) function.
226+
194227
```python
195228
import pyodbc
196-
conn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=DBServername;Database=DBName;Trusted_Connection=yes;")
229+
conn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};Server=DBServername;Database=DBName;Trusted_Connection=yes;")
197230
```
198231

199232
In RStudio, you can also make the connection with the GUI:
@@ -215,7 +248,7 @@ However, it is probably easier to provide the configuration to specific database
215248

216249
```
217250
[nbn_ipt]
218-
Driver = ODBC Driver 13 for SQL Server
251+
Driver = ODBC Driver 17 for SQL Server
219252
Description = odbc verbinding naar db
220253
Trace = No
221254
Server = DBServername

0 commit comments

Comments
 (0)