Author SHA1 Message Date
yaemiku 4c33d3f2f4 Merge branch 'default_music_folder' 2026-04-26 03:58:21 +02:00
yaemiku b2c317a449 Merge branch 'ldap_auth' 2026-04-26 03:58:13 +02:00
yaemiku 1e59ef9a81 Merge branch 'master' into ldap_auth 2026-04-26 03:42:56 +02:00
yaemiku 28ca45c6a1 Merge branch 'default_music_folder' 2026-04-26 03:10:03 +02:00
yaemiku a6349ecbed Merge branch 'ldap_auth' 2026-04-26 03:09:52 +02:00
yaemiku 094ab2e458 Merge branch 'master' into ldap_auth 2026-04-26 03:02:46 +02:00
yaemiku ac2f8c57ac Merge branch 'master' 2026-03-11 22:19:55 +01:00
yaemiku 88edd8b546 Merge branch 'master' into ldap_auth 2026-03-11 22:19:10 +01:00
yaemiku 2888fb2153 Merge branch 'master' 2026-02-19 03:26:22 +01:00
yaemiku 9c258bd316 Merge branch 'master' into ldap_auth 2026-02-19 03:25:57 +01:00
yaemiku 4305601c9e Merge branch 'ldap_auth' 2026-02-19 03:09:24 +01:00
yaemiku bb8a68fe77 Enable a flag to change username attribute in LDAP 2026-02-19 00:22:34 +01:00
yaemiku 1e99bb4a0a README LDAP env vars entries 2026-02-15 05:50:41 +01:00
yaemiku 9e331dd459 Move LDAP store out of the global variable 2026-02-15 05:01:16 +01:00
yaemiku ae99e76fc7 Merge branch 'master' into ldap_auth 2026-02-14 03:58:30 +01:00
yaemiku 4837448092 Merge remote-tracking branch 'origin' into ldap_auth 2026-02-14 03:54:36 +01:00
yaemiku eccc957fd1 Merge branch 'master' into ldap_auth
Nightly Release / Check latest commit (push) Successful in 6s
Nightly Release / Lint and test (push) Has been skipped
Nightly Release / Build and release Docker image (push) Has been skipped
2025-10-12 11:06:18 +02:00
yaemiku 6fba25ca0b ldap login logic, subsonic api hex encrypted password 2025-09-21 08:02:10 +02:00
yaemiku e5c192c83c Merge branch 'master' into ldap_auth 2025-09-21 06:37:41 +02:00
Daniel Hall d9facdcca6 Merge branch 'master' into ldap_auth 2024-09-08 10:59:37 -07:00
Daniel Hall 21b562b5fe style: Made invalid auth chain less chain-y 2024-06-26 15:54:39 -07:00
Daniel Hall 758c4c7279 lint: Fixed ineffassign on Add 2024-06-26 15:49:41 -07:00
Daniel Hall 4c5c015190 go mod tidy 2024-06-26 15:34:15 -07:00
Daniel Hall 7159e1ca09 fix: Fixed conf music path check 2024-06-26 15:33:54 -07:00
betapictoris f812c15fa1 Merge branch 'master' into ldap_auth 2024-06-10 23:00:54 -07:00
betapictoris dc98b6aa50 Merge branch 'sentriz:master' into ldap_auth 2024-04-08 19:00:41 -07:00
Daniel Hall e2415e944c Do session change on failed LDAP check 2024-04-08 18:13:16 -07:00
Daniel Hall 0f7e24b39b Fixed filter params 2024-04-08 13:52:04 -07:00
Daniel Hall f5195f15c4 Fix password check for local users 2024-04-07 12:55:29 -07:00
Daniel Hall fccf01642f Added LDAP password cache 2024-04-07 12:29:45 -07:00
Daniel Hall 5638ef5df7 Added LDAP admin filter 2024-04-07 11:24:26 -07:00
Daniel Hall 6ca68b2c26 Only allow use of subsonic API with one auth method 2024-04-07 10:43:07 -07:00
Daniel Hall b36f26e32a Have LDAP read from config 2024-04-07 10:18:00 -07:00
Daniel Hall 995c566131 Readded gofeed dep 2024-04-07 09:55:46 -07:00
Daniel Hall 6eddc2a1a9 Made withUser return a middleware and take dbc 2024-04-07 09:40:25 -07:00
betapictoris 6d7c605578 Merge branch 'master' into ldap_auth 2024-04-01 10:49:18 -07:00
Daniel Hall 6bf39cc0c4 Removed LDAP config from admin templates 2024-04-01 10:45:55 -07:00
Daniel Hall 8ba05ef14d Reverted home template 2024-04-01 10:42:11 -07:00
Daniel Hall dc3682dc8f Removed LDAP web UI 2024-04-01 10:40:42 -07:00
Daniel Hall 3cf6d0a28b Added LDAP config 2024-04-01 10:33:59 -07:00
Daniel Hall c531666eb6 Bump LDAP deps 2024-04-01 10:13:33 -07:00
Daniel 02fd31452d Merge branch 'sentriz:master' into ldap_auth 2024-02-28 13:57:45 -08:00
Daniel 9a97fa4b22 Merge branch 'master' into ldap_auth 2024-02-23 11:00:55 -08:00
Daniel 8d4c22ad2f Merge branch 'master' into ldap_auth 2024-02-22 07:35:53 -08:00
Daniel Hall 0d85e0ce02 Stopped opening up a second connection when creating a user from LDAP 2024-02-18 09:44:26 -08:00
Daniel Hall 8793a36364 Rewrote if-else to switch for LDAP results 2024-02-17 22:38:19 -08:00
Daniel Hall ac31258f88 Removed unnecessary trailing newline 2024-02-17 22:29:29 -08:00
Daniel Hall 683525aad2 Removed unused password parameter from createUserFromLDAP 2024-02-17 22:27:57 -08:00
Daniel Hall bc62b213a5 Lower-cased and removed punctuation for errors
Fixes linting
2024-02-17 22:27:08 -08:00
Daniel Hall f6ecd6d39b Added dashboard login for LDAP users 2024-02-17 22:23:38 -08:00
Daniel Hall fdceb555bf Removed unused logs 2024-02-17 22:23:12 -08:00
Daniel Hall 6301cb25bc Fix User struct from having not null passwords
This is required for LDAP auth to work, blank passwords don't work anyway.
2024-02-17 22:13:52 -08:00
Daniel Hall 408d325c2c Move LDAP into a seperate file 2024-02-17 22:12:56 -08:00
Daniel e944817f8b Merge with upstream
Merge pull request #1 from BetaPictoris/master
2024-02-15 11:00:04 -08:00
Daniel f8b0fbbfa2 Merge branch 'ldap_auth' into master 2024-02-15 10:59:33 -08:00
Daniel 90b5324179 gofmt handlers 2023-12-08 23:15:51 -08:00
Daniel 05149961b5 Used log to log instead of fmt 2023-12-08 23:15:10 -08:00
Daniel 84e29da258 Merge branch 'master' into ldap_auth 2023-12-08 23:12:25 -08:00
Daniel 7c6e1957fb Simplified code using gofmt 2023-12-08 23:10:26 -08:00
Daniel df42923f7b Made LDAP query log message match others 2023-12-08 23:04:13 -08:00
Daniel 4799fb2441 Update go-ldap/ldap to v3 2023-12-01 12:31:24 -08:00
Daniel 322aa0747a Made WithUser middleware private 2023-11-30 14:23:51 -08:00
Daniel 7558bb3f23 Merge branch 'master' into ldap_auth 2023-11-11 17:12:27 -08:00
Daniel e770eaa07a Fixed old references to use the new style
Readded goldap
Fixed `c.DB` to `c.dbc`
Fixed `WithUser`
2023-11-10 13:58:33 -08:00
Daniel a24b7c07cb Merge branch master into ldap_auth 2023-11-10 13:47:47 -08:00
BetaPictoris c03e10454c Fixed merge conflicts 2023-10-28 17:05:50 -07:00
BetaPictoris a99d63ab12 Fixed nil password causing invalid dereferences 2023-10-27 16:02:47 -07:00
BetaPictoris 667cf731fd Extract out LDAP connection creation 2023-10-27 15:48:41 -07:00
BetaPictoris 38ea72bbc6 Only try to login if there is exactly 1 user, otherwise return an error. 2023-10-27 10:53:43 -07:00
BetaPictoris d6d51ed9f7 Update username error message to match Subsonic API 2023-10-27 10:50:33 -07:00
beta 9e5b8d4ac8 Fixed newLDAPUser being reset 2023-09-09 09:55:29 -07:00
beta 238856ad73 Fixed newLDAPUser def 2023-09-09 09:49:48 -07:00
beta 7de6cf1e9e Fixed use of newLDAPUser 2023-09-09 09:48:54 -07:00
beta e7d6fdab69 Fixed bug where two requests got merged 2023-09-09 09:37:36 -07:00
beta 94027dcf9b Fixed variable defs 2023-09-09 09:28:57 -07:00
beta 46dac6d463 Check errors in ldap do handler 2023-09-09 09:27:12 -07:00
Daniel fc08e0a171 Merge branch 'sentriz:master' into ldap_auth 2023-09-05 02:53:33 +00:00
Daniel c317046fc9 Merge branch 'sentriz:master' into ldap_auth 2023-08-15 15:39:05 -07:00
BetaPictoris a558947da6 Fixed SetSetting err checking 2023-08-06 03:20:29 -07:00
BetaPictoris e5f815c79e Fixed filter labels 2023-08-06 03:14:43 -07:00
BetaPictoris 80f5facbd2 Added c.DB.SetSetting (errcheck) 2023-08-06 03:12:36 -07:00
BetaPictoris 23d23c7c6a Fixed r param revive 2023-08-06 03:04:59 -07:00
BetaPictoris 1fd8c9b2c3 Fix else if (gocritic) 2023-08-06 03:02:13 -07:00
BetaPictoris 9c56bf61ab Fixed for LDAP connection 2023-08-06 03:00:00 -07:00
BetaPictoris 79b28ef653 Fixed ineffassign to 2023-08-06 02:58:40 -07:00
BetaPictoris d8338590fd Added LDAP user creation 2023-08-06 02:54:17 -07:00
BetaPictoris fdb2ec66de Added LDAP auth if there is a user 2023-08-06 01:33:21 -07:00
BetaPictoris 6c8f5fa968 Added go-ldap dep 2023-08-06 00:43:20 -07:00
BetaPictoris 6602495032 Added a way of disabling LDAP auth 2023-08-06 00:40:26 -07:00
BetaPictoris 6b2f853b3c Removed eURL file 2023-08-05 22:12:13 -07:00
BetaPictoris 23e797e62a Addd default value for LDAP config page 2023-08-05 22:11:05 -07:00
BetaPictoris 1fab192195 Added TODO 2023-08-05 18:48:01 -07:00
BetaPictoris 98be763e37 Added saving of LDAP settings 2023-08-05 18:46:47 -07:00
BetaPictoris 830ab090fd Fixed typo 2023-08-05 18:42:27 -07:00
BetaPictoris 13bb999bd5 Made TLS checkbox work.
TODO: Make the styles match the rest of the page and move them out of inline.
2023-08-05 17:06:37 -07:00
BetaPictoris ae9f95aa75 Added LDAP route 2023-08-05 16:43:03 -07:00
BetaPictoris c5b35a6ff1 Added LDAP config template 2023-08-05 16:30:54 -07:00
BetaPictoris cf3f6666e0 Added LDAP link 2023-08-05 15:19:10 -07:00
10 changed files with 355 additions and 14 deletions

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
*.db
*.db.*.bak
*db-wal
*db-shm
*.sql
+9
View File
@@ -76,6 +76,15 @@ password can then be changed from the web interface
| `GONIC_TRANSCODE_CACHE_SIZE` | `-transcode-cache-size` | **optional** size of the transcode cache in MB (0 = no limit) |
| `GONIC_TRANSCODE_EJECT_INTERVAL` | `-transcode-eject-interval` | **optional** interval (in minutes) to eject transcode cache (0 = never) |
| `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) |
| `GONIC_LDAP_FQDN` | `-ldap-fqdn` | **optional** the name of the server to connect to (required for LDAP) |
| `GONIC_LDAP_PORT` | `-ldap-port` | **optional** what port the LDAP server is hosted on (_default_ `389`) |
| `GONIC_LDAP_TLS` | `-ldap-tls` | **optional** whether gonic will connect to the LDAP server using TLS (_default_ `false`) |
| `GONIC_LDAP_BASE_DN` | `-ldap-base-dn` | **optional** the base DN for LDAP objects (required for LDAP, escaping the commas might be necessary if using environmental variable) |
| `GONIC_LDAP_USERNAME_ATTR` | `-ldap-username-attr` | **optional** attribute used by the LDAP server for usernames, gets prepended to BaseDN (_default_ `uid`) |
| `GONIC_LDAP_BIND_USER` | `-ldap-bind-user` | **optional** the bind user to bind to LDAP with (required for LDAP) |
| `GONIC_LDAP_BIND_PASS` | `-ldap-bind-pass` | **optional** the password of the LDAP bind user (required for LDAP) |
| `GONIC_LDAP_FILTER` | `-ldap-filter` | **optional** the filter to select LDAP objects with (escaping the commas might be necessary if using environmental variable) |
| `GONIC_LDAP_ADMIN_FILTER` | `-ldap-admin-filter` | **optional** the filter to select LDAP admin objects with (escaping the commas might be necessary if using environmental variable) (_default_ `(memberof=cn=admin)`) |
## multi valued tags (v0.16+)
+23 -2
View File
@@ -39,6 +39,7 @@ import (
"go.senan.xyz/gonic/infocache/artistinfocache"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/listenbrainz"
"go.senan.xyz/gonic/playlist"
"go.senan.xyz/gonic/podcast"
@@ -84,6 +85,26 @@ func main() {
confExcludePattern := flag.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)")
var ldapConfig ldap.Config
var ldapStore = make(ldap.LDAPStore)
flag.StringVar(&ldapConfig.BindUser, "ldap-bind-user", "", "the bind user to bind to LDAP with (required for LDAP)")
flag.StringVar(&ldapConfig.BindPass, "ldap-bind-pass", "", "the password of the LDAP bind user (required for LDAP)")
flag.StringVar(&ldapConfig.BaseDN, "ldap-base-dn", "", "the base DN for LDAP objects (required for LDAP)")
flag.StringVar(&ldapConfig.UsernameAttr, "ldap-username-attr", "uid", "attribute used by the LDAP server for usernames, gets prepended to BaseDN (optional)")
flag.StringVar(&ldapConfig.Filter, "ldap-filter", "", "the filter to select LDAP objects with (optional)")
flag.StringVar(&ldapConfig.AdminFilter, "ldap-admin-filter", "(memberof=cn=admin)", "the filter to select LDAP objects with (optional)")
flag.StringVar(&ldapConfig.FQDN, "ldap-fqdn", "", "the name of the server to connect to (required for LDAP)")
flag.UintVar(&ldapConfig.Port, "ldap-port", 389, "what port the LDAP server is hosted on (optional)")
flag.BoolVar(&ldapConfig.TLS, "ldap-tls", false, "whether gonic will connect to the LDAP server using TLS (optional)")
if ldapConfig.FQDN != "" {
if ldapConfig.BindUser == "" || ldapConfig.BindPass == "" || ldapConfig.BaseDN == "" {
log.Fatal("a server was provided for an LDAP connection, but configuration is incomplete")
}
}
var confMultiValueGenre, confMultiValueArtist, confMultiValueAlbumArtist multiValueSetting
flag.Var(&confMultiValueGenre, "multi-value-genre", "setting for multi-valued genre scanning (optional)")
flag.Var(&confMultiValueArtist, "multi-value-artist", "setting for multi-valued track artist scanning (optional)")
@@ -253,11 +274,11 @@ func main() {
return url.String()
}
ctrlAdmin, err := ctrladmin.New(dbc, sessDB, scannr, podcast, lastfmClient, resolveProxyPath)
ctrlAdmin, err := ctrladmin.New(dbc, sessDB, scannr, podcast, lastfmClient, resolveProxyPath, ldapConfig, ldapStore)
if err != nil {
log.Panicf("error creating admin controller: %v\n", err)
}
ctrlSubsonic, err := ctrlsubsonic.New(dbc, scannr, musicPaths, *defaultMusicPath, *confPodcastPath, cacheDirAudio, cacheDirCovers, jukebx, playlistStore, scrobblers, podcast, transcoder, lastfmClient, artistInfoCache, albumInfoCache, tagReader, resolveProxyPath)
ctrlSubsonic, err := ctrlsubsonic.New(dbc, scannr, musicPaths, *defaultMusicPath, *confPodcastPath, cacheDirAudio, cacheDirCovers, jukebx, playlistStore, scrobblers, podcast, transcoder, lastfmClient, artistInfoCache, albumInfoCache, tagReader, resolveProxyPath, ldapConfig, ldapStore)
if err != nil {
log.Panicf("error creating subsonic controller: %v\n", err)
}
+1 -1
View File
@@ -304,7 +304,7 @@ type User struct {
ID int `gorm:"primary_key"`
CreatedAt time.Time
Name string `gorm:"not null; unique_index" sql:"default: null"`
Password string `gorm:"not null" sql:"default: null"`
Password string `sql:"default: null"`
LastFMSession string `sql:"default: null"`
ListenBrainzURL string `sql:"default: null"`
ListenBrainzToken string `sql:"default: null"`
+3
View File
@@ -13,6 +13,7 @@ require (
github.com/env25/mpdlrc v0.7.4
github.com/fatih/structs v1.1.0
github.com/fsnotify/fsnotify v1.9.0
github.com/go-ldap/ldap/v3 v3.4.6
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
github.com/gorilla/securecookie v1.1.2
@@ -38,11 +39,13 @@ require (
)
require (
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/PuerkitoBio/goquery v1.12.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
github.com/go-openapi/jsonpointer v0.23.1 // indirect
github.com/go-openapi/swag/jsonname v0.26.0 // indirect
github.com/gorilla/context v1.1.2 // indirect
+12
View File
@@ -1,4 +1,6 @@
cloud.google.com/go v0.33.1/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
@@ -8,6 +10,8 @@ github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuN
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO8RIBo=
github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
@@ -37,6 +41,10 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-asn1-ber/asn1-ber v1.5.5 h1:MNHlNMBDgEKD4TcKr36vQN68BA00aDfjIt3/bD50WnA=
github.com/go-asn1-ber/asn1-ber v1.5.5/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-ldap/ldap/v3 v3.4.6 h1:ert95MdbiG7aWo/oPYp9btL3KJlMPKnP58r09rI8T+A=
github.com/go-ldap/ldap/v3 v3.4.6/go.mod h1:IGMQANNtxpsOzj7uUAMjpGBaOVTC4DYyIy8VsTdxmtc=
github.com/go-openapi/jsonpointer v0.23.1 h1:1HBACs7XIwR2RcmItfdSFlALhGbe6S92p0ry4d1GWg4=
github.com/go-openapi/jsonpointer v0.23.1/go.mod h1:iWRmZTrGn7XwYhtPt/fvdSFj1OfNBngqRT2UG3BxSqY=
github.com/go-openapi/swag/jsonname v0.26.0 h1:gV1NFX9M8avo0YSpmWogqfQISigCmpaiNci8cGECU5w=
@@ -57,6 +65,7 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
@@ -143,8 +152,11 @@ github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 h1:sLILANWN76ja66/K4k/mBqJuCjDZaM67w+Ru6rEB0s0=
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981/go.mod h1:Rx8XB1ck+so+41uu9VY1gMKs1CPQ2NTq0pzf+OCCQHo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
+225
View File
@@ -0,0 +1,225 @@
package ldap
import (
"errors"
"fmt"
"log"
"time"
"go.senan.xyz/gonic/db"
"github.com/go-ldap/ldap/v3"
)
// LDAPStore maps users to a cached password
type LDAPStore map[string]CachedLDAPpassword
// Add caches a password username set.
func (store LDAPStore) Add(username, password string) {
store[username] = CachedLDAPpassword{
Password: password,
ExpiresAt: time.Now().Add(time.Hour * 8), // Keep the password valid for 8 hours.
}
}
// IsValid checks if a user's password is stored in the cache and checks if a
// given password is valid.
func (store LDAPStore) IsValid(username, password string) bool {
cached, ok := store[username]
if !ok {
return false
}
if cached.Password != password {
return false
}
return cached.IsValid()
}
// CachedLDAPpassword stores an LDAP user's password and a time at which the
// server should no longer accept it.
type CachedLDAPpassword struct {
Password string
ExpiresAt time.Time
}
func (password CachedLDAPpassword) IsValid() bool {
return password.ExpiresAt.After(time.Now())
}
// Cofig stores the user's LDAP server options.
type Config struct {
BindUser string
BindPass string
BaseDN string
UsernameAttr string
Filter string
AdminFilter string
FQDN string
Port uint
TLS bool
}
func (c Config) IsSetup() bool {
// This is basically checking if LDAP is setup, if ldapFQDN isn't set we can
// assume that the user hasn't configured LDAP.
return c.FQDN != ""
}
func CheckLDAPcreds(username string, password string, dbc *db.DB, config Config, store LDAPStore) (bool, error) {
if !config.IsSetup() {
return false, nil
}
if store.IsValid(username, password) {
log.Println("Password authenticated via cache!")
return true, nil
}
log.Println("Checking password against LDAP server ...")
// Now, we can try to connect to the LDAP server.
l, err := createLDAPconnection(config)
if err != nil {
// Return a generic error.
log.Println("Failed to connect to LDAP server:", err)
return false, errors.New("failed to connect to LDAP server")
}
defer l.Close()
// Create the user if it doesn't exist on the database already.
err = createUserFromLDAP(username, dbc, config, l)
if err != nil {
log.Println("Failed to create user from LDAP:", err)
return false, err
}
// After we have a connection, let's try binding
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
Username: fmt.Sprintf("%s=%s,%s", config.UsernameAttr, username, config.BaseDN),
Password: password,
})
if err == nil {
// Authentication was OK
store.Add(username, password)
return true, nil
}
log.Println("Failed to bind to LDAP server:", err)
return false, nil
}
// Creates a user from creds
func createUserFromLDAP(username string, dbc *db.DB, config Config, l *ldap.Conn) error {
user := dbc.GetUserByName(username)
if user != nil {
return nil
}
if !config.IsSetup() {
return nil
}
isAdmin := doesLDAPAdminExist(username, config, l)
log.Println(username, isAdmin)
if !doesLDAPUserExist(username, config, l) {
return errors.New("no such user")
}
newUser := db.User{
Name: username,
Password: "", // no password because we want auth to fail.
IsAdmin: isAdmin,
}
err := dbc.Create(&newUser).Error
if err != nil {
return err
}
log.Println("User created via LDAP:", username)
return nil
}
// doesLDAPAdminExist checks if an admin exists on the server.
func doesLDAPAdminExist(username string, config Config, l *ldap.Conn) bool {
filter := fmt.Sprintf("(&(%s=%s)%s)", config.UsernameAttr, ldap.EscapeFilter(username), config.AdminFilter)
searchReq := ldap.NewSearchRequest(
config.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
filter,
[]string{"dn"},
nil,
)
result, err := l.Search(searchReq)
if err != nil {
log.Println("failed to query LDAP server:", err)
return false
}
if len(result.Entries) == 1 {
return true
}
return false
}
// doesLDAPUserExist checks if a user exists on the server.
func doesLDAPUserExist(username string, config Config, l *ldap.Conn) bool {
filter := fmt.Sprintf("(&(%s=%s)%s)", config.UsernameAttr, ldap.EscapeFilter(username), config.Filter)
searchReq := ldap.NewSearchRequest(
config.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
filter,
[]string{"dn"},
nil,
)
result, err := l.Search(searchReq)
if err != nil {
log.Println("failed to query LDAP server:", err)
return false
}
if len(result.Entries) == 1 {
return true
}
return false
}
// Creates a connection to an LDAP server.
func createLDAPconnection(config Config) (*ldap.Conn, error) {
protocol := "ldap"
if config.TLS {
protocol = "ldaps"
}
// Now, we can try to connect to the LDAP server.
l, err := ldap.DialURL(fmt.Sprintf("%s://%s:%d", protocol, config.FQDN, config.Port))
if err != nil {
// Warn the server and return the error.
log.Println("Failed to connect to LDAP server", err)
return nil, err
}
// After we have a connection, let's try binding
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
Username: fmt.Sprintf("%s=%s,%s", config.UsernameAttr, config.BindUser, config.BaseDN),
Password: config.BindPass,
})
if err != nil {
log.Println("Failed to bind to LDAP:", err)
return nil, errors.New("wrong username or password")
}
return l, nil
}
+6 -1
View File
@@ -27,6 +27,7 @@ import (
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/handlerutil"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/podcast"
"go.senan.xyz/gonic/scanner"
"go.senan.xyz/gonic/server/ctrladmin/adminui"
@@ -48,11 +49,13 @@ type Controller struct {
podcasts *podcast.Podcasts
lastfmClient *lastfm.Client
resolveProxyPath ProxyPathResolver
ldapConfig ldap.Config
ldapStore ldap.LDAPStore
}
type ProxyPathResolver func(in string) string
func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts *podcast.Podcasts, lastfmClient *lastfm.Client, resolveProxyPath ProxyPathResolver) (*Controller, error) {
func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts *podcast.Podcasts, lastfmClient *lastfm.Client, resolveProxyPath ProxyPathResolver, ldapConfig ldap.Config, ldapStore ldap.LDAPStore) (*Controller, error) {
c := Controller{
ServeMux: http.NewServeMux(),
@@ -62,6 +65,8 @@ func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts
podcasts: podcasts,
lastfmClient: lastfmClient,
resolveProxyPath: resolveProxyPath,
ldapConfig: ldapConfig,
ldapStore: ldapStore,
}
resp := respHandler(adminui.TemplatesFS, resolveProxyPath)
+22 -2
View File
@@ -1,28 +1,48 @@
package ctrladmin
import (
"log"
"net/http"
"github.com/gorilla/sessions"
"go.senan.xyz/gonic/ldap"
)
func (c *Controller) ServeLoginDo(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(CtxSession).(*sessions.Session)
username := r.FormValue("username")
password := r.FormValue("password")
user := c.dbc.GetUserByName(username)
if username == "" || password == "" {
sessAddFlashW(session, []string{"please provide username and password"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
}
user := c.dbc.GetUserByName(username)
if user == nil || password != user.Password {
if c.ldapConfig.IsSetup() {
ok, err := ldap.CheckLDAPcreds(username, password, c.dbc, c.ldapConfig, c.ldapStore)
if err != nil {
log.Println("Failed to check LDAP credentials:", err)
sessAddFlashW(session, []string{"failed to check LDAP credentials"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
} else if !ok {
sessAddFlashW(session, []string{"invalid username / password"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
}
} else if user == nil || user.Password != password {
sessAddFlashW(session, []string{"invalid username / password"})
sessLogSave(session, w, r)
http.Redirect(w, r, r.Referer(), http.StatusSeeOther)
return
}
user = c.dbc.GetUserByName(username)
// put the user name into the session. future endpoints after this one
// are wrapped with WithUserSession() which will get the name from the
// session and put the row into the request context
+53 -8
View File
@@ -10,6 +10,7 @@ import (
"io"
"log"
"net/http"
"strings"
"time"
"go.senan.xyz/gonic/db"
@@ -18,6 +19,7 @@ import (
"go.senan.xyz/gonic/infocache/artistinfocache"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/playlist"
"go.senan.xyz/gonic/podcast"
"go.senan.xyz/gonic/scanner"
@@ -73,7 +75,7 @@ type Controller struct {
resolveProxyPath ProxyPathResolver
}
func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, defaultMusicPath string, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, tagReader tags.Reader, resolveProxyPath ProxyPathResolver) (*Controller, error) {
func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, defaultMusicPath string, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, tagReader tags.Reader, resolveProxyPath ProxyPathResolver, ldapConfig ldap.Config, ldapStore ldap.LDAPStore) (*Controller, error) {
c := Controller{
ServeMux: http.NewServeMux(),
@@ -100,7 +102,7 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, defaultMus
chain := handlerutil.Chain(
withParams,
withRequiredParams,
withUser(dbc),
withUser(dbc, ldapConfig, ldapStore),
)
chainRaw := handlerutil.Chain(
chain,
@@ -231,39 +233,82 @@ func withRequiredParams(next http.Handler) http.Handler {
})
}
func withUser(dbc *db.DB) handlerutil.Middleware {
func withUser(dbc *db.DB, ldapConfig ldap.Config, ldapStore ldap.LDAPStore) handlerutil.Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params := r.Context().Value(CtxParams).(params.Params)
// ignoring errors here, a middleware has already ensured they exist
username, _ := params.Get("u")
password, _ := params.Get("p")
passwordHex, _ := params.Get("p")
token, _ := params.Get("t")
salt, _ := params.Get("s")
passwordAuth := token == "" && salt == ""
tokenAuth := password == ""
tokenAuth := passwordHex == ""
if tokenAuth == passwordAuth {
_ = writeResp(w, r, spec.NewError(10,
"please provide `t` and `s`, or just `p`"))
return
}
var password string
if passwordAuth && passwordHex != "" {
if strings.HasPrefix(passwordHex, "enc:") {
raw := strings.TrimPrefix(passwordHex, "enc:")
decoded, err := hex.DecodeString(raw)
if err != nil {
log.Println("Failed to decode hex password:", err)
_ = writeResp(w, r, spec.NewError(40, "invalid password encoding"))
return
}
password = string(decoded)
} else {
// if not prefixed with "enc:", treat as plain text
password = passwordHex
}
}
user := dbc.GetUserByName(username)
if user == nil {
_ = writeResp(w, r, spec.NewError(40,
"invalid username %q", username))
if ldapConfig.IsSetup() {
// Complete auth using LDAP
log.Println("Authenticating using LDAP ...")
ok, err := ldap.CheckLDAPcreds(username, password, dbc, ldapConfig, ldapStore)
if err != nil {
log.Println("Failed to check LDAP creds:", err)
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
if !ok {
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
withUser := context.WithValue(r.Context(), CtxUser, user)
next.ServeHTTP(w, r.WithContext(withUser))
return
}
log.Println("Authenticating using built-in ...")
if user == nil {
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
var credsOk bool
if tokenAuth {
credsOk = checkCredsToken(user.Password, token, salt)
} else {
credsOk = checkCredsBasic(user.Password, password)
}
if !credsOk {
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
return
}
withUser := context.WithValue(r.Context(), CtxUser, user)
next.ServeHTTP(w, r.WithContext(withUser))
})