This document explains the authentication security improvements implemented in Issue #28 to ensure that when authentication is enabled, login is forced and only explicitly public endpoints are accessible without authentication.
When authentication is enabled, only the following endpoints are public by default:
/api/health - Health check endpoint/api/status - Basic server statusThe following endpoints now require authentication when auth is enabled:
/api/models - Model discovery and listing/api/models/types - Model type information/api/models/directories - Model directory information/api/samplers - Sampling methods/api/schedulers - Scheduler options/api/parameters - Generation parameters/api/queue/status - Queue status/api/queue/job/{id} - Job statusThe authentication middleware now follows an "authentication-first" approach:
Administrators can now customize which endpoints remain public using the --public-paths command line option:
# Default behavior (only health and status are public)
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt
# Custom public paths
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt --public-paths "/api/health,/api/status,/api/models"
# Make all endpoints public (not recommended for production)
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt --public-paths "/"
--public-paths <paths>: Comma-separated list of public paths that don't require authentication
/api/health,/api/status when auth is enabled--public-paths "/api/health,/api/status,/api/models"--auth <method>: Authentication method (none, jwt, api-key, unix, pam, optional)--jwt-secret <secret>: JWT secret key--jwt-expiration <minutes>: JWT token expiration time--enable-guest-access: Allow unauthenticated guest access--pam-service-name <name>: PAM service name--auth-data-dir <dir>: Directory for authentication dataThe default configuration is now secure by default:
When configuring custom public paths:
Different authentication methods provide different security levels:
Authentication is only one layer of security:
If you're upgrading from a previous version:
--public-paths if you need to maintain previous behavior temporarilyIf you need to keep API documentation public:
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt --public-paths "/api/health,/api/status,/api/docs,/api/openapi.json"
If you have internal monitoring tools that need access:
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt --public-paths "/api/health,/api/status,/api/queue/status"
For development where you want more permissive access:
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt --public-paths "/api/health,/api/status,/api/models,/api/samplers"
# Test without authentication (should fail)
curl -i http://localhost:8080/api/models
# Test with authentication
curl -i -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8080/api/models
# Test public endpoint (should succeed)
curl -i http://localhost:8080/api/health
401 Unauthorized on Previously Public Endpoints
--public-paths to make endpoint publicAuthentication Not Working
Public Paths Not Working
--public-paths/ and are comma-separatedEnable verbose logging to debug authentication issues:
./stable-diffusion-rest --models-dir /data/SD_MODELS --auth jwt --verbose
Check the logs for authentication-related messages and failed authentication attempts.