diff --git a/.env.example b/.env.example index 63cecec..4d40c81 100644 --- a/.env.example +++ b/.env.example @@ -4,20 +4,6 @@ APP_URL=http://localhost:3000 USERS=your_user_password_hash USERS_FILE=users_file SECURE_COOKIE=false -GITHUB_CLIENT_ID=github_client_id -GITHUB_CLIENT_SECRET=github_client_secret -GITHUB_CLIENT_SECRET_FILE=github_client_secret_file -GOOGLE_CLIENT_ID=google_client_id -GOOGLE_CLIENT_SECRET=google_client_secret -GOOGLE_CLIENT_SECRET_FILE=google_client_secret_file -GENERIC_CLIENT_ID=generic_client_id -GENERIC_CLIENT_SECRET=generic_client_secret -GENERIC_CLIENT_SECRET_FILE=generic_client_secret_file -GENERIC_SCOPES=generic_scopes -GENERIC_AUTH_URL=generic_auth_url -GENERIC_TOKEN_URL=generic_token_url -GENERIC_USER_URL=generic_user_url -DISABLE_CONTINUE=false OAUTH_WHITELIST= GENERIC_NAME=My OAuth SESSION_EXPIRY=7200 @@ -30,4 +16,7 @@ OAUTH_AUTO_REDIRECT=none BACKGROUND_IMAGE=some_image_url GENERIC_SKIP_SSL=false RESOURCES_DIR=/data/resources -DATABASE_PATH=/data/tinyauth.db \ No newline at end of file +DATABASE_PATH=/data/tinyauth.db +DISABLE_ANALYTICS=false +DISABLE_RESOURCES=false +TRUSTED_PROXIES= \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go index c81a52a..723cb36 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -95,6 +95,7 @@ func init() { {"database-path", "/data/tinyauth.db", "Path to the Sqlite database file."}, {"trusted-proxies", "", "Comma separated list of trusted proxies (IP addresses or CIDRs) for correct client IP detection."}, {"disable-analytics", false, "Disable anonymous version collection."}, + {"disable-resources", false, "Disable the resources server."}, } for _, opt := range configOptions { diff --git a/internal/bootstrap/app_bootstrap.go b/internal/bootstrap/app_bootstrap.go index 3416ff2..e92bb9a 100644 --- a/internal/bootstrap/app_bootstrap.go +++ b/internal/bootstrap/app_bootstrap.go @@ -255,7 +255,8 @@ func (app *BootstrapApp) Setup() error { }, apiRouter, authService) resourcesController := controller.NewResourcesController(controller.ResourcesControllerConfig{ - ResourcesDir: app.config.ResourcesDir, + ResourcesDir: app.config.ResourcesDir, + ResourcesDisabled: app.config.DisableResources, }, mainRouter) healthController := controller.NewHealthController(apiRouter) diff --git a/internal/config/config.go b/internal/config/config.go index 32e586e..28c14df 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -40,6 +40,7 @@ type Config struct { DatabasePath string `mapstructure:"database-path" validate:"required"` TrustedProxies string `mapstructure:"trusted-proxies"` DisableAnalytics bool `mapstructure:"disable-analytics"` + DisableResources bool `mapstructure:"disable-resources"` } // OAuth/OIDC config diff --git a/internal/controller/resources_controller.go b/internal/controller/resources_controller.go index 92384e7..bed4fcc 100644 --- a/internal/controller/resources_controller.go +++ b/internal/controller/resources_controller.go @@ -7,7 +7,8 @@ import ( ) type ResourcesControllerConfig struct { - ResourcesDir string + ResourcesDir string + ResourcesDisabled bool } type ResourcesController struct { @@ -38,5 +39,12 @@ func (controller *ResourcesController) resourcesHandler(c *gin.Context) { }) return } + if controller.config.ResourcesDisabled { + c.JSON(403, gin.H{ + "status": 403, + "message": "Resources are disabled", + }) + return + } controller.fileServer.ServeHTTP(c.Writer, c.Request) }