From 20a82efda43fb18bd66ea249bd65c988295e75ce Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 11 Jul 2022 05:08:15 +0200 Subject: [PATCH] Auth: Shorten passwd mode option (password still works) #98 #782 Signed-off-by: Michael Mayer --- Makefile | 4 ++-- docker-compose.latest.yml | 2 +- docker-compose.local.yml | 2 +- docker-compose.postgres.yml | 2 +- docker-compose.yml | 2 +- docker/examples/arm64/docker-compose.yml | 2 +- docker/examples/armv7/docker-compose.yml | 2 +- docker/examples/cloud/docker-compose.yml | 4 ++-- docker/examples/docker-compose.yml | 2 +- docker/examples/macos/docker-compose.yml | 2 +- docker/examples/scheduler/docker-compose.yml | 2 +- docker/examples/sqlite/docker-compose.yml | 2 +- docker/examples/windows/docker-compose.yml | 2 +- internal/config/config_auth.go | 17 ++++++++++++----- internal/config/config_auth_test.go | 9 ++++++++- 15 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index e4662d644..2ef2d1c7a 100644 --- a/Makefile +++ b/Makefile @@ -124,9 +124,9 @@ acceptance-stop: acceptance-private-restart: cp -f storage/acceptance/backup.db storage/acceptance/index.db cp -f storage/acceptance/config/settingsBackup.yml storage/acceptance/config/settings.yml - ./photoprism --auth-mode "password" --url "http://localhost:2343/" --upload-nsfw=false --db "sqlite" --dsn "./storage/acceptance/index.db" --import-path "./storage/acceptance/import" --port 2343 -c "./storage/acceptance/config" -o "./storage/acceptance/originals" -s "./storage/acceptance" --test --backup-path "./storage/acceptance/backup" --disable-backups start -d + ./photoprism --auth-mode "passwd" --url "http://localhost:2343/" --upload-nsfw=false --db "sqlite" --dsn "./storage/acceptance/index.db" --import-path "./storage/acceptance/import" --port 2343 -c "./storage/acceptance/config" -o "./storage/acceptance/originals" -s "./storage/acceptance" --test --backup-path "./storage/acceptance/backup" --disable-backups start -d acceptance-private-stop: - ./photoprism --auth-mode "password" --url "http://localhost:2343/" --upload-nsfw=false --db "sqlite" --dsn "./storage/acceptance/index.db" --import-path "./storage/acceptance/import" --port 2343 -c "./storage/acceptance/config" -o "./storage/acceptance/originals" -s "./storage/acceptance" --test --backup-path "./storage/acceptance/backup" --disable-backups stop + ./photoprism --auth-mode "passwd" --url "http://localhost:2343/" --upload-nsfw=false --db "sqlite" --dsn "./storage/acceptance/index.db" --import-path "./storage/acceptance/import" --port 2343 -c "./storage/acceptance/config" -o "./storage/acceptance/originals" -s "./storage/acceptance" --test --backup-path "./storage/acceptance/backup" --disable-backups stop start: ./photoprism start -d stop: diff --git a/docker-compose.latest.yml b/docker-compose.latest.yml index e96f10abd..0daaca0ca 100644 --- a/docker-compose.latest.yml +++ b/docker-compose.latest.yml @@ -21,7 +21,7 @@ services: environment: PHOTOPRISM_UID: ${UID:-1000} # user id, should match your host user id PHOTOPRISM_GID: ${GID:-1000} # group id - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # initial "admin" password (minimum 8 characters) ## Public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_SITE_URL: "https://latest.localssl.dev/" diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 5144ff8fd..3ea8f8a64 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -21,7 +21,7 @@ services: environment: PHOTOPRISM_UID: ${UID:-1000} # user id, should match your host user id PHOTOPRISM_GID: ${GID:-1000} # group id - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # initial "admin" password (minimum 8 characters) ## Public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_SITE_URL: "https://latest.localssl.dev/" diff --git a/docker-compose.postgres.yml b/docker-compose.postgres.yml index 2a76d9744..bde8fb869 100644 --- a/docker-compose.postgres.yml +++ b/docker-compose.postgres.yml @@ -25,7 +25,7 @@ services: - "go-mod:/go/pkg/mod" shm_size: "2gb" environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # initial "admin" password (minimum 8 characters) PHOTOPRISM_SITE_URL: "http://localhost:2342/" PHOTOPRISM_SITE_CAPTION: "AI-Powered Photos App" diff --git a/docker-compose.yml b/docker-compose.yml index d2f4b61d5..84de1c2f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,7 @@ services: ## Switch to a non-root user after initialization (supported IDs are 33, 50-99, 500-600, and 900-1200): PHOTOPRISM_UID: ${UID:-1000} # user id, should match your host user id PHOTOPRISM_GID: ${GID:-1000} # group id - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "photoprism" # initial "admin" password (minimum 8 characters) ## External development server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_SITE_URL: "https://app.localssl.dev/" diff --git a/docker/examples/arm64/docker-compose.yml b/docker/examples/arm64/docker-compose.yml index f4c8e0646..6b01f03ae 100644 --- a/docker/examples/arm64/docker-compose.yml +++ b/docker/examples/arm64/docker-compose.yml @@ -60,7 +60,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/docker/examples/armv7/docker-compose.yml b/docker/examples/armv7/docker-compose.yml index 832fbb06c..0beeef5dc 100644 --- a/docker/examples/armv7/docker-compose.yml +++ b/docker/examples/armv7/docker-compose.yml @@ -55,7 +55,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/docker/examples/cloud/docker-compose.yml b/docker/examples/cloud/docker-compose.yml index 7a8f75685..8d89896f5 100644 --- a/docker/examples/cloud/docker-compose.yml +++ b/docker/examples/cloud/docker-compose.yml @@ -132,7 +132,7 @@ services: PHOTOPRISM_SITE_CAPTION: "AI-Powered Photos App" PHOTOPRISM_SITE_DESCRIPTION: "" # meta site description PHOTOPRISM_SITE_AUTHOR: "" # meta site author - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "_admin_password_" # YOUR INITIAL "admin" PASSWORD PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) PHOTOPRISM_HTTP_COMPRESSION: "gzip" # improves transfer speed and bandwidth utilization (none or gzip) @@ -170,7 +170,7 @@ services: ## see https://docs.photoprism.app/getting-started/proxies/traefik/ traefik: restart: always - image: traefik:v2.6 + image: traefik:v2.8 container_name: traefik ports: - "80:80" diff --git a/docker/examples/docker-compose.yml b/docker/examples/docker-compose.yml index 4a0ef7b38..bb8d60f2b 100644 --- a/docker/examples/docker-compose.yml +++ b/docker/examples/docker-compose.yml @@ -52,7 +52,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/docker/examples/macos/docker-compose.yml b/docker/examples/macos/docker-compose.yml index 322fc1c9d..ac1fe879e 100644 --- a/docker/examples/macos/docker-compose.yml +++ b/docker/examples/macos/docker-compose.yml @@ -49,7 +49,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/docker/examples/scheduler/docker-compose.yml b/docker/examples/scheduler/docker-compose.yml index ca5ed3e6d..feb9b074d 100644 --- a/docker/examples/scheduler/docker-compose.yml +++ b/docker/examples/scheduler/docker-compose.yml @@ -54,7 +54,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/docker/examples/sqlite/docker-compose.yml b/docker/examples/sqlite/docker-compose.yml index 1084aa4ec..bdf4f4d63 100644 --- a/docker/examples/sqlite/docker-compose.yml +++ b/docker/examples/sqlite/docker-compose.yml @@ -52,7 +52,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/docker/examples/windows/docker-compose.yml b/docker/examples/windows/docker-compose.yml index 903f9e1f9..226097c03 100644 --- a/docker/examples/windows/docker-compose.yml +++ b/docker/examples/windows/docker-compose.yml @@ -54,7 +54,7 @@ services: ports: - "2342:2342" # HTTP port (host:container) environment: - PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password) + PHOTOPRISM_AUTH_MODE: "passwd" # authentication mode (public, passwd) PHOTOPRISM_ADMIN_PASSWORD: "insecure" # YOUR INITIAL ADMIN PASSWORD (MINIMUM 8 CHARACTERS, USERNAME "admin") PHOTOPRISM_SITE_URL: "http://localhost:2342/" # public server URL incl http:// or https:// and /path, :port is optional PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video) diff --git a/internal/config/config_auth.go b/internal/config/config_auth.go index f36423552..87ff1975a 100644 --- a/internal/config/config_auth.go +++ b/internal/config/config_auth.go @@ -9,8 +9,8 @@ import ( ) const ( - AuthModePublic = "public" - AuthModePassword = "password" + AuthModePublic = "public" + AuthModePasswd = "passwd" ) func isBcrypt(s string) bool { @@ -46,11 +46,18 @@ func (c *Config) AdminPassword() string { func (c *Config) AuthMode() string { if c.Public() { return AuthModePublic - } else if m := strings.ToLower(strings.TrimSpace(c.options.AuthMode)); m != "" { - return m } - return AuthModePassword + mode := strings.ToLower(strings.TrimSpace(c.options.AuthMode)) + + switch mode { + case AuthModePublic: + return AuthModePublic + case "", "pw", "pass", "passwd", "password", "passwort", "passwords": + return AuthModePasswd + default: + return AuthModePasswd + } } // Auth checks if authentication is required. diff --git a/internal/config/config_auth_test.go b/internal/config/config_auth_test.go index 0a3d212ed..bb7fd12ce 100644 --- a/internal/config/config_auth_test.go +++ b/internal/config/config_auth_test.go @@ -13,9 +13,16 @@ func TestAuthMode(t *testing.T) { assert.Equal(t, AuthModePublic, c.AuthMode()) c.options.Public = false c.options.Demo = false - assert.Equal(t, AuthModePassword, c.AuthMode()) + assert.Equal(t, AuthModePasswd, c.AuthMode()) c.options.Demo = true assert.Equal(t, AuthModePublic, c.AuthMode()) + c.options.AuthMode = "pass" + assert.Equal(t, AuthModePublic, c.AuthMode()) + c.options.Demo = false + c.options.AuthMode = "pass" + assert.Equal(t, AuthModePasswd, c.AuthMode()) + c.options.AuthMode = "password" + assert.Equal(t, AuthModePasswd, c.AuthMode()) } func TestAuth(t *testing.T) {