-
Notifications
You must be signed in to change notification settings - Fork 95
GSSAPI #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaggederest
wants to merge
18
commits into
main
Choose a base branch
from
feat/gssapi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GSSAPI #479
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a5ee125
GSSAPI phase 1
jaggederest 42bdc27
gssapi phase 2
jaggederest 9279bfe
gssapi phase 3
jaggederest 0b3a898
gssapi phase 4
jaggederest 5f6841d
gssapi mostly working...
jaggederest ad4426d
working backend and frontend GSSAPI connections
jaggederest 89a4da5
a couple test fixes
jaggederest 0a5bc70
A few fixes (#480)
levkk c079ec5
minor test fixes
jaggederest be8af9a
merge origin/feat/gssapi into feat/gssapi
jaggederest 78a3c3c
feature flag gssapi tests, set up krb5 dependencies in ci
jaggederest 9037e92
try to create keytabs before integration tests
jaggederest afea619
progress towards tests
jaggederest e04b948
ci updates
jaggederest 0fe12a4
try the kdc setup verbosely
jaggederest 61baaf2
keytab script revamp
jaggederest 4b51890
try getting creds from keytab if cache fails
jaggederest 407f4fd
try again with the gssapi test setup
jaggederest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
[target.x86_64-unknown-linux-gnu] | ||
linker = "/usr/bin/clang" | ||
rustflags = ["-C", "link-arg=--ld-path=/usr/bin/mold"] | ||
|
||
# Configuration for macOS to use MIT Kerberos from Homebrew | ||
[target.aarch64-apple-darwin] | ||
linker = "clang" | ||
rustflags = [ | ||
"-L", "/opt/homebrew/opt/krb5/lib", | ||
"-C", "link-args=-Wl,-rpath,/opt/homebrew/opt/krb5/lib" | ||
] | ||
|
||
[target.x86_64-apple-darwin] | ||
linker = "clang" | ||
rustflags = [ | ||
"-L", "/opt/homebrew/opt/krb5/lib", | ||
"-C", "link-args=-Wl,-rpath,/opt/homebrew/opt/krb5/lib" | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,4 @@ CLAUDE.local.md | |
pgdog-plugin/src/bindings.rs | ||
local/ | ||
integration/log.txt | ||
integration/gssapi/keytabs/*.keytab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# GSSAPI (Kerberos) Authentication Configuration Example | ||
|
||
This directory contains example configurations for using GSSAPI/Kerberos authentication with PGDog. | ||
|
||
## Overview | ||
|
||
PGDog supports GSSAPI authentication in a dual-context model: | ||
- **Frontend**: Accepts GSSAPI authentication from clients | ||
- **Backend**: Uses service credentials to authenticate to PostgreSQL servers | ||
|
||
This approach preserves connection pooling while providing strong authentication. | ||
|
||
## Files | ||
|
||
- `pgdog.toml` - Main configuration with GSSAPI settings | ||
- `users.toml` - User mappings for GSSAPI principals | ||
|
||
## Key Features Demonstrated | ||
|
||
### 1. Global GSSAPI Configuration | ||
- Server keytab for accepting client connections | ||
- Default backend credentials for PostgreSQL servers | ||
- Ticket refresh intervals | ||
- Realm stripping for username mapping | ||
|
||
### 2. Per-Server Backend Authentication | ||
- Different keytabs for different PostgreSQL servers | ||
- Useful for multi-tenant or sharded deployments | ||
- Fine-grained access control per database | ||
|
||
### 3. Mixed Authentication | ||
- GSSAPI for some databases, password for others | ||
- Fallback options for migration scenarios | ||
|
||
## Setup Requirements | ||
|
||
### Prerequisites | ||
1. Kerberos KDC (Key Distribution Center) configured | ||
2. Service principals created for PGDog and PostgreSQL servers | ||
3. Keytab files generated and placed in appropriate locations | ||
4. PostgreSQL servers configured to accept GSSAPI authentication | ||
|
||
### Keytab Files | ||
|
||
#### Frontend (Client-facing) | ||
```bash | ||
# Create service principal for PGDog | ||
kadmin.local -q "addprinc -randkey postgres/pgdog.example.com" | ||
kadmin.local -q "ktadd -k /etc/pgdog/pgdog.keytab postgres/pgdog.example.com" | ||
``` | ||
|
||
#### Backend (PostgreSQL-facing) | ||
```bash | ||
# Create service principal for backend connections | ||
kadmin.local -q "addprinc -randkey pgdog-service" | ||
kadmin.local -q "ktadd -k /etc/pgdog/backend.keytab pgdog-service" | ||
|
||
# For per-server authentication | ||
kadmin.local -q "addprinc -randkey pgdog-shard1" | ||
kadmin.local -q "ktadd -k /etc/pgdog/shard1.keytab pgdog-shard1" | ||
``` | ||
|
||
### PostgreSQL Configuration | ||
|
||
Configure PostgreSQL servers to accept GSSAPI authentication from PGDog's service principal: | ||
|
||
```postgresql | ||
# pg_hba.conf | ||
host all [email protected] 0.0.0.0/0 gss | ||
host all [email protected] 0.0.0.0/0 gss | ||
``` | ||
|
||
## Authentication Flow | ||
|
||
1. **Client → PGDog**: Client authenticates using their Kerberos principal (e.g., [email protected]) | ||
2. **Username Mapping**: PGDog maps the principal to a user in users.toml (strips realm if configured) | ||
3. **PGDog → PostgreSQL**: PGDog uses its service credentials to connect to the backend | ||
4. **Connection Pooling**: PGDog maintains pooled connections using its service identity | ||
|
||
## Security Considerations | ||
|
||
- Keytab files should be readable only by the PGDog process user | ||
- Use separate service principals for different environments (dev/staging/prod) | ||
- Regularly rotate keytabs and update Kerberos passwords | ||
- Consider using GSSAPI encryption if SQL inspection is not required | ||
- Monitor ticket refresh logs for authentication issues | ||
|
||
## Testing | ||
|
||
```bash | ||
# Test client authentication | ||
kinit [email protected] | ||
psql -h pgdog.example.com -p 6432 -d production -U alice | ||
|
||
# Verify PGDog's service ticket | ||
klist -k /etc/pgdog/pgdog.keytab | ||
|
||
# Check backend connectivity | ||
kinit -kt /etc/pgdog/backend.keytab [email protected] | ||
psql -h pg1.example.com -p 5432 -d postgres -U pgdog-service | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
### Common Issues | ||
|
||
1. **Clock Skew**: Ensure all servers have synchronized time (use NTP) | ||
2. **DNS Resolution**: Kerberos requires proper forward and reverse DNS | ||
3. **Keytab Permissions**: Check file ownership and permissions (600 or 400) | ||
4. **Principal Names**: Verify exact principal names including realm | ||
5. **Ticket Expiration**: Monitor ticket refresh intervals | ||
|
||
### Debug Logging | ||
|
||
Enable Kerberos debug output: | ||
```bash | ||
export KRB5_TRACE=/tmp/krb5_trace.log | ||
``` | ||
|
||
## Migration from Password Authentication | ||
|
||
1. Enable `fallback_enabled = true` in GSSAPI configuration | ||
2. Deploy PGDog with both authentication methods available | ||
3. Migrate users gradually to GSSAPI | ||
4. Once all users migrated, disable fallback |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have protobuf! We are finally complete