mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-09 04:25:18 -05:00
It should be possible to provide a file to LFS_JWT_SECRET #10942
Closed
opened 2025-11-02 09:22:42 -06:00 by GiteaMirror
·
26 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.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
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/proposal
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#10942
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @varanauskas on GitHub (Jun 1, 2023).
Feature Description
TLDR:
LFS_JWT_SECRTshould be able to be stored in a separate file outlined by outlined byLFS_JWT_SECRET_URISecrets in the
[security]section of config allow providing both an inline secret as well as a file where the secret is stored with the_URIsuffix.For example
This allows for better installation/maintenance of Gitea, as /etc/gitea/app.ini could be stored in version control, as all secrets would be outlined separately.
Proposal:
I propose adding a new config key
LFW_JWT_SECRET_URIthat would work the same asINTERNAL_TOKEN_URIby allowing users to specify a separate file where theLFS_JWT_SECRETis storedScreenshots
No response
@varanauskas commented on GitHub (Jun 1, 2023):
I do not have Go experience, but could try implementing this as it seems simple enough, as long as someone can review my changes
@lonix1 commented on GitHub (Jun 17, 2023):
Excellent idea.
Two points:
There are four secrets, and two have a file option:
We should use docker compose secrets for this, so for example
SECRET_KEY_URIis mounted as/run/secrets/my-secret-key. But when I did that I discovered it is mounted asroot:rootand gitea runs asgitea:gitea.Ideally we should have file secrets for all four secrets. But how do we deal with the second point? (How did you do it?)
@techknowlogick commented on GitHub (Jun 17, 2023):
@lonix1 two have the URI as an option.
As well, if you are using the docker image, then all of them are, in theory, available as reading from a file if using env vars.
@lonix1 commented on GitHub (Jun 17, 2023):
Thanks, you are right! I was probably looking at an old
app.example.ini. So onlyJWT_SECRET_URIandLFS_JWT_SECRET_URIare needed.I assume you mean this?...
EDIT: actually, by putting them into env vars, it's a bad idea. They could get logged.
@wxiaoguang commented on GitHub (Jun 17, 2023):
Make environment-to-ini support loading key value from file #24832
@lonix1 commented on GitHub (Jun 17, 2023):
Thank you very much @wxiaoguang for your advice. But I'm struggling to understand that PR (I'm not a go developer). Is there an example how to use it?
@wxiaoguang commented on GitHub (Jun 17, 2023):
It's for docker users. See the documents.
And https://docs.gitea.com/1.20/installation/install-with-docker#managing-deployments-with-environment-variables
@lonix1 commented on GitHub (Jun 17, 2023):
Oh! 😄 Ok, that is what we were talking about above. But as I said there, keeping secrets in environment variables is a bad idea. Sometimes it's the only option though.
@varanauskas is right, we should have four file-based options for the four secrets.
But we need to consider that there is no good way to load them into the app, without leaking secrets. Maybe env vars is the only way, I hope there is a better way.
@wxiaoguang commented on GitHub (Jun 17, 2023):
Sorry I didn't get your point. See:
They are indeed able to be stored in your file.
@lonix1 commented on GitHub (Jun 17, 2023):
Sorry @wxiaoguang, I didn't see that part.
So we can do this:
docker-compose.yml$ cat ./INTERNAL_TOKEN$ cat ./JWT_SECRET$ cat ./LFS_JWT_SECRET$ cat ./SECRET_KEYIs that what you mean?
@wxiaoguang commented on GitHub (Jun 17, 2023):
Yes, it should work this way.
If it doesn't work, feel free to open an issue for it (with reproducible steps)
@lonix1 commented on GitHub (Jun 17, 2023):
@wxiaoguang Thanks! That is very good news.
@varanauskas I am going to do it this way. I will let you know my results.
@lonix1 commented on GitHub (Jun 17, 2023):
My findings are here.
@lonix1 commented on GitHub (Jun 17, 2023):
Update TL;DR:
The environment-to-ini option is not suitable. It is not meant for secrets - it will hardcode the secrets into
app.iniwhich will mean they are readable by anyone on the host.So @varanauskas proposal is still good:
INTERNAL_TOKEN_URIandSECRET_KEY_URIJWT_SECRET_URIandLFS_JWT_SECRET_URITo avoid the "leaking secrets by logging env vars" problem, the solution:
'0600'app.ini, those four secrets are referenced indirectly:@wxiaoguang commented on GitHub (Jun 17, 2023):
I can understand your meaning but I can't understand why it is a problem.
The
app.iniis 0600 by default:I do not understand why
they are readable by anyone on the host.If there is anyone who can read
app.ini, they can also read your "secret files" at the same time.@lonix1 commented on GitHub (Jun 17, 2023):
Thanks @wxiaoguang you are right. You help me a lot today.
So there are
threetwo solutions:JWT_SECRET_URIandLFS_JWT_SECRET_URIexpose secrets via environment variables, e.g. fromdoes not work properlyenv_file@varanauskas commented on GitHub (Jun 19, 2023):
It is my understanding environment-to-ini modifies the app.ini file.
This unfortunately does not fit my use case, what I want to do is this:
thus option of secrets being added to app.ini from env automatically do not fit this use case
@lonix1 commented on GitHub (Jun 19, 2023):
@varanauskas Agreed, I have the same use case.
The env-to-ini option writes to the
app.iniso it is inappropriate. (But to be fair that is it's purpose. I suggested that they exclude the four secrets from this behaviour.)So we need your idea of
XXX_URIenv vars for the secrets, and they should not write to theapp.ini.(I have a compromise solution which keeps secrets out of version control, but I'm using automation (ansible). I'm unsure of your approach to deployment.)
@varanauskas commented on GitHub (Jun 19, 2023):
Exactly I also use Ansible
@wxiaoguang commented on GitHub (Jun 19, 2023):
Actually, unlike other secrets, this "LFS_JWT_SECRET" do not need to be pre-generated.
You can keep it empty, then when Gitea starts, the secret will be generated automatically.
@varanauskas commented on GitHub (Jun 19, 2023):
Is it okay if LFS_JWT_SECRET is different on each boot with Same db and sessions?
@lonix1 commented on GitHub (Jun 19, 2023):
If you also use ansible, this is my compromise until there is a better way:
app.ini.j2template which contains those variables; file is0600The implications of this are:
app.ini.j2can be checked into source control (no secrets in there)app.inifile on the server does contain secrets, but is only accessible to the ansible user, and has mode0600app.ini, gitea never writes to it, so when I run the ansible role again it is not detected as "changed" and then overwrittenI wish there were a better way. But I tried all the other ways and they weren't as good:
app.iniwhich breaks future ansible runs@wxiaoguang commented on GitHub (Jun 19, 2023):
I think it is OK because the LFS_JWT_SECRET is a short-live token for LFS operations. Each token is re-generated for each
git-lfs-authenticate.@techknowlogick commented on GitHub (Jun 21, 2023):
I've implemented the other secrets to be able to be loaded via URI in the linked PR. If anyone want to test it that would be appreciated :)
@lonix1 commented on GitHub (Jun 23, 2023):
I can try find ttime to test it, which version must I get?
@techknowlogick commented on GitHub (Jun 23, 2023):
@lonix1 the nightly version would have it. either the binary https://dl.gitea.com/gitea/main/ or the
:nightlydocker image would be where you can run it from.