fruworg.github.io/content/posts/postgres-krb5.md
root c793b55750 Revert "remove shell"
This reverts commit 65914f8895.
2023-09-24 18:58:33 +03:00

78 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Аутентификация в Postgres Pro с помощью Kerberos
description: Используя протокол GSSAPI
date: 2022-11-29T16:21:00+05:00
tags: [linux, postgres, krb5]
---
## Установка Kerberos и Postgres Pro
Для начала, необходимо установить [Postgres Pro](//fruw.org/posts/postgres-pro-astra-se) и [Kerberos](//fruw.org/posts/linux-krb5).
На машину с Postgres Pro Kerberos устанавливается также, как и на клиента.
## Конфигурация сервера Kerberos
### Добавление принципиала Postgres Pro
```shell
kadmin.local
addprinc <username>
addprinc postgres
addprinc postgres/<pg-hostname>
q
```
### Экспорт субъекта-службы
```shell
ktutil
add_entry -password -p postgres/<pg-hostname>@<DOMAIN.NAME> -k 1 -e aes256-cts-hmac-sha1-96
wkt postgres.keytab
q
```
### Перенос субъекта-службы на сервер Postgres Pro
Перенести keytab можно как угодно, главное, чтобы он находился в папке с конфигурационными файлами Postgres Pro.
Я перенесу с помощью команды scp:
```shell
scp postgres.keytab postgres@<pg-hostname>:/var/lib/pgpro/std-13/data/
```
## Конфигурация сервера Postgres Pro
### Включение ранее перенесённого keytab
```shell
ktutil
read_kt postgres.keytab
q
```
### Изменение конфигруационного файла Postgres Pro
```shell
krb_server_keyfile = 'postgres.keytab'
listen_addresses = 'localhost, <pg-ip>'
# /var/lib/pgpro/std-13/data/postgresql.conf
```
### Разрешение подключения
```shell
hostgssenc all postgres localhost/32 gss include_realm=0
hostgssenc <database> <username> <client-ip>/32 gss include_realm=0
# /var/lib/pgpro/std-13/data/pg_hba.conf
```
### Получение тикета от Kerberos
```shell
kinit postgres
```
## Конфигурация клиента
### Получение тикета от Kerberos
```shell
kinit <username>
```
### Подключение к Postgres Pro
```shell
psql -d <database> -h <pg-hostname> -U <username>
```