Commit Graph

3454 Commits

Author SHA1 Message Date
Maximiliano Sandoval
abd07ffcff mark extern C blocks as unsafe
This is required in edition 2024.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2025-03-19 12:19:19 +01:00
Gabriel Goller
a75b97da76 log, rest-server: worker_task: add log_unfiltered
To write result message manually, bypassing tracing.

The workertasks currently get their status from parsing the log
messages in the task-log file. The problem is that if these messages are
filtered – which is now possible using the PBS_LOG env variable – some
workertasks will end up with a "stopped: unknown" status. This is not
desirable so write the message manually to the workertask file and
bypass tracing.

This way we are guaranteed that, regardless of the max logging level the
user sets, the final message (and status) is written.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2025-03-19 12:19:02 +01:00
Wolfgang Bumiller
c99308ecfc log: factor out NoWorkerTask filter
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-19 11:52:08 +01:00
Wolfgang Bumiller
6bdd07075d log: fix doctests
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-19 11:51:53 +01:00
Gabriel Goller
656fedb0c4 log: add layer for pve workertasks in perlmod crates
Add a layer that outputs messages to stderr in a specific format. In
PVE, stderr is rerouted to the tasklog if the we are within a
workertask. Therefore, ensure the stderr output is formatted
appropriately.

Reported-by: Lukas Wagner <l.wagner@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2025-03-19 09:52:35 +01:00
Gabriel Goller
f6269b800d log: introduce logging builder
Add a builder-like struct to compose a tracing logger using different
layers. Instead of having an init function per product/binary or
super-specific init functions that describe the logger, have a dynamic
builder. The builder improves the usability and makes the logging
initialization more self-explaining.

Suggested-by: Lukas Wagner <l.wagner@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2025-03-19 09:52:35 +01:00
Shannon Sterz
3e382fd29c auth-api: set content type header for the new HttpOnly ticket endpoint
otherwise some clients might struggle to interpret the body correctly

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-14 09:28:11 +01:00
Fabian Grünbichler
b82e51f15a bump proxmox-router to 3.1.1-1
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2025-03-13 13:58:50 +01:00
Fabian Grünbichler
e4bc435beb env_logger: bump to 0.11
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2025-03-13 13:55:29 +01:00
Wolfgang Bumiller
f32f48b119 router: cli: avoid unnecessary clones/allocation
The `new_args` Vec is directly passed to the other Vec's `.extend()`,
which takes an `IntoIterator` consuming it, so just pass the
intermediate `Iterator`.

The `rest` Vec owns its strings and we don't need it afterwards, so
similarly, we can consume it via `.extend()` instead of a manual
push(s.clone()) loop.

The .truncate(0) can just be .clear() - they are equivalent according
to their documentation.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-13 11:46:52 +01:00
Shannon Sterz
00c75c734d tree-wide: fix private intra doc links
a previous commit fixed up all intra doc links that were present on
public apis, this also fixes the links for private members.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-07 11:35:03 +01:00
Shannon Sterz
a9a7bbdabc auth-api: fix intra doc link for Empty
`Display` isn't used directly anymore, so fix up the intra doc link
here again.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 16:35:51 +01:00
Wolfgang Bumiller
5c7b1ab4ab tfa, auth-api: simplify and restyle Display implementation
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
4836cb5334 tree-wide: fix intra doc links
this fixes intra document links or rephrases the documentation in a
more appropriate way to remove all `broken_intra_doc_links` warnings.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
ccb34b33e2 api-macro: re-order ObjectSchema fields to be sorted
this panics when running `cargo test` otherwise, as the api macro
requires fields in `ObjectSchema`s to be sorted now.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
f0b23def30 router: fix nested doc test cases to match inteded output
commit 68b13965 (router: docs: add horizontal line before nested
command docs) broke the nested command group test case. this commit
adapts the expected output accordingly.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
4fc074b4ba network-api: ignore clippy lint about upper case acronyms
while the lint is correct about how these enum members should be
capitalized, the enum is marked as `pub` and all users of it would
need to adapt. so ignore the lint for now [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
730f908458 apt: ignore clippy lint about new having to return Self
while this is a reasonable convention to follow, in this case the new
function is part of a public trait and changing the signature would
force all users to adapt. so ignore the lint for now [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
8fc324ee73 apt: ignore clippy lint about using a slice reference instead of &Vec
while the function would be more useful as pointed out by the clippy
lint, it i currently `pub` and users of the function would need to
adapt to the change here. so ignore the lint for now.

[1]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
59898d0177 rest-server/router: ignore type complexity clippy lint
the `type_complexity` clippy lint [1] is intended to make the code
more legible in most cases. however, the lint triggers on a member of
a private enum, an example minimal rest server and a private static
variable here. so the benefits of declaring a new type that would
encapsulate this complexity is minimal. hence, ignore the warnings for
now.

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
f9dd576783 router: ignore clippy lint missing_transmute_annotations
the `ApiHandler`'s `PartialEq` implementation makes heavy use of
`transmute`. clippy wants the types to be explicitly stated here and
not inferred, to avoid potential undefined behaviour if an unexpected
type is inferred. however, the types that would be inferred here are
so complex, that the code would become illegible anyway, so ignore
this lint for now.

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#missing_transmute_annotations

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
dcc6eb9918 shared-memory: specify generic types for transmute
this annotates a `transmute` call with proper types to avoid possible
undefined behaviour, as suggested by clippy [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#missing_transmute_annotations

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
ab2d5c9777 acme/auth-api: add Default for types with un-parameterized new()
this fixes a clippy lint for types that have a `new()` function that
has no parameters [1]. this should allow using these types with
functions such as `unwrap_or_default()`.

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:25:24 +01:00
Shannon Sterz
efc8556c27 auth-api/tfa: prefer Display over ToString/an inherent function
this fixes two clippy lints that check if either `ToString` or an
inherent `to_string()` function is implement [1, 2]. `Display`
provides `ToString` for free and, thus, is preferable.

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#/inherent_to_string
[2]:
https://rust-lang.github.io/rust-clippy/master/index.html#to_string_trait_impl

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:17:35 +01:00
Shannon Sterz
d95a4f25e0 router: allow from_str on Confirmation that is not for FromStr
while usually this would improve ergonomics, in this case it isn't
clear whether all uses of `FromStr` would be considered valid here.
renaming the function would also make the type more confusing to use
as `from_str_with_default` also exists, so keep this for consistency.
this ignores a clippy lint [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:16:04 +01:00
Shannon Sterz
92ecc301b6 sys: add truncate option to OpenOptions in test case
this resolves a clippy lint that checks for uses of `create()` without
`truncate()` [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:15:43 +01:00
Shannon Sterz
946d95cfcd access-control/tfa: use ? instead of unnecessary match statements
this makes the code more concise and legible. fixes a clippy lint [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:15:22 +01:00
Shannon Sterz
a318fcedd3 tfa: remove needless as_bytes call
len() already returns the length in bytes, no need to call `as_bytes`
first. this fixes a clippy lint [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_as_bytes

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:15:11 +01:00
Shannon Sterz
0b9c1485c0 tfa: don't use block in conditions
this fixes a clippy style lint that does not allow blocks in
conditionals. moving the block out and the result into a temporary
variable should make this more legible [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:14:19 +01:00
Shannon Sterz
d980c2229b tree-wide: remove clone calls on types that are Copy
this resolves a clippy lint that checks that `clone()` isn't called on
`Copy` types as that is unnecessary [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:12:16 +01:00
Shannon Sterz
2c07729ff3 tree-wide: add parantheses to clarify precedence
this resolves a clippy lint that aims to improve legibility for people
unaware of rust's precendence rules [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#precedence

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:11:00 +01:00
Shannon Sterz
2134657529 io: clippy fix: replace map() followed by any() with just any()
this fixes a clippy lint that complains about map invocations followed
by any invocations that are just checking for identity as this can be
replaced by just the any invocation alone [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#map_all_any_identity

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-06 15:03:10 +01:00
Wolfgang Bumiller
b5e238613e auth-api: bump to 0.4.8-1
While *technically* breaking as it changes the method signature for
the `create_ticket` call to use a struct for its parameters, this is
only (supposed to be) used via its `CREATE_TICKET_API_METHOD` handler
to be passed to a router. Direct use of this does not make sense.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-04 16:03:17 +01:00
Wolfgang Bumiller
e73bc1509d rest-server: bump to 0.8.7-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-04 15:54:19 +01:00
Wolfgang Bumiller
3f6345021c router: bump to 3.1.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-04 15:54:19 +01:00
Wolfgang Bumiller
fda6fc9def client: bump to 0.5.2-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-04 15:54:19 +01:00
Wolfgang Bumiller
86336f6c88 login: bump to 0.2.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-04 15:54:19 +01:00
Wolfgang Bumiller
986b465d48 time: bump to 2.0.4-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-04 15:54:19 +01:00
Shannon Sterz
0c9ed7daa4 client: specify cookie names for authentication headers where possible
if the client knows the auth cookie's name, it now passes it on to the
relevant parts of `proxmox-login` so that the ticket is send the
correct cookie

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
bedf92c0df client: add compatibility with HttpOnly cookies
this should make it possible to use the proxmox-client crate outside
of context where HttpOnly cookies are handled for us. if a cookie
name is provided to a client, it tries to find a corresponding
`Set-Cookie` header in the login response and passes tries to parse
it as a ticket. that ticket is then passed on to proxmox-login like
any regular ticket.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
7dee2d7016 login: add functions to specify full cookie names
previously the name in which the ticket was send was derived by the
product abbreviation in the ticket itself. the assumption was that
authentication cookies would always have a name like this:
`<PRODUCT_ABBREVIATION>AuthCookie`.

this commit adds helpers that allow specifying the cookie's name by
users of this crate.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
f199b02a7a login: add helper to check whether a ticket is just informational
tickets that end in `::ticketinfo` are not properly signed and just
include information such as the timestamp when the ticket was created.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
867e890141 login: add TicketResult::HttpOnly member
this allows client to be aware that the ticket they manage is
informational only and that the real ticket should have been set via
a HttpOnly cookie.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
b28e98ca99 login: add helpers to pass cookie values when parsing login responses
depending on the context a client may or may not have access to
HttpOnly cookies. this change allows them to pass such values to
`proxmox-login` to take them into account when parsing login
responses.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
f137b5e528 login: make password optional when creating Login requests
in certain context (for example, the browser), no password needs to be
provided when using HttpOnly cookies as they are handle by said
context. so make renewing ticket with password optional and add a new
helper function that does not require a password.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
9c6d6b8d2a login: add optional field for ticket_info and make password optional
tickets created through the new HttpOnly ticket endpoint won't return
a ticket in the password field. so this field will be left empty.
hence make it optional.

the endpoint does return a ticket_info parameter, though, that
includes the information when a ticket needs to be refreshed. so add
a new optional field for that too.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
1b9def4736 auth-api: add logout method
adds a new endpoint that is useful when dealing with HttpOnly cookies
that cannot be removed by client-side javascript (and by extension
wasm) code. the logout handle simply removes the cookie that is used
for storing the current ticket. this works the same way as it does in
the front-end: by setting an expired cookie with the same name.

as cookies are now prefixed with `__Host-` by default, the cookie here
also needs to be `Secure` and have the same `Path` to not be rejected
by the browser before it can remove the old cookie.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
6a7f631709 auth-api: make regular ticket endpoint use the new types and handler
so we can re-use more code between the different ticket endpoints

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
8405154c6d auth-api: add endpoint for issuing tickets as HttpOnly tickets
this adds a new endpoint for requesting tickets. instead of returning
the ticket in the responses body, the ticket is set as a HttpOnly
cookie. this has a couple of advantages:

- the cookie cannot be stolen if an attacker downgrades the connection
  to http and injects malicious javascript (`HttpOnly`)
- we don't need to rely on the client to make sure that the cookie is
  only send in the appropriate context and only over https
  connections (`Secure`, `SameSite`).
- the cookie cannot be overwritten by other subdomains, insecure
  connections etc. (the default is to prefix them with `__Host-`)

this follows the best practice guide for secure cookies from MDN
[1]. we also set the cookies to expire when the ticket would so that
the browser removes the cookie once the ticket isn't valid anymore.

the endpoint still returns a ticket that only contains the
informational portions of the ticket but not a valid signature. this
is helpful to let clients know when to refresh the ticket by querying
this endpoint again. it still protects the cookie, though, as it
isn't a valid ticket by itself.

[1]: https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides/Cookies

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
acaffffaf9 auth-api: introduce new CreateTicket and CreateTickeReponse api types
these types are used for creating a ticket and responding to a new
ticket request.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00