mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-10 13:56:06 -05:00
Feature Request: Move INTERNAL_TOKEN value out of app.ini #1394
Closed
opened 2025-11-02 03:59:15 -06:00 by GiteaMirror
·
44 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
v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.3.3
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
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#1394
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 @minoru7 on GitHub (Dec 20, 2017).
[x]):Description
I'd like to request that the INTERNAL_TOKEN value that is currently placed in the app.ini during Gitea startup be moved to a separate file/config than the user-defined app.ini. It should probably be placed in a lockfile, pid, or separate gitea-system-controlled config file, etc.
The reason for this is that a lot of organizations use automation tools such as Puppet, SaltStack, Ansible, etc. to deploy configurations to servers. If the app.ini (user-defined config file) is being managed by one of these, it will overwrite the existing app.ini that includes the INTERNAL_TOKEN. This is less than ideal, and obviously breaks the functioning of Gitea.
References:
@danielfbm commented on GitHub (Dec 28, 2017):
same problem using kubernetes and configmaps, config files should not be used to save any kind of state
@xoxys commented on GitHub (Jan 11, 2018):
Any chance to fix this in near future? It's annoying to use idempotent config management with this...
@strk commented on GitHub (Jan 11, 2018):
If you provide a pull-request chances are high that it will be merged
@xoxys commented on GitHub (Jan 11, 2018):
👍 will have a look
@cdrage commented on GitHub (Mar 27, 2018):
@xoxys @strk
Any updates? We are unfortunately blocked on this and we're unable to add Gitea as a Helm chart to Kubernetes since it's trying to write to
app.ini... Despiteapp.inionly used for configuration, INTERNAL_TOKEN is being updated within in.See errors: https://storage.googleapis.com/kubernetes-jenkins/pr-logs/pull/charts/3408/pull-charts-e2e/7056/build-log.txt
Also our Helm chart PR here: https://github.com/kubernetes/charts/pull/3408
@cdrage commented on GitHub (Mar 27, 2018):
ping @lafriks
@cdrage commented on GitHub (Mar 27, 2018):
Specifically:
Which is causing the issue (Gitea is trying to write to
app.iniwhen it shouldn't..)@strk commented on GitHub (Mar 27, 2018):
I guess any update would be mentioned here.
Your best bet is providing a pull request
@lafriks commented on GitHub (Mar 27, 2018):
@cdrage you can pregenerate token and other values using gitea cli command
generatethat was added in 1.4.0 (see https://docs.gitea.io/en-us/command-line/)@cdrage commented on GitHub (Mar 28, 2018):
@lafriks Yup. I saw from your other comments on the other issues. Yes, that helps with configuration and setting up your
.inifile. However, this issue is regarding when INTERNAL_TOKEN isn't set, what gitea should do.The problem is that
app.inior whatever configuration file you use, should be immutable when deploying (through Ansible, read-only file system, etc.)My thinking:
If INTERNAL_TOKEN does not exist, the key should be automatically generated and set internally rather than being passed to the configuration file.
Reference:
96c268c0fc/modules/setting/setting.go (L924)I'll most likely push a PR later this week once I have enough time!
@Nodraak commented on GitHub (Mar 29, 2018):
Hi @cdrage! I am very much interested in deploying Gitea with a k8s Chart. If you need any help (testing, review, code, ...), don't hesitate to ping me :)
@cdrage commented on GitHub (Mar 29, 2018):
@Nodraak There's already a PR: https://github.com/kubernetes/charts/pull/3408 but we're blocked on this issue 👍
@lunny commented on GitHub (Mar 29, 2018):
Maybe put that on a file like pid? @cdrage the INTERNAL_TOKEN token will be shared by
gitea webandgitea hookprocesses. So I don't think a memory shared is enough. Any idea?@cdrage commented on GitHub (Mar 29, 2018):
@lunny Yeah, anything else preferably, pid would probably do. The code:
96c268c0fc/modules/setting/setting.go (L924)shows that INTERNAL_TOKEN is actually the only variable that it set within the configuration, no other environment variables are set / modify the configuration file after launching.Alternatively (as a hack, for now) we could set the internal token as part of the configMap within Kubernetes (before launching). But then again.. it would be nice to have it automatically generated instead.
Anyways! I'll try to push a PR this/next week.
@Nodraak commented on GitHub (Mar 30, 2018):
TL;DR: for internal gitea calls, why not call the function directly, instead of using an HTTP api?
Reading again this thread, I have some trouble understanding the utility of
INTERNAL_TOKEN.Correct me if I'm wrong, but from what I have understood:
INTERNAL_TOKEN, gitea works fine (when deployed bare metal or with kubernetes)INTERNAL_TOKEN, gitea will try to write one to the config file, which will fail when deployed with kubernetes (why? does k8s changes the file permissions? or is the problem when k8s deploys a new version which overwrite the token?)INTERNAL_TOKENseems to be used only in this function:96c268c0fc/routers/private/internal.go (L18-L24)Which is used here:
96c268c0fc/routers/private/internal.go (L39-L48)I guess the goal is to verify if the call comes from gitea itself or from outside. Then for internal gitea calls, why not call the function directly, instead of using an HTTP api?
For example, the HTTP route
/ssh/:id/updateis used here:96c268c0fc/modules/private/internal.go (L53-L70)Then, instead of
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/%d/update", keyID)andnewInternalRequest(reqURL, "POST"), why not doUpdatePublicKey(keyID)?@Nodraak commented on GitHub (Mar 30, 2018):
I've played a little with the code, and managed to substitute the calls (replace HTTP requests by function calls) and to remove all references to
INTERNAL_TOKEN. I have not tested extensively, but all the tests passes.I won't submit a PR yet, but please have a look at my two commits (the most relevant is commit
c20afe9e0a"Substitute calls") and if they solve properly this issue, I can open a PR. I am not aware of all the trade-off of gitea, so I probably missed something.@ cdrage: I did have seen that you planned to work on a PR, sorry for "stealing" your work. I just tried to naively implement my idea :)
@lafriks commented on GitHub (Mar 30, 2018):
@Nodraak what you have removed whas specially made so that ssh process would not need to create database connection that update data as this totally break sqlite3 db backend (sqlite can have only single connection that updates data)
@Nodraak commented on GitHub (Mar 30, 2018):
Ahah, so that was what I missed. Actually, I'm stupid, I should have run a
git blameand dig in the git history. Anyway.So, if I understand correctly, concurrent write access and timeouts are handled by the HTTP protocol (I guess gitea has only one webserver, so there can be only one access to the DB), instead of directly by the database. I don't see why this is a better solution, IMO it adds a lot of complexity (due to indirect calls). Moreover, sqlite support concurrent write acces: the transaction will retry until the DB is unlock or the timeout expires. By default the timeout is 0 so any concurrent write will immediatly return
Error: database is locked, but with_busy_timeoutone can set an appropriate timeout, for instance a few seconds. (the parameter _busy_timeout is passed when opening the connection)@lafriks commented on GitHub (Mar 30, 2018):
@Nodraak internal calls is planned to increase most probably if we want to support clustering of some kind
@lafriks commented on GitHub (Mar 30, 2018):
As for sqlite locking it is a bit more difficult because we use xorm and also there is GoLang layer not directly c calls
@lunny commented on GitHub (Mar 30, 2018):
Two benefit for this change from both
gitea webandgitea hookconnected to mysql or sqlite. One is to resolve sqlite share write problem. Another is SSH could be deployed different machine from web in future.@cdrage commented on GitHub (Jun 6, 2018):
Did anyone else happen to start work on this recently? This is still blocking us from deploying Gitea to Kubernetes: https://github.com/kubernetes/charts/pull/3408
@lafriks @Nodraak
@Nodraak commented on GitHub (Jun 6, 2018):
Hi
Sadly I could not take a look. For now my priorities have changed and I can't say if I will have the time to work on this issue in the future
@lunny commented on GitHub (Jun 6, 2018):
We could create a single file on
data/internal/lockto share between multiple processes?@techknowlogick commented on GitHub (Jun 6, 2018):
@cdrage Is this indeed blocking? There have been others who have deployed Gitea to kubernetes
@minoru7 commented on GitHub (Jun 6, 2018):
While I certainly have been able to work around the INTERNAL_TOKEN issue myself in Puppet and elsewhere in automation, the workarounds are less than ideal. It makes life difficult to manage Gitea settings while Gitea is modifying the settings file that I'm laying down through automation. The applications tend to fight each other. While this may not be critical, it is definitely a fairly large hiccup.
Thank you to anyone who has the time to look into this and place a PR! You would be my savior, that's for sure. ;-)
@cdrage commented on GitHub (Jun 6, 2018):
@techknowlogick Yes. You're unable to create a ConfigMap for the app.ini settings. If you go by the links you posted, it's using volumes for configuration management, rather than the better way of using ConfigMaps (more Kubernetes-esque).
@minoru7 What was your work-around?
@minoru7 commented on GitHub (Jun 6, 2018):
@cdrage Well, for Puppet, I have the configuration file being laid down only if it doesn't already exist. Which, that's fine for a new system, but defeats the purpose of Puppet and continuous configuration. If I make a change to the configuration, which happens on occasion, I have to manually delete the app.ini to have it take effect. As for Kubernetes, I haven't had enough time yet to start digging into that, so unfortunately, I don't have any help for you there, sorry.
@cdrage commented on GitHub (Jun 6, 2018):
@minoru7 Thanks!
That helps, since it's the exact same issue as when deploying to Kubernetes. Since app.ini should be immutable, it's difficult to have continuous configuration with INTERNAL_TOKEN making changes to the app.ini file.
So essentially it's also blocking any Puppet deployment too.
@lunny commented on GitHub (Jun 6, 2018):
Could INTERNAL_TOKEN be set when first set up?
@minoru7 commented on GitHub (Jun 6, 2018):
@lunny I believe, last I remember, that it was linked to the daemon or somesuch. The INTERNAL_TOKEN value changes upon each restart of the service. So that's why my original request mentioned maybe adding this to a pid file or something instead.
@lunny commented on GitHub (Jun 6, 2018):
The only one place to change the token is https://github.com/go-gitea/gitea/blob/master/modules/setting/setting.go#L918 when INTERNAL_TOKEN is empty. If it is changed each restart that maybe a bug.
@lunny commented on GitHub (Jun 6, 2018):
And in fact we can generate it via
96c268c0fc/cmd/generate.go (L55)gitea generate@cdrage commented on GitHub (Jun 6, 2018):
Yeah. The problem is that on each restart, a new token is generated. If you decide to set one yourself at start-up (providing INTERNAL_TOKEN to
app.ini) the service will run into an error of trying to modifyapp.inidespite it already being set (see my above comments for the log)@lunny commented on GitHub (Jun 6, 2018):
OK. I will investigate it.
@bkcsoft commented on GitHub (Jul 10, 2018):
So, as far as I can see, the code should only generate this token if it does not exist. Is this still an issue?
@minoru7 commented on GitHub (Jul 10, 2018):
I'm using version 1.3.2. Last time I attempted it, I generated a token and inserted it into the ini file. When I restarted the service it overwrote my InternalToken with a newly generated one, which then threw Puppet into overwriting it, which restarts the service, which Puppet then overwrites again. It was a bad situation. Not only that, but if I'm rolling out a few of these servers, I want to be able to automate that Token generation in that case. Or otherwise, the best scenario would be to take the Token out of the config file that Puppet would need to manage. I have not attempted a newer version of Gitea, so maybe you guys have sorted out my original issue? I'll give it a try soon when time permits.
@stale[bot] commented on GitHub (Jan 19, 2019):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
@andreymal commented on GitHub (Jan 19, 2019):
@stale nope plz
@cdrage commented on GitHub (Jan 21, 2019):
Yeah, this is still a major blocker getting Gitea on Kubernetes.
@pytimer commented on GitHub (Jan 23, 2019):
@cdrage I follow your helm chart to deploy gitea on the Kubernetes 1.11.6, and i add
INTERNAL_TOKENin configmap.yaml, and it's works well. So can we addinternalTokenin gitea chart values.yaml first? If this feature completed, we can change.Below is my configmap.yaml :
@cdrage commented on GitHub (Jan 23, 2019):
@pytimer The problem is that INTERNAL_TOKEN is the only value that's not hard-coded / doesn't change for Gitea. It's not "kubernetes like" to have to modify configmap.yaml afterwards. That's why we should move INTERNAL_TOKEN out of app.ini and somewhere else.
@sapk commented on GitHub (Feb 19, 2019):
I think the real problem is that internal token should not change and I can't find why it should in the code.
The PR https://github.com/go-gitea/gitea/pull/3531 should have introduced all the needed generator to provide a valid and stable configuration.
@lunny commented on GitHub (Mar 16, 2019):
In fact I like @sapk's idea.