|
| 1 | +--- |
| 2 | +title: OIDC Authentication |
| 3 | +weight: 30 |
| 4 | +--- |
| 5 | + |
| 6 | +# OIDC Authentication |
| 7 | + |
| 8 | +The kube-bind backend supports OpenID Connect (OIDC) authentication for securing API access. There are two modes of operation: external OIDC providers and an embedded OIDC provider for development. |
| 9 | + |
| 10 | +## External OIDC Provider (Production) |
| 11 | + |
| 12 | +For production deployments, use an external OIDC provider such as: |
| 13 | +- Dex |
| 14 | +- Keycloak |
| 15 | +- Auth0 |
| 16 | +- Google |
| 17 | +- Microsoft Azure AD |
| 18 | +- Any OIDC-compliant provider |
| 19 | + |
| 20 | +### Configuration |
| 21 | + |
| 22 | +Configure the backend to use an external OIDC provider with these flags: |
| 23 | + |
| 24 | +```bash |
| 25 | +--oidc-type=external |
| 26 | +--oidc-issuer-url=https://your-oidc-provider.com |
| 27 | +--oidc-issuer-client-id=your-client-id |
| 28 | +--oidc-issuer-client-secret=your-client-secret |
| 29 | +--oidc-callback-url=https://your-backend.com/callback |
| 30 | +--oidc-authorize-url=https://your-oidc-provider.com/auth |
| 31 | +--oidc-ca-file=/path/to/ca-bundle.pem # Optional: for custom CA certificates |
| 32 | +``` |
| 33 | + |
| 34 | +### External OIDC Flow |
| 35 | + |
| 36 | +1. User initiates authentication by accessing a protected endpoint |
| 37 | +2. Backend redirects user to the external OIDC provider's authorization endpoint |
| 38 | +3. User authenticates with the OIDC provider |
| 39 | +4. OIDC provider redirects back to the backend's callback URL with authorization code |
| 40 | +5. Backend exchanges authorization code for ID token and access token |
| 41 | +6. Backend validates the tokens and establishes user session |
| 42 | +7. User can now access protected APIs with valid session |
| 43 | + |
| 44 | +## Embedded OIDC Provider (Development Only) |
| 45 | + |
| 46 | +For development and testing purposes, kube-bind includes an embedded OIDC provider that eliminates the need to set up an external authentication service. |
| 47 | + |
| 48 | +### Configuration |
| 49 | + |
| 50 | +Configure the backend to use the embedded OIDC provider: |
| 51 | + |
| 52 | +```bash |
| 53 | +--oidc-type=embedded |
| 54 | +--oidc-callback-url=https://your-backend.com/callback |
| 55 | +--oidc-issuer-url=https://your-backend.com # The backend serves as the OIDC provider |
| 56 | +``` |
| 57 | + |
| 58 | +### Embedded OIDC Flow |
| 59 | + |
| 60 | +1. Backend starts up and initializes the embedded OIDC server using mockoidc |
| 61 | +2. The embedded OIDC server automatically generates: |
| 62 | + - Client ID and client secret |
| 63 | + - Signing keys for tokens |
| 64 | + - OIDC discovery endpoints (`/.well-known/openid_configuration`) |
| 65 | +3. User initiates authentication by accessing a protected endpoint |
| 66 | +4. Backend redirects user to its own embedded OIDC authorization endpoint |
| 67 | +5. User authenticates with the embedded provider (typically accepts any credentials for development) |
| 68 | +6. Embedded OIDC provider redirects back to the backend's callback URL |
| 69 | +7. Backend validates the tokens (self-issued) and establishes user session |
| 70 | +8. User can now access protected APIs with valid session |
| 71 | + |
| 72 | +### Development Mode Warning |
| 73 | + |
| 74 | +When using embedded OIDC, the backend displays a prominent warning message at startup to remind developers that this mode is not suitable for production use. |
| 75 | + |
| 76 | +## Security Considerations |
| 77 | + |
| 78 | +### External OIDC (Production) |
| 79 | +- Use HTTPS for all endpoints |
| 80 | +- Validate OIDC provider certificates |
| 81 | +- Use strong client secrets |
| 82 | +- Configure proper redirect URI restrictions |
| 83 | +- Monitor for security updates to the OIDC provider |
| 84 | + |
| 85 | +### Embedded OIDC (Development Only) |
| 86 | +- **NEVER use in production** - provides no real security |
| 87 | +- Accepts any credentials for authentication |
| 88 | +- Intended only for local development and testing |
| 89 | +- Does not persist user data between restarts |
| 90 | + |
| 91 | +## Troubleshooting |
| 92 | + |
| 93 | +### Common Issues |
| 94 | + |
| 95 | +1. **Certificate validation failures**: Use `--oidc-ca-file` to specify custom CA certificates |
| 96 | +2. **Callback URL mismatches**: Ensure the callback URL matches what's configured in your OIDC provider |
| 97 | +3. **Token validation errors**: Check that the issuer URL matches between provider and backend configuration |
| 98 | +4. **Network connectivity**: Verify the backend can reach the external OIDC provider |
| 99 | + |
| 100 | +### Debug Logging |
| 101 | + |
| 102 | +Enable debug logging to troubleshoot OIDC issues: |
| 103 | + |
| 104 | +```bash |
| 105 | +--v=2 # Increase verbosity for more detailed logs |
| 106 | +``` |
0 commit comments