Commit Graph

2871 Commits

Author SHA1 Message Date
Thomas Lamprecht
98f91a4d24 server/rest: also log user agent
allows easily to see if a request is from a browser or a proxmox-backup-client
CLI

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 11:23:49 +02:00
Thomas Lamprecht
287659dcda server/rest: implement request access log
reuse the FileLogger module in append mode.
As it implements write, which is not thread safe (mutable self) and
we use it in a async context we need to serialize access using a
mutex.

Try to use the same format we do in pveproxy, namely the one which is
also used in apache or nginx by default.

Use the response extensions to pass up the userid, if we extract it
from a ticket.

The privileged and unprivileged dameons log both to the same file, to
have a unified view, and avoiding the need to handle more log files.
We avoid extra intra-process locking by reusing the fact that a write
smaller than PIPE_BUF (4k on linux) is atomic for files opened with
the 'O_APPEND' flag. For now the logged request path is not yet
guaranteed to be smaller than that, this will be improved in a future
patch.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 11:23:49 +02:00
Thomas Lamprecht
1d07c62e74 tools file logger: fix example and comments
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 11:16:29 +02:00
Thomas Lamprecht
3b2aaa1878 tools: file logger: use option struct to control behavior
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 10:48:36 +02:00
Thomas Lamprecht
43ab000e92 server: rest: also log the query part of URL
As it is part of the request and we do so in our other products

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 10:41:05 +02:00
Thomas Lamprecht
da8439b25e server: rest: implement max URI path and query length request limits
Add a generous limit now and return the correct error (414 URI Too
Long). Otherwise we could to pretty larger GET requests, 64 KiB and
possible bigger (at 64 KiB my simple curl test failed due to
shell/curl limitations).

For now allow a 3072 characters as combined length of URI path and
query.

This is conform with the HTTP/1.1 RFCs (e.g., RFC 7231, 6.5.12 and
RFC 2616, 3.2.1) which do not specify any limits, upper or lower, but
require that all server accessible resources mus be reachable without
getting 414, which is normally fulfilled as we have various length
limits for stuff which could be in an URI, in place, e.g.:
 * user id: max. 64 chars
 * datastore: max. 32 chars

The only known problematic API endpoint is the catalog one, used in
the GUI's pxar file browser:
GET /api2/json/admin/datastore/<id>/catalog?..&filepath=<path>

The <path> is the encoded archive path, and can be arbitrary long.

But, this is a flawed design, as even without this new limit one can
easily generate archives which cannot be browsed anymore, as hyper
only accepts requests with max. 64 KiB in the URI.
So rather, we should move that to a GET-as-POST call, which has no
such limitations (and would not need to base32 encode the path).

Note: This change was inspired by adding a request access log, which
profits from such limits as we can then rely on certain atomicity
guarantees when writing requests to the log.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 10:40:39 +02:00
Thomas Lamprecht
e4bece494c server/rest: forward real client IP on proxied request
needs new proxmox dependency to get the RpcEnvironment changes,
adding client_ip getter and setter.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-16 10:36:54 +02:00
Dietmar Maurer
f3c10cc9df bump proxmox version to 0.4.4-1 2020-10-16 10:30:22 +02:00
Thomas Lamprecht
e30fd48080 server: rest: refactor code to avoid multiple log_response calls
The 'Ok::<_, Self::Error>(res)' type annotation was from a time where
we could not use async, and had a combinator here which needed
explicity type information. We switched over to async in commit
df52ba5e45 and, as the type annotation
is already included in the Future type, we can safely drop it.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-15 13:58:47 +02:00
Thomas Lamprecht
009737844c code cleanups
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-15 13:58:47 +02:00
Thomas Lamprecht
88586e9343 api: RPC environment: add client IP getter/setter to trait
This is similar to what we have in PVE and PMG now. Will be used to
set the real client IP for proxied connections.

with a dummy implementation, which avoids the need to implement it
for the CLI or Backup environments, which do not have or care for a
client IP

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-14 13:53:04 +02:00
Wolfgang Bumiller
4d8bd987a4 clippy fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-14 11:20:07 +02:00
Wolfgang Bumiller
e5456f873d clippy fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-14 11:13:20 +02:00
Thomas Lamprecht
649ff6f67f server/REST: check auth: code cleanup, better variable names
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-12 18:39:45 +02:00
Thomas Lamprecht
1fa5b1108d server/REST: make handle_request private
it's not used anywhere else, so do not suggest so

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-12 18:39:00 +02:00
Thomas Lamprecht
4becd202c5 server: get index: make content-type non mutable
feels more idiomatic

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-12 13:36:45 +02:00
Thomas Lamprecht
a049949d14 server/rest: code cleanup: use async
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-12 13:36:45 +02:00
Fabian Grünbichler
16f05d6649 REST: don't print CSRF token
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-08 15:57:22 +02:00
Dietmar Maurer
75bc02d9db bump proxmox version to 0.4.3-1 2020-10-08 09:00:22 +02:00
Thomas Lamprecht
82172720a4 tools: change constnamemap to a more automatic constnamedbitmap
We only used this for the privileges for now, and there it's a
nuisance to alter all bit definitions manually if something is added.

This change makes it count the bits up automatically.

Rename the macro to indicate that this is not a generic name map but
a more specific named bit mapping.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-08 08:54:26 +02:00
Wolfgang Bumiller
19dc729b7b formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-05 12:04:22 +02:00
Wolfgang Bumiller
9fa9c76a9c improve error messages in parse_rfc3339
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-05 09:16:51 +02:00
Thomas Lamprecht
d2b63c504a REST server: avoid hard coding world readable API endpoints
while we probably do not add much more to them, it still looks ugly.

If this was made so that adding a World readable API call is "hard"
and not done by accident, it rather should be done as a test on build
time. But, IMO, the API permission schema definitions are easy to
review, and not often changed/added - so any wrong World readable API
call will normally still caught.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-05 08:29:43 +02:00
Thomas Lamprecht
c6ab240333 rest server: cleanup use statements
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-02 13:04:08 +02:00
Wolfgang Bumiller
307cb04795 big formatting cleanup
had to be done, sorry not sorry

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-02 10:00:04 +02:00
Wolfgang Bumiller
ef5c719150 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-02 09:59:52 +02:00
Stefan Reiter
6eff0b289e rrd: fix integer underflow
Causes a panic if last_update is smaller than RRD_DATA_ENTRIES*reso,
which (I believe) can happen when inserting the first value for a DB.

Clamp the value to 0 in that case.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-10-01 14:30:32 +02:00
Dominik Csapak
ef6ccff5d1 proxmox/tools/common_regex: improve IPRE_BRACKET
by disallowing [] around ipv4 adresses (which is not very common)

we did not use this anywhere, so there should not be any compatibility
problem

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-30 06:13:58 +02:00
Dietmar Maurer
d79e1cfefe bump version to 0.4.2-1 2020-09-28 10:06:28 +02:00
Dietmar Maurer
f9763e12f9 simplify open_file_locked 2020-09-28 09:16:53 +02:00
Dominik Csapak
5440c65787 proxmox/tools/fs: create tmpfile helper
by factoring out the code we had in 'replace_file'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-28 07:09:02 +02:00
Dominik Csapak
115f003742 proxmox/tools/fs: add shared lock helper
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-28 07:02:48 +02:00
Wolfgang Bumiller
b9552a97e9 module consistency
tools/time.rs -> tools/time/mod.rs
sys/linux/procfs.rs -> sys/linux/procfs/mod.rs

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-09-22 09:02:15 +02:00
Thomas Lamprecht
29ed80c0a7 d/changelog: fixup email address
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-09-21 16:52:58 +02:00
Dietmar Maurer
c0a376058a bump version to 0.4.1-1 2020-09-21 10:22:52 +02:00
Dietmar Maurer
48d049d4bf proxmox/src/tools/email.rs: use slice instead of Vec 2020-09-21 10:03:48 +02:00
Dietmar Maurer
2702a2a7b5 bump versions to proxmox 0.4.0 and proxmox-api-macro 0.2.2 2020-09-19 06:32:06 +02:00
Dominik Csapak
3458d3fa69 api-macro: replace ident hashmap with simple find
after benchmarking (again), i found that doing a simple find instead
of saving the inidices for the ident strings in a hashmap has
no real performance impact (the max list size for the properties
are max ~25 at the moment, so this should not be impacting compile
times much) but it is much simpler

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-19 06:28:36 +02:00
Fabian Grünbichler
3be70bc4a8 permissions: introduce UserParam permission
to safely differentiate between checking
- the current user matches some static string
- the current user matches the value in some (path) parameter.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-09-18 18:20:01 +02:00
Dietmar Maurer
f84ac35804 bump version to 0.3.9, api-macro dependency to 0.2.1 2020-09-17 08:33:17 +02:00
Dietmar Maurer
2fb7f4a312 bump proxmox-api-macro version to 0.2.1-1 2020-09-17 08:26:25 +02:00
Dominik Csapak
958e72aa69 api-macro: relax Fieldname rules
by replacing more characters ('.','+') by '_' and prefix them when
it starts with a number

we sometimes need to parse such fields, e.g in serde attributes like
 #[serde(rename = "802.3ad")]

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-17 08:21:17 +02:00
Dominik Csapak
29763449f0 api-macro: fix broken binary ident search
the 'properties_' list is sorted by the the literal string of a
fieldname, but we binary-search for the 'ident_str' (which may be
different, since we map '-' to '_' for example)

by creating a hashmap to map from ident to index, we can do a simple
lookup in that case that will work

benchmarks showed no measurable performance difference

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-17 08:20:44 +02:00
Fabian Grünbichler
94c96348a7 time: add tests for gmtime range
mainly so we notice if this assumption does not hold for some platform
or changes in the future.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-09-15 13:13:40 +02:00
Fabian Grünbichler
0830d33e99 time/rfc3339: add leading zeroes for years < 1000
strftime(3) does not mention this explicitly, but years before 1000 have
their leading zero(es) stripped, which is not valid according to either
ISO-8601 or its profile RFC3339.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-09-15 13:13:29 +02:00
Fabian Grünbichler
c698d4b889 time: add tests for RFC3339 corner cases
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-09-15 13:13:17 +02:00
Fabian Grünbichler
ceefaa8095 time: allow leap seconds when parsing RFC3339
we don't ever produce those, but they are valid RFC3339 strings

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-09-15 13:12:58 +02:00
Fabian Grünbichler
ed7c58cf47 time: add test for leap second parsing/converting
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-09-15 13:12:23 +02:00
Dietmar Maurer
dc12cf44aa avoid chrono dependency, depend on proxmox 0.3.8
- remove chrono dependency

- depend on proxmox 0.3.8

- remove epoch_now, epoch_now_u64 and epoch_now_f64

- remove tm_editor (moved to proxmox crate)

- use new helpers from proxmox 0.3.8
  * epoch_i64 and epoch_f64
  * parse_rfc3339
  * epoch_to_rfc3339_utc
  * strftime_local

- BackupDir changes:
  * store epoch and rfc3339 string instead of DateTime
  * backup_time_to_string now return a Result
  * remove unnecessary TryFrom<(BackupGroup, i64)> for BackupDir

- DynamicIndexHeader: change ctime to i64

- FixedIndexHeader: change ctime to i64
2020-09-15 07:12:57 +02:00
Dietmar Maurer
110ceff08c avoid chrono dependency, depend on proxmox 0.3.8
- remove chrono dependency

- depend on proxmox 0.3.8

- remove epoch_now, epoch_now_u64 and epoch_now_f64

- remove tm_editor (moved to proxmox crate)

- use new helpers from proxmox 0.3.8
  * epoch_i64 and epoch_f64
  * parse_rfc3339
  * epoch_to_rfc3339_utc
  * strftime_local

- BackupDir changes:
  * store epoch and rfc3339 string instead of DateTime
  * backup_time_to_string now return a Result
  * remove unnecessary TryFrom<(BackupGroup, i64)> for BackupDir

- DynamicIndexHeader: change ctime to i64

- FixedIndexHeader: change ctime to i64
2020-09-15 07:12:57 +02:00