| author | |
| committer | |
| log | 42cb7282cfc609f4f765d92eca82e7a33bb9ef37 |
| tree | a1f62689ce084f2809cd2828a51f5ad00790f544 |
| parent | 6544ee39cbc4b1e3af5467239fed6984f31c63e7 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Keep Navidrome as the music backend, with Snow Globe SSO for the web player and password authentication for music clients.
Assisted-by: gpt-6.1-terra5 files changed, 225 insertions(+), 21 deletions(-)
service/navidrome/README.md created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | # Music | |
| 2 | ||
| 3 | The music address serves Feishin with Snow Globe sign-in and Navidrome's | |
| 4 | Subsonic and native APIs for clients. Existing Navidrome data and the Music | |
| 5 | folder remain the backend. The browser bridge uses Navidrome's externally | |
| 6 | authenticated session; Feishin's local cache is cleared when the signed-in | |
| 7 | account changes. | |
| 8 | ||
| 9 | Clients that cannot use Snow Globe SSO need a Navidrome password. Open | |
| 10 | `/manage/`, select the account from the user menu, and set a password; use the | |
| 11 | music address as the server URL. For an account created through SSO, the first | |
| 12 | password can be set without its autogenerated current password. Passwords are | |
| 13 | separate from Snow Globe and continue to work for clients until changed. | |
| 14 | ||
| 15 | The preview starts with an empty database and music directory. It does not | |
| 16 | connect to the production library or send external integration requests. |
service/navidrome/bootstrap.js created+47| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | (async () => { | |
| 2 | const response = await fetch('/snow-session', { cache: 'no-store' }); | |
| 3 | if (!response.ok) throw new Error('Music sign-in failed'); | |
| 4 | const match = (await response.text()).match(/window\.__APP_CONFIG__\s*=\s*(.+)/); | |
| 5 | if (!match) throw new Error('Music session is unavailable'); | |
| 6 | const value = JSON.parse(match[1].trim().replace(/;$/, '')); | |
| 7 | const auth = (typeof value === 'string' ? JSON.parse(value) : value).auth; | |
| 8 | if (!auth?.username || !auth.id || !auth.subsonicSalt || !auth.subsonicToken) { | |
| 9 | throw new Error('Music session is unavailable'); | |
| 10 | } | |
| 11 | if (localStorage.getItem('snow_user') !== auth.username) { | |
| 12 | localStorage.clear(); | |
| 13 | await new Promise((resolve, reject) => { | |
| 14 | const request = indexedDB.deleteDatabase('keyval-store'); | |
| 15 | request.onsuccess = resolve; | |
| 16 | request.onerror = request.onblocked = reject; | |
| 17 | }); | |
| 18 | localStorage.setItem('snow_user', auth.username); | |
| 19 | } | |
| 20 | const id = 'snowglobe'; | |
| 21 | const saved = JSON.parse(localStorage.getItem('store_authentication') || 'null'); | |
| 22 | const server = { | |
| 23 | ...saved?.state?.serverList?.[id], | |
| 24 | id, | |
| 25 | name: 'Music', | |
| 26 | type: 'navidrome', | |
| 27 | url: window.location.origin, | |
| 28 | username: auth.username, | |
| 29 | userId: auth.id, | |
| 30 | isAdmin: auth.isAdmin, | |
| 31 | credential: `u=${encodeURIComponent(auth.username)}&s=${auth.subsonicSalt}&t=${auth.subsonicToken}`, | |
| 32 | ndCredential: 'sso', | |
| 33 | }; | |
| 34 | const state = saved?.state || {}; | |
| 35 | state.currentServer = server; | |
| 36 | state.serverList = { [id]: server }; | |
| 37 | localStorage.setItem('store_authentication', JSON.stringify({ state, version: 2 })); | |
| 38 | if (document.readyState === 'loading') { | |
| 39 | await new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve, { once: true })); | |
| 40 | } | |
| 41 | const original = document.querySelector('script[type="application/x-snow-module"]'); | |
| 42 | if (!original) throw new Error('Music application is unavailable'); | |
| 43 | const script = document.createElement('script'); | |
| 44 | script.type = 'module'; | |
| 45 | script.src = original.src; | |
| 46 | document.head.appendChild(script); | |
| 47 | })(); |
service/navidrome/nginx.conf created+91| ... | ... | @@ -0,0 +1,91 @@ |
| 1 | server { | |
| 2 | listen 127.0.0.1:{{ env "NOMAD_PORT_app_http" }}; | |
| 3 | absolute_redirect off; | |
| 4 | access_log off; | |
| 5 | root /usr/share/nginx/html; | |
| 6 | ||
| 7 | location = /snow-health { proxy_pass http://unix:/socket/navidrome.sock:/ping; } | |
| 8 | location /snow.oauth2/ { | |
| 9 | proxy_set_header Host $host; | |
| 10 | proxy_set_header X-Forwarded-Proto https; | |
| 11 | proxy_pass http://{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "AUTH_SERVICE" }}{{ .Address }}:{{ .Port }}{{ end }}; | |
| 12 | } | |
| 13 | location = /snow-auth { | |
| 14 | internal; | |
| 15 | proxy_pass http://{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "AUTH_SERVICE" }}{{ .Address }}:{{ .Port }}{{ end }}/snow.oauth2/auth; | |
| 16 | proxy_pass_request_body off; | |
| 17 | proxy_set_header Content-Length ""; | |
| 18 | proxy_set_header Host $host; | |
| 19 | proxy_set_header X-Forwarded-Proto https; | |
| 20 | proxy_set_header X-Forwarded-Uri $request_uri; | |
| 21 | } | |
| 22 | location = /snow-signin { | |
| 23 | internal; | |
| 24 | return 302 /snow.oauth2/start?rd=https://$host$request_uri; | |
| 25 | } | |
| 26 | location = /ping { | |
| 27 | proxy_set_header Remote-User ""; | |
| 28 | proxy_pass http://unix:/socket/navidrome.sock:; | |
| 29 | } | |
| 30 | location = /auth/login { | |
| 31 | proxy_set_header Remote-User ""; | |
| 32 | proxy_set_header X-Forwarded-For ""; | |
| 33 | proxy_pass http://unix:/socket/navidrome.sock:; | |
| 34 | } | |
| 35 | location /rest/ { | |
| 36 | proxy_set_header Remote-User ""; | |
| 37 | proxy_set_header X-Forwarded-For ""; | |
| 38 | proxy_pass http://unix:/socket/navidrome.sock:; | |
| 39 | } | |
| 40 | location = /snow-session { | |
| 41 | auth_request /snow-auth; | |
| 42 | auth_request_set $snow_user $upstream_http_x_auth_request_preferred_username; | |
| 43 | proxy_set_header Remote-User $snow_user; | |
| 44 | proxy_set_header X-Forwarded-For ""; | |
| 45 | proxy_set_header X-Nd-Authorization ""; | |
| 46 | proxy_set_header Authorization ""; | |
| 47 | add_header Cache-Control "no-store" always; | |
| 48 | proxy_pass http://unix:/socket/navidrome.sock:/app/; | |
| 49 | } | |
| 50 | location = /manage { return 308 /manage/; } | |
| 51 | location = /app { return 308 /app/; } | |
| 52 | location ~ ^/(app|manage|share)/ { | |
| 53 | auth_request /snow-auth; | |
| 54 | error_page 401 = /snow-signin; | |
| 55 | auth_request_set $snow_user $upstream_http_x_auth_request_preferred_username; | |
| 56 | proxy_set_header Remote-User $snow_user; | |
| 57 | proxy_set_header X-Forwarded-For ""; | |
| 58 | proxy_set_header X-Nd-Authorization ""; | |
| 59 | proxy_set_header Authorization ""; | |
| 60 | rewrite ^/manage/(.*)$ /app/$1 break; | |
| 61 | proxy_pass http://unix:/socket/navidrome.sock:; | |
| 62 | } | |
| 63 | location /api/ { | |
| 64 | auth_request /snow-auth; | |
| 65 | error_page 401 = @native_api; | |
| 66 | auth_request_set $snow_user $upstream_http_x_auth_request_preferred_username; | |
| 67 | proxy_set_header Remote-User $snow_user; | |
| 68 | proxy_set_header X-Forwarded-For ""; | |
| 69 | proxy_set_header X-Nd-Authorization ""; | |
| 70 | proxy_set_header Authorization ""; | |
| 71 | proxy_pass http://unix:/socket/navidrome.sock:; | |
| 72 | } | |
| 73 | location @native_api { | |
| 74 | proxy_set_header Remote-User ""; | |
| 75 | proxy_set_header X-Forwarded-For ""; | |
| 76 | proxy_pass http://unix:/socket/navidrome.sock:; | |
| 77 | } | |
| 78 | location = /settings.js { | |
| 79 | auth_request /snow-auth; | |
| 80 | alias /etc/nginx/conf.d/settings.js; | |
| 81 | add_header Cache-Control "no-store"; | |
| 82 | } | |
| 83 | location / { | |
| 84 | auth_request /snow-auth; | |
| 85 | error_page 401 = /snow-signin; | |
| 86 | sub_filter '<head>' '<head><script src="/snow-bootstrap.js"></script>'; | |
| 87 | sub_filter 'type="module" crossorigin src=' 'type="application/x-snow-module" crossorigin src='; | |
| 88 | sub_filter_once off; | |
| 89 | try_files $uri $uri/ /index.html; | |
| 90 | } | |
| 91 | } |
service/navidrome/service.pkl+66-21| ... | ... | @@ -1,31 +1,76 @@ |
| 1 | 1 | amends "../../config/Service.pkl" |
| 2 | 2 | |
| 3 | 3 | import "../../config/site.pkl" as site |
| 4 | import "../../config/OpenID.pkl" as sso | |
| 5 | import "../forward-auth/service.pkl" as forwardAuth | |
| 4 | 6 | |
| 5 | name = "Navidrome" | |
| 7 | name = "Music" | |
| 8 | access = "media" | |
| 9 | stageIsolation = if (site.preview) "fresh" else "clone" | |
| 6 | 10 | |
| 7 | container { | |
| 8 | image = "docker.io/deluan/navidrome@sha256:59ce76e6e06193fbfbb1736a93b8468227e1ea663fc7b25b1da13fbb97f5197b" | |
| 9 | ||
| 10 | http { | |
| 11 | containerPort = 4533 | |
| 12 | subdomain = "music" | |
| 13 | authRole = "media" | |
| 14 | userHeader = "Remote-User" | |
| 15 | checkPath = "/ping" | |
| 11 | requirements { | |
| 12 | new sso.Client { | |
| 13 | clientId = module.id | |
| 14 | name = module.name | |
| 15 | redirectUris { "https://\(module.containers["app"].http.hostname)/snow.oauth2/callback" } | |
| 16 | 16 | } |
| 17 | } | |
| 17 | 18 | |
| 18 | volumes { | |
| 19 | ["/data"] {} | |
| 20 | ["/music"] { src = "\(site.mediaRoot)/Music"; readOnly = true } | |
| 21 | } | |
| 19 | secrets { ["cookie"] = forwardAuth.secrets["cookie"] } | |
| 22 | 20 | |
| 23 | env { | |
| 24 | ["ND_SCANNER_GROUPALBUMRELEASES"] = "1" | |
| 25 | ["ND_BASEURL"] = "https://\(module.container.http.hostname)/" | |
| 26 | ["ND_PID_ALBUM"] = "folder" | |
| 27 | ["ND_EXTAUTH_USERHEADER"] = "Remote-User" | |
| 28 | ["ND_EXTAUTH_TRUSTEDSOURCES"] = "10.88.0.1/32" | |
| 29 | ["ND_PORT"] = "4533" | |
| 21 | containers { | |
| 22 | ["auth"] = (forwardAuth.container!!) { | |
| 23 | lifecycle = "prestartSidecar" | |
| 24 | hostNetwork = true | |
| 25 | http = null | |
| 26 | tcp { new { name = "oauth"; containerPort = 4180 } } | |
| 27 | envTemplate = "OAUTH2_PROXY_HTTP_ADDRESS=127.0.0.1:{{ env \"NOMAD_PORT_auth_oauth\" }}" | |
| 28 | env { | |
| 29 | ["OAUTH2_PROXY_COOKIE_NAME"] = "_snow_\(module.id)" | |
| 30 | ["OAUTH2_PROXY_COOKIE_DOMAINS"] = module.containers["app"].http.hostname!! | |
| 31 | ["OAUTH2_PROXY_WHITELIST_DOMAINS"] = "\(module.containers["app"].http.hostname),\(sso.hostname)" | |
| 32 | ["OAUTH2_PROXY_REDIRECT_URL"] = "https://\(module.containers["app"].http.hostname)/snow.oauth2/callback" | |
| 33 | ["OAUTH2_PROXY_ALLOWED_GROUPS"] = "role:media" | |
| 34 | ["OAUTH2_PROXY_AUTH_LOGGING"] = "false" | |
| 35 | ["OAUTH2_PROXY_REQUEST_LOGGING"] = "false" | |
| 36 | } | |
| 37 | } | |
| 38 | ["server"] { | |
| 39 | image = "docker.io/deluan/navidrome@sha256:59ce76e6e06193fbfbb1736a93b8468227e1ea663fc7b25b1da13fbb97f5197b" | |
| 40 | lifecycle = "prestartSidecar" | |
| 41 | hostNetwork = true | |
| 42 | volumes { | |
| 43 | ["/data"] {} | |
| 44 | ["/socket"] {} | |
| 45 | when (site.preview) { ["/music"] {} } | |
| 46 | when (!site.preview) { ["/music"] { src = "\(site.mediaRoot)/Music"; readOnly = true } } | |
| 47 | } | |
| 48 | env { | |
| 49 | ["ND_SCANNER_GROUPALBUMRELEASES"] = "1" | |
| 50 | ["ND_BASEURL"] = "https://\(module.containers["app"].http.hostname)/" | |
| 51 | ["ND_PID_ALBUM"] = "folder" | |
| 52 | ["ND_EXTAUTH_USERHEADER"] = "Remote-User" | |
| 53 | ["ND_EXTAUTH_TRUSTEDSOURCES"] = "@" | |
| 54 | ["ND_ADDRESS"] = "unix:/socket/navidrome.sock" | |
| 55 | when (site.preview) { ["ND_ENABLEEXTERNALSERVICES"] = "false" } | |
| 56 | } | |
| 57 | } | |
| 58 | ["app"] { | |
| 59 | image = "ghcr.io/jeffvli/feishin@sha256:6c75a4d3b99065ac245e2eb2b693fde3e5f2a6fe41c9e255da4fcb8948071965" | |
| 60 | hostNetwork = true | |
| 61 | entrypoint = "nginx" | |
| 62 | args { "-g"; "daemon off;" } | |
| 63 | cpu = 100 | |
| 64 | memory = 256 | |
| 65 | http { containerPort = 9180; loopback = true; subdomain = "music"; checkPath = "/snow-health" } | |
| 66 | volumes { | |
| 67 | ["/socket"] { readOnly = true } | |
| 68 | ["/etc/nginx/conf.d/settings.js"] { config = "settings.js" } | |
| 69 | ["/usr/share/nginx/html/snow-bootstrap.js"] { config = "bootstrap.js" } | |
| 70 | } | |
| 71 | secretFiles { | |
| 72 | ["/etc/nginx/conf.d/default.conf"] = read("nginx.conf").text | |
| 73 | .replaceAll("AUTH_SERVICE", "\(module.id)-auth") | |
| 74 | } | |
| 30 | 75 | } |
| 31 | 76 | } |
service/navidrome/settings.js created+5| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | window.SERVER_URL = window.location.origin; | |
| 2 | window.SERVER_NAME = 'Music'; | |
| 3 | window.SERVER_TYPE = 'navidrome'; | |
| 4 | window.SERVER_LOCK = true; | |
| 5 | window.ANALYTICS_DISABLED = true; |