File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
fr/brouillard/gitbucket/h2/controller Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,9 @@ sbt clean package
6666
6767### 1.4.0
6868
69- - compatibility with gitbucket 4.10, scala 2.12
69+ - compatibility with gitbucket 4.10, scala 2.12 [ #20 ] ( https://github.com/gitbucket-plugins/gitbucket-h2-backup-plugin/issues/20 )
70+ - allow to secure ` database/backup ` endpoint [ #1 ] ( https://github.com/gitbucket-plugins/gitbucket-h2-backup-plugin/issues/1 ) ,[ #19 ] ( https://github.com/gitbucket-plugins/gitbucket-h2-backup-plugin/issues/19 )
71+ see [ Securing backup endpoint] ( #securing-backup-endpoint ) paragraph
7072
7173### 1.3.0
7274
@@ -86,3 +88,15 @@ sbt clean package
8688
8789- introduce gitbucket-h2-backup-plugin
8890- allows to backup h2 database via a live dump
91+
92+ ## Securing backup endpoint
93+
94+ In version 1.4.0, it is possible to secure the ` database/backup ` endpoint:
95+
96+ - launch gitbucket with System property _ secure.backup_ set to true (for example ` -Dsecure.backup=true ` on the command line)
97+ - due to actual limitations of gibucket & plugins security, once the previous setting is activated,
98+ a call to ` http://YOUR_GITBUCKET/database/backup ` will be temporary redirected ` http://YOUR_GITBUCKET/api/v3/plugins/database/backup ` .
99+ You have to follow this temporary redirection.
100+ - if you call the endpoint using _ httpie_ , use the ` --follow ` parameter
101+ - this secured endpoint route is TEMPORARY you should not call it directly.
102+ If you do think that it will change in the future when gitbucket will support secured routes for plugins.
Original file line number Diff line number Diff line change @@ -25,5 +25,6 @@ class Plugin extends gitbucket.core.plugin.Plugin {
2525 override val controllers = Seq (
2626 " /admin/h2backup" -> new H2BackupController ()
2727 , " /database/backup" -> new H2BackupController ()
28+ , " /api/v3/plugins/database/backup" -> new H2BackupController ()
2829 )
2930}
Original file line number Diff line number Diff line change @@ -41,7 +41,22 @@ class H2BackupController extends ControllerBase with AdminAuthenticator {
4141 html.export(flash.get(" info" ), flash.get(" dest" ).orElse(Some (defaultBackupFileName())));
4242 })
4343
44+ get(" /api/v3/plugins/database/backup" ) {
45+ context.loginAccount match {
46+ case Some (x) if (x.isAdmin) => doExport()
47+ case _ => org.scalatra.Unauthorized ()
48+ }
49+ }
50+
4451 get(" /database/backup" ) {
52+ if (sys.props.get(" secure.backup" ) exists (_ equalsIgnoreCase " true" ))
53+ org.scalatra.TemporaryRedirect (" /api/v3/plugins/database/backup?dest=" + params.getOrElse(" dest" , defaultBackupFileName()))
54+ else {
55+ doExport()
56+ }
57+ }
58+
59+ private def doExport (): Unit = {
4560 val filePath : String = params.getOrElse(" dest" , defaultBackupFileName())
4661 exportDatabase(new File (filePath))
4762 Ok (" done: " + filePath)
You can’t perform that action at this time.
0 commit comments