Skip to content

Commit 15f6ec9

Browse files
InonSlunny
authored andcommitted
LFS: make HTTP auth period configurable (#4035)
* LFS: make HTTP auth period configurable * Formatting: Removed semicolon Due to automated fmt-check failure (drone.gitea.io) * applying code reviews * Applied code review comment: Change HTTPAuthExpiry to time.Duration * Updated config cheat sheet
1 parent 832ca50 commit 15f6ec9

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

cmd/serv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func runServ(c *cli.Context) error {
268268
claims := jwt.MapClaims{
269269
"repo": repo.ID,
270270
"op": lfsVerb,
271-
"exp": now.Add(5 * time.Minute).Unix(),
271+
"exp": now.Add(setting.LFS.HTTPAuthExpiry).Unix(),
272272
"nbf": now.Unix(),
273273
}
274274
if user != nil {

custom/conf/app.ini.sample

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ LFS_START_SERVER = false
189189
LFS_CONTENT_PATH = data/lfs
190190
; LFS authentication secret, change this yourself
191191
LFS_JWT_SECRET =
192+
; LFS authentication validity period (in time.Duration), pushes taking longer than this may fail.
193+
LFS_HTTP_AUTH_EXPIRY = 20m
192194

193195
; Define allowed algorithms and their minimum key length (use -1 to disable a type)
194196
[ssh.minimum_key_sizes]

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
115115
- `LFS_START_SERVER`: **false**: Enables git-lfs support.
116116
- `LFS_CONTENT_PATH`: **./data/lfs**: Where to store LFS files.
117117
- `LFS_JWT_SECRET`: **\<empty\>**: LFS authentication secret, change this a unique string.
118+
- `LFS_HTTP_AUTH_EXPIRY`: **20m**: LFS authentication validity period in time.Duration, pushes taking longer than this may fail.
118119
- `REDIRECT_OTHER_PORT`: **false**: If true and `PROTOCOL` is https, redirects http requests
119120
on another (https) port.
120121
- `PORT_TO_REDIRECT`: **80**: Port used when `REDIRECT_OTHER_PORT` is true.

modules/setting/setting.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ var (
136136
}
137137

138138
LFS struct {
139-
StartServer bool `ini:"LFS_START_SERVER"`
140-
ContentPath string `ini:"LFS_CONTENT_PATH"`
141-
JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
142-
JWTSecretBytes []byte `ini:"-"`
139+
StartServer bool `ini:"LFS_START_SERVER"`
140+
ContentPath string `ini:"LFS_CONTENT_PATH"`
141+
JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
142+
JWTSecretBytes []byte `ini:"-"`
143+
HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
143144
}
144145

145146
// Security settings
@@ -828,6 +829,9 @@ func NewContext() {
828829
LFS.ContentPath = filepath.Join(AppWorkPath, LFS.ContentPath)
829830
}
830831

832+
sec = Cfg.Section("LFS")
833+
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(20 * time.Minute)
834+
831835
if LFS.StartServer {
832836

833837
if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {

0 commit comments

Comments
 (0)