Better Session Provider Documentation #6534

Closed
opened 2025-11-02 06:58:44 -06:00 by GiteaMirror · 9 comments
Owner

Originally created by @Skaronator on GitHub (Dec 16, 2020).

  • Gitea version (or commit ref): 1.13
  • Git version:
  • Operating system: Docker / Kubernetes
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

It took me litterally 1 hour to figure out how to configure the sessions properly with Postgres. The offical Gitea Documentation is really lite on that topic as you can see here https://docs.gitea.io/en-us/config-cheat-sheet/#session-session

There are only 2 lines that describe how to configure it but doesn't mention how to do it exactly. A example would be great here.

After searching in the code I found out that Gitea uses a library for that and the library has a wonderfull documentation. Maybe it make sense to a) either link their documentation in the Gitea documentation or b) copy the important parts out of it and further reference them.

https://go-macaron.com/middlewares/session#postgresql

What do you think?

...

Screenshots

Originally created by @Skaronator on GitHub (Dec 16, 2020). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.13 - Git version: - Operating system: Docker / Kubernetes <!-- Please include information on whether you built gitea yourself, used one of our downloads or are using some other package --> <!-- Please also tell us how you are running gitea, e.g. if it is being run from docker, a command-line, systemd etc. ---> <!-- If you are using a package or systemd tell us what distribution you are using --> - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - Log gist: <!-- It really is important to provide pertinent logs --> <!-- Please read https://docs.gitea.io/en-us/logging-configuration/#debugging-problems --> <!-- In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini --> ## Description It took me litterally 1 hour to figure out how to configure the sessions properly with Postgres. The offical Gitea Documentation is really lite on that topic as you can see here https://docs.gitea.io/en-us/config-cheat-sheet/#session-session There are only 2 lines that describe how to configure it but doesn't mention how to do it exactly. A example would be great here. After searching in the code I found out that Gitea uses a library for that and the library has a wonderfull documentation. Maybe it make sense to a) either link their documentation in the Gitea documentation or b) copy the important parts out of it and further reference them. https://go-macaron.com/middlewares/session#postgresql What do you think? ... ## Screenshots <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the type/docs label 2025-11-02 06:58:44 -06:00
Author
Owner

@lunny commented on GitHub (Jan 26, 2021):

macaron has been replaced by go-chi and the session middleware has been replaced by https://gitea.com/go-chi/session

@lunny commented on GitHub (Jan 26, 2021): macaron has been replaced by go-chi and the session middleware has been replaced by https://gitea.com/go-chi/session
Author
Owner

@6543 commented on GitHub (Jan 26, 2021):

@Skaronator if you like you could enhance the docu ... :) - just send a pull

@6543 commented on GitHub (Jan 26, 2021): @Skaronator if you like you could enhance the docu ... :) - just send a pull
Author
Owner

@zeripath commented on GitHub (Feb 21, 2021):

The new db session provider is even simpler than any of the rest - it simply uses the gitea db so doesn't need any configuration.

@zeripath commented on GitHub (Feb 21, 2021): The new db session provider is even simpler than any of the rest - it simply uses the gitea db so doesn't need any configuration.
Author
Owner

@6543 commented on GitHub (Feb 21, 2021):

@zeripath we should at least mention this option for clustering ...

@6543 commented on GitHub (Feb 21, 2021): @zeripath we should at least mention this option for clustering ...
Author
Owner

@ndaidong commented on GitHub (Apr 22, 2021):

@Skaronator @lunny we actually need some lines about how to store session within postgres. I've tried to change PROVIDER to postgres and PROVIDER_CONFIG to postgrest connection string, but Gitea throws error:

Apr 22 09:44:52 gs gitea[8184]: panic: pq: SSL is not enabled on the server
Apr 22 09:44:52 gs gitea[8184]: goroutine 1 [running]:
Apr 22 09:44:52 gs gitea[8184]: gitea.com/go-chi/session.Sessioner(0xc002f5d3f0, 0x1, 0x1, 0x6)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/vendor/gitea.com/go-chi/session/session.go:238 +0x1a5
Apr 22 09:44:52 gs gitea[8184]: code.gitea.io/gitea/routers/routes.WebRoutes(0xc00249cf80)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/routers/routes/web.go:133 +0x1b8
Apr 22 09:44:52 gs gitea[8184]: code.gitea.io/gitea/routers/routes.NormalRoutes(0xc00133be40)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/routers/routes/web.go:123 +0x11b
Apr 22 09:44:52 gs gitea[8184]: code.gitea.io/gitea/cmd.runWeb(0xc00133be40, 0x0, 0x0)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/cmd/web.go:138 +0x4ae
Apr 22 09:44:52 gs gitea[8184]: github.com/urfave/cli.HandleAction(0x24c10c0, 0x3728000, 0xc00133be40, 0xc00133be40, 0x0)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/vendor/github.com/urfave/cli/app.go:524 +0x105
Apr 22 09:44:52 gs gitea[8184]: github.com/urfave/cli.Command.Run(0x28c963a, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a2d0ae, 0x16, 0x0, ...)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/vendor/github.com/urfave/cli/command.go:173 +0x579
Apr 22 09:44:52 gs gitea[8184]: github.com/urfave/cli.(*App).Run(0xc0011bddc0, 0xc00003c040, 0x2, 0x2, 0x0, 0x0)
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/vendor/github.com/urfave/cli/app.go:277 +0x808
Apr 22 09:44:52 gs gitea[8184]: main.main()
Apr 22 09:44:52 gs gitea[8184]:         /workspace/gitea/main.go:115 +0xa6a
Apr 22 09:44:52 gs systemd[1]: gitea.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 22 09:44:52 gs systemd[1]: gitea.service: Failed with result 'exit-code'.
@ndaidong commented on GitHub (Apr 22, 2021): @Skaronator @lunny we actually need some lines about how to store session within postgres. I've tried to change `PROVIDER` to `postgres` and `PROVIDER_CONFIG` to postgrest connection string, but Gitea throws error: ``` Apr 22 09:44:52 gs gitea[8184]: panic: pq: SSL is not enabled on the server Apr 22 09:44:52 gs gitea[8184]: goroutine 1 [running]: Apr 22 09:44:52 gs gitea[8184]: gitea.com/go-chi/session.Sessioner(0xc002f5d3f0, 0x1, 0x1, 0x6) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/vendor/gitea.com/go-chi/session/session.go:238 +0x1a5 Apr 22 09:44:52 gs gitea[8184]: code.gitea.io/gitea/routers/routes.WebRoutes(0xc00249cf80) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/routers/routes/web.go:133 +0x1b8 Apr 22 09:44:52 gs gitea[8184]: code.gitea.io/gitea/routers/routes.NormalRoutes(0xc00133be40) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/routers/routes/web.go:123 +0x11b Apr 22 09:44:52 gs gitea[8184]: code.gitea.io/gitea/cmd.runWeb(0xc00133be40, 0x0, 0x0) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/cmd/web.go:138 +0x4ae Apr 22 09:44:52 gs gitea[8184]: github.com/urfave/cli.HandleAction(0x24c10c0, 0x3728000, 0xc00133be40, 0xc00133be40, 0x0) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/vendor/github.com/urfave/cli/app.go:524 +0x105 Apr 22 09:44:52 gs gitea[8184]: github.com/urfave/cli.Command.Run(0x28c963a, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a2d0ae, 0x16, 0x0, ...) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/vendor/github.com/urfave/cli/command.go:173 +0x579 Apr 22 09:44:52 gs gitea[8184]: github.com/urfave/cli.(*App).Run(0xc0011bddc0, 0xc00003c040, 0x2, 0x2, 0x0, 0x0) Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/vendor/github.com/urfave/cli/app.go:277 +0x808 Apr 22 09:44:52 gs gitea[8184]: main.main() Apr 22 09:44:52 gs gitea[8184]: /workspace/gitea/main.go:115 +0xa6a Apr 22 09:44:52 gs systemd[1]: gitea.service: Main process exited, code=exited, status=2/INVALIDARGUMENT Apr 22 09:44:52 gs systemd[1]: gitea.service: Failed with result 'exit-code'. ```
Author
Owner

@zeripath commented on GitHub (Apr 22, 2021):

@ndaidong what is the 👎 for?

How can I be clearer:

If you set PROVIDER=db then you don't need to set anything in PROVIDER_CONFIG and the session will just use the DB configuration.

@zeripath commented on GitHub (Apr 22, 2021): @ndaidong what is the :-1: for? How can I be clearer: If you set `PROVIDER=db` then you don't need to set anything in `PROVIDER_CONFIG` and the session will just use the DB configuration.
Author
Owner

@ndaidong commented on GitHub (Apr 23, 2021):

@zeripath thank you, it works for me now, even the log show:

Apr 23 09:32:22 gs gitea[10421]: 2021/04/23 09:32:22 ...odules/session/db.go:166:GC() [I] session/DB: error garbage collecting: pq: column "created_unix" does not exist
Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 cmd/web.go:189:listen() [I] Listen: http://0.0.0.0:18081
Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 cmd/web.go:192:listen() [I] LFS server enabled
Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 ...s/graceful/server.go:55:NewServer() [I] Starting new Web server: tcp:0.0.0.0:18081 on PID: 10421
Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 ...odules/session/db.go:166:GC() [I] session/DB: error garbage collecting: pq: column "created_unix" does not exist

Anyway, it's neccessary to update the docs and example, currently there is no word mentioning to db or posgres.

[session]
; Either "memory", "file", or "redis", default is "memory"
PROVIDER = memory
; Provider config options
; memory: doesn't have any config yet
; file: session file path, e.g. `data/sessions`
; redis: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180
; mysql: go-sql-driver/mysql dsn config string, e.g. `root:password@/session_table`
PROVIDER_CONFIG = data/sessions
@ndaidong commented on GitHub (Apr 23, 2021): @zeripath thank you, it works for me now, even the log show: ``` Apr 23 09:32:22 gs gitea[10421]: 2021/04/23 09:32:22 ...odules/session/db.go:166:GC() [I] session/DB: error garbage collecting: pq: column "created_unix" does not exist Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 cmd/web.go:189:listen() [I] Listen: http://0.0.0.0:18081 Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 cmd/web.go:192:listen() [I] LFS server enabled Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 ...s/graceful/server.go:55:NewServer() [I] Starting new Web server: tcp:0.0.0.0:18081 on PID: 10421 Apr 23 09:32:23 gs gitea[10421]: 2021/04/23 09:32:23 ...odules/session/db.go:166:GC() [I] session/DB: error garbage collecting: pq: column "created_unix" does not exist ``` Anyway, it's neccessary to update the docs and example, currently there is no word mentioning to `db` or `posgres`. ``` [session] ; Either "memory", "file", or "redis", default is "memory" PROVIDER = memory ; Provider config options ; memory: doesn't have any config yet ; file: session file path, e.g. `data/sessions` ; redis: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180 ; mysql: go-sql-driver/mysql dsn config string, e.g. `root:password@/session_table` PROVIDER_CONFIG = data/sessions ```
Author
Owner

@lunny commented on GitHub (Apr 23, 2021):

@ndaidong Could you help to send a PR to improve that?

@lunny commented on GitHub (Apr 23, 2021): @ndaidong Could you help to send a PR to improve that?
Author
Owner

@ndaidong commented on GitHub (Apr 23, 2021):

@lunny sure, my pleasure. I will send a PR this weekend.

@ndaidong commented on GitHub (Apr 23, 2021): @lunny sure, my pleasure. I will send a PR this weekend.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#6534