Commit graph

65 commits

Author SHA1 Message Date
Michael Eischer
9fc5066fc4 fix most linter errors 2025-02-07 22:34:40 +01:00
Michael Eischer
be14687a9c Print fsync warning only once
The repo.Handler is freshly instantiated for every request such that it
forget that the fsync warning was already printed. Use a single instance
in the Server instead.
2023-05-13 21:50:39 +02:00
Drayton Munster
3903ed000c Add configurable htpasswd location 2022-03-25 15:39:20 -04:00
Michael Eischer
16889717c6 Add option to disable integrity check on upload 2021-08-09 15:40:50 +02:00
Konrad Wojas
9db2d52fbe Prometheus: keep auth by default
Restore the previous behaviour where the Prometheus /metrics endpoint
required auth if auth was enabled.

A new -prometheus-no-auth flag allows you to override this and disable
auth for that specific endpoint.
2021-08-09 10:49:41 +02:00
Konrad Wojas
63c8797ba3 Fix tests, add PanicOnError option
- Helper method for internal server errors with consistent logging.
- Add PanicOnError option to panic on internal server errors. This
  makes it easier to traces where the condition was hit in testing.
2021-08-09 10:49:41 +02:00
Konrad Wojas
d4cd47e503 Minor cleanup and fixes
- Do not allow '.' as path component, because it undermines depth
  checks, and add tests
- Fix GiB reporting
- Fix metrics label
- Helper function for http errors
2021-08-09 10:49:41 +02:00
Konrad Wojas
1f593fafaf Make Server use the new repo.Handler
This contains all the glue to make Server use the new repo.Handler:

- Remove all old handlers
- Add ServeHTTP to make Server a single http.Handler
- Remove Goji routing and replace by net/http and custom routing logic

Additionally, this implements two-level backup repositories.
2021-08-09 10:49:41 +02:00
Konrad Wojas
55e549e92c Move maxsizewriter to quota package 2021-08-09 10:49:41 +02:00
Alexander Neumann
723f29e594 Cleanup path before auth check 2020-09-13 11:19:26 +02:00
Konrad Wojas
f8e774393c Stricter path sanitization
Goji routes incoming requests without first URL decoding the path, so
'%2F' in a URL will not be decoded to a '/' before routing. But by the
time that we perform the path checks for private urls on r.URL.Path,
these characters have been decoded.

As a consequence, a user 'foo' could use 'foo%2Fbar' as the repo name.
The private repo check would see that the path starts with 'foo/' and
allow it, and rest-server would happily create a 'foo/bar' repo. Other
more harmful variants are possible.

To resolve this issue, we now reject any name part that contains a '/'.

Additionally, we immediately reject a few other characters that are
disallowed under some operating systems or filesystems.
2020-09-13 11:19:26 +02:00
Matt Holt
a87d968870
Add --max-size flag to limit size of repositories (#72)
* Add --max-size flag to limit repository size

* Only update repo size on successful write

* Use initial size as current size for first SaveBlob

* Apply LimitReader to request body

* Use HTTP 413 for size overage responses

* Refactor size limiting; do checks after every write

* Remove extra commented lines, d'oh

* Account for deleting blobs when counting space usage

* Remove extra commented line

* Fix unrelated bug (inverted err check)

* Update comment to trigger new CI build
2018-06-14 15:53:29 -06:00
Alexander Trost
6f412e6a8a Exclude /metrics path from private repos check (#69)
Signed-off-by: Alexander Trost <galexrt@googlemail.com>
2018-06-14 15:53:12 -06:00
Matthew Holt
df3b6aa1cf Rename Config to Server and use singular one in main 2018-04-15 08:31:50 -06:00
Matthew Holt
b98c171644 Refactor handlers: make Config not global 2018-04-12 19:55:44 -06:00
Alexander Neumann
0f72176ddd Refuse writing the config in append-only mode 2018-04-02 13:09:37 +02:00
Alexander Neumann
bf34e9d62d Implement amended API protocol v2
The version is now selected via the HTTP request header "Accept".
2018-01-23 23:34:32 +01:00
Zlatko Čalušić
cd4d054887 Introduce ListBlobsV2()
Returns not only blob names, but also their sizes.

References:
 https://github.com/restic/restic/issues/1567
 https://github.com/restic/restic/pull/1571
2018-01-23 23:34:32 +01:00
Mebus
55134ae37a removed some blank lines 2018-01-23 13:56:26 +01:00
Mebus
0f85243f5a implemented wojas proposal in handlers.go 2018-01-23 13:56:26 +01:00
Mebus
75578acd66 fixed the code style with goimports 2018-01-23 13:56:26 +01:00
Mebus
6c846f856c added a feature for private repositories 2018-01-23 13:56:26 +01:00
Alexander Neumann
f02ee7386a Auto create data/ subdirs on demand
Closes #40
2018-01-05 18:04:26 +01:00
Konrad Wojas
d1504d7d66 Prometheus: add user label and delete blob metrics 2017-10-30 17:05:56 +01:00
Zlatko Čalušić
d056b85432 Check errors in many places
Admittedly, in some places just document the fact that we ignore error
return values, 'cause we don't know what to do with it.  At least, the
linter is happy.
2017-10-25 18:31:34 +02:00
Zlatko Čalušić
10951e4540 Unshadow err in one place 2017-10-25 18:19:14 +02:00
Konrad Wojas
b213d2a274 Fix goimports 2017-10-25 17:53:37 +02:00
Konrad Wojas
ca0e09261f Add Prometheus metrics
Exposes a few metrics for Prometheus under /metrics if started with --prometheus.

Example:

    # HELP rest_server_blob_read_bytes_total Total number of bytes read from blobs
    # TYPE rest_server_blob_read_bytes_total counter
    rest_server_blob_read_bytes_total{repo="test",type="data"} 2.13557024e+09
    rest_server_blob_read_bytes_total{repo="test",type="index"} 1.198653e+06
    rest_server_blob_read_bytes_total{repo="test",type="keys"} 5388
    rest_server_blob_read_bytes_total{repo="test",type="locks"} 1975
    rest_server_blob_read_bytes_total{repo="test",type="snapshots"} 10018
    # HELP rest_server_blob_read_total Total number of blobs read
    # TYPE rest_server_blob_read_total counter
    rest_server_blob_read_total{repo="test",type="data"} 3985
    rest_server_blob_read_total{repo="test",type="index"} 21
    rest_server_blob_read_total{repo="test",type="keys"} 12
    rest_server_blob_read_total{repo="test",type="locks"} 12
    rest_server_blob_read_total{repo="test",type="snapshots"} 32
    # HELP rest_server_blob_write_bytes_total Total number of bytes written to blobs
    # TYPE rest_server_blob_write_bytes_total counter
    rest_server_blob_write_bytes_total{repo="test",type="data"} 1.063726179e+09
    rest_server_blob_write_bytes_total{repo="test",type="index"} 395586
    rest_server_blob_write_bytes_total{repo="test",type="locks"} 1975
    rest_server_blob_write_bytes_total{repo="test",type="snapshots"} 1933
    # HELP rest_server_blob_write_total Total number of blobs written
    # TYPE rest_server_blob_write_total counter
    rest_server_blob_write_total{repo="test",type="data"} 226
    rest_server_blob_write_total{repo="test",type="index"} 6
    rest_server_blob_write_total{repo="test",type="locks"} 12
    rest_server_blob_write_total{repo="test",type="snapshots"} 6
2017-10-25 17:53:37 +02:00
Kenny Keslar
618b530b88 Implement an append only mode. 2017-09-13 14:46:56 +02:00
Alexander Neumann
a628c4e01a Fix directory traversal
This commit introduces the strict checks from net/http.Dir, which fixes
a directory traversal issue.

Closes #22
2017-07-30 17:37:45 +02:00
Matthew Holt
65152c7bf5 Move main function into separate package (closes #12) 2017-06-25 11:48:02 +02:00
Zlatko Čalušić
489391646d Refactor createDirectories(), improve error handling 2017-05-01 20:10:46 +02:00
Zlatko Čalušić
e93bc32c78 Remove legacy code 2017-05-01 20:02:27 +02:00
Zlatko Čalušić
e2a4dd5dab Handler cleanup 2017-05-01 20:01:52 +02:00
Alexander Neumann
84cabc7880 Make rest-server compatible (#8)
* Allow deleting config files
* Directly write to target files, with O_EXCL
2017-03-18 13:11:29 +01:00
Zlatko Čalušić
919add5012 Implement POST /path?create=true for explicit repository creation
Legacy code which created repo on first "POST /keys/foo" remains, so
restic clients <= v0.3.3 continue working.
2017-01-27 20:45:53 +01:00
Zlatko Čalušić
2c90434911 Add debug output for HTTP error cases 2017-01-16 23:39:56 +01:00
Zlatko Čalušić
c1ace4c9d9 Don't shadow config struct 2017-01-16 23:01:08 +01:00
Alexander Neumann
0f4373ed7f Replace flag with cobra 2016-12-30 21:13:51 +01:00
Zlatko Čalušić
c600048400 Use Go constants for HTTP errors 2016-12-28 19:51:25 +01:00
Zlatko Čalušić
f14b15ee31 Allow multiple repositories 2016-12-28 00:57:25 +01:00
Zlatko Čalušić
755cf10659 Use goji.io pat package to extract params 2016-12-27 18:59:47 +01:00
Zlatko Čalušić
d0027c19db Create toplevel repository directory 2016-12-27 16:15:54 +01:00
Zlatko Čalušić
fa0b53efe7 Use goji.io mux
Remove old router implementation.
2016-12-27 14:24:07 +01:00
Zlatko Čalušić
1f29574118 Add debug flag 2016-12-27 12:26:41 +01:00
Zlatko Čalušić
061d31829d Create directories before key setup, not on startup 2016-12-27 01:35:45 +01:00
Zlatko Čalušić
75c1eae7f2 Add isHashed() 2016-11-11 01:29:55 +01:00
Zlatko Čalušić
267ae63276 Remove fs package and dirty tricks it does
The Linux kernel page cache ALWAYS knows better.  Fighting it brings
only worse performance. Usage of fadvise() is wrong 9 out of 10 times.

Removing the whole fs package brings a nice 100% speedup when running
costly prune command. And that is measured on localhost, the improvement
could be much bigger when using network with higher latency.
2016-11-06 20:09:42 +01:00
Zlatko Čalušić
9bba2f0b78 Miscellaneous handlers.go changes 2016-11-06 18:59:19 +01:00
Zlatko Čalušić
bbca04fd7e Sync BLOB's to disk before returning OK status
This slows down backup command up to 25% on a very fast network (read:
localhost), but is the right thing to do. Safety first, performance
second.
2016-11-06 18:14:08 +01:00