Commit Graph

62 Commits

Author SHA1 Message Date
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
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
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
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
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
Shannon Sterz
6f61b991a0 auth-api: check for new prefixed cookies as well
this makes sure that newly generated cookies that are prefixed with,
for example, `__Host-`, for security purposes, are correctly picked
up on. otherwise, the new cookies would not be able to yield proper
authentication.

currently this still falls back to insecure non-prefixed cookies. we
should deprecate them in the long-term and remove this fallback.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Shannon Sterz
b598e03287 auth-api: extend AuthContext with prefixed cookie name
this adds the function `prefixed_auth_cookie_name` to the
`AuthContext` trait. said function can be used by users of this crate
to modify the expected prefix of the auth cookie. most products
should be able to use the default of `__Host-` though, so this also
adds a default implementation.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
2025-03-04 15:53:29 +01:00
Wolfgang Bumiller
f01f934963 auth-api: bump to 0.4.7-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-01-15 12:47:08 +01:00
Thomas Lamprecht
f4868ff519 tree-wide: check in d/control meta changes for newer debcargo
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-26 14:44:33 +01:00
Wolfgang Bumiller
d6e86d670b tree-wide: unify workspace inherited attributes
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-09-20 08:42:45 +02:00
Wolfgang Bumiller
3d812952bc auth-api: bump to 0.4.6
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-09-05 14:15:11 +02:00
Wolfgang Bumiller
c319c5925d auth-api: bump to 0.4.5
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-08-14 11:35:15 +02:00
Maximiliano Sandoval
0b19e344d7 auth-api: remove lazy_static dependency
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-08-14 10:33:42 +02:00
Maximiliano Sandoval
642db84474 auth-api: docs: remove wrong return info
The method returns a boolean.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
2024-08-07 20:58:04 +02:00
Maximiliano Sandoval
77fe0f6954 docs: clippy: add indentation to doc list items
Fixes the clippy warning:

warning: doc list item missing indentation
   --> proxmox-subscription/src/subscription_info.rs:179:9
    |
179 |     ///  (this mode is used to decide whether to refresh the subscription information)
    |         ^
    |
    = help: if this is supposed to be its own paragraph, add a blank line
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
    = note: `#[warn(clippy::doc_lazy_continuation)]` on by default
help: indent this line
    |
179 |     ///   (this mode is used to decide whether to refresh the subscription information)
    |          +

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
2024-08-07 20:58:04 +02:00
Wolfgang Bumiller
150f203209 auth-api: bump to 0.4.4
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-24 14:32:28 +02:00
Maximiliano Sandoval
c8b975799b fix typos in strings
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-07-22 08:49:42 +02:00
Maximiliano Sandoval
72ab48eb55 fix typos in rust api documentation
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-07-22 08:49:42 +02:00
Wolfgang Bumiller
540e9a8134 auth-api: bump to 0.4.3
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-11 15:26:00 +02:00
Wolfgang Bumiller
3545d67b1f auth-api: bump version to 0.4.2
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-03 15:26:23 +02:00
Wolfgang Bumiller
0652d81977 tree-wide: enable doc_cfg and doc_auto_cfg for docs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-02 11:59:53 +02:00
Maximiliano Sandoval
52cf0c05f5 auth-api: do not clone struct implementing Copy
Fixes the clippy warning:

warning: using `clone` on type `Option<&dyn AuthContext>` which implements the `Copy` trait
   --> proxmox-auth-api/src/api/mod.rs:111:5
    |
111 | /     AUTH_CONTEXT
112 | |         .lock()
113 | |         .unwrap()
114 | |         .clone()
    | |________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
    = note: `#[warn(clippy::clone_on_copy)]` on by default
help: try dereferencing it
    |
111 ~     (*AUTH_CONTEXT
112 +         .lock()
113 +         .unwrap())
    |

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-06-28 11:09:48 +02:00
Maximiliano Sandoval
18dda8106b remove unnecesary pub(self)
Fixes the clippy warning:

warning: unnecessary `pub(self)`
    --> proxmox-tfa/src/api/mod.rs:1268:1
     |
1268 | pub(self) fn bool_is_false(v: &bool) -> bool {
     | ^^^^^^^^^ help: remove it
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pub_self

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-06-28 10:22:58 +02:00
Maximiliano Sandoval
aff76f9e0e remove needless borrows
Fixes the following clippy warnings:

warning: the borrowed expression implements the required traits
  --> proxmox-tfa/src/api/recovery.rs:86:24
   |
86 |         Ok(hex::encode(&hmac))
   |                        ^^^^^ help: change this to: `hmac`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

and

warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> proxmox-network-api/src/api_impl.rs:108:47
    |
108 |                 interface.set_bond_slave_list(&slaves)?;
    |                                               ^^^^^^^ help: change this to: `slaves`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
    = note: `#[warn(clippy::needless_borrow)]` on by default

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-06-28 10:22:58 +02:00
Wolfgang Bumiller
90f954005a auth-api: bump to 0.4.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-06-19 12:10:41 +02:00
Wolfgang Bumiller
e5c8d70324 auth-api: add PasswordAuthenticator
This is the PbsAuthenticator with the hardcoded shadow.json/lock
configurable.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-06-13 11:14:36 +02:00
Wolfgang Bumiller
aae8a03dc4 auth-api: bump version to 0.4.0
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-05-22 16:04:04 +02:00
Wolfgang Bumiller
9c95b4d66e auth-api: rustfmt
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-05-22 15:41:56 +02:00
Wolfgang Bumiller
fc75d98cb3 auth-api: cleanup a warning
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-05-22 15:40:12 +02:00
Wolfgang Bumiller
a6dc4d322d auth-api: remove unnecessary allocation
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-05-22 15:38:26 +02:00
Stefan Sterz
5b4cb9b124 auth-api: fix types compilefail test
due to missing `use` statements they failed, as they should, but for
the wrong reasons. also adapt a test case that presumably was meant
to test whether `TokennameRef` can be compared, but instead
duplicated the `UsernameRef` test case.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2024-05-22 10:26:44 +02:00
Stefan Sterz
4d6922e2c4 auth-api: move to hmac signing for csrf tokens
previously we used our own hmac-like implementation for csrf token
signing that simply appended the key to the message (csrf token).
however, this is possibly insecure as an attacker that finds a
collision in the hash function can easily forge a signature. after all,
two messages would then produce the same start conditions before
hashing the key. while this is probably a theoretic attack on our csrf
implementation, it does not hurt to move to the safer standard hmac
implementation that avoids such pitfalls.

this commit re-uses the hmac key wrapper used for the keyring. it also
keeps the old construction around so we can use it for a transition
period between old and new csrf token implementations.

this is a breaking change as it changes the signature of the
`csrf_secret` method of the `AuthContext` trait to return an hmac
key.

also exposes `assemble_csrf_prevention_toke` so we can re-use this
code here instead of duplicating it in e.g. proxmox-backup's
auth_helpers.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2024-05-22 10:26:40 +02:00
Stefan Sterz
8609fb58ef auth-api: use constant time comparison for csrf tokens
by using openssl's `memcmp::eq()` we can avoid potential side-channel
attack on the csrf token comparison. this comparison's runtime only
depends on the length of the two byte vectors, not their contents.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2024-05-22 10:26:38 +02:00
Stefan Sterz
b926ea1f5c auth-api: add ability to use hmac singing in keyring
previously we only used asymmetric cryptographic schemes to
authenticate tickets. this is fairly costly and not necessary in every
instance. imagine a service that runs as a single daemon. this daemon
is then the only party that needs to sign and verify tickets. this
makes hmac perfectly suitable for such usecases. hmac has some
advantages over asymmetric schemes:

- much simpler and well reviewed construction
- much faster and better optimized crypto primitives (hash functions)

this commit first introduces a new hmac key wrapper that uses openssl's
hmac implementation and can easily be reused by other parts of the
code. it also refactors the keyring code to make it easier to rotate
new hmac keys into place so switching to hmac keys is easier.

hmac keys are symmetric, so the verification key is the same key as the
signing key. this breaks the previous assumption by the keyring that
these correspond to public and private keys. thus, this commit
introduces two wrapper enums to distinguish between hmac and asymmetric
signature schemes.

the verification of hmac keys is also done via `openssl::memcmp::eq()`
to avoid potential timing side-channel attacks.

below are some simple benchmarks done with criterion.rs to show how much
faster hmac is, no matter the actual hash function:

rsa 4096 + sha256        time:   [2.7825 ms 2.7907 ms 2.7995 ms]
ed25519                  time:   [94.411 µs 94.840 µs 95.324 µs]
hmac sha256              time:   [5.7202 µs 5.7412 µs 5.7645 µs]
hmac sha384              time:   [6.6577 µs 6.6780 µs 6.7006 µs]
hmac sha3_256            time:   [5.6930 µs 5.7114 µs 5.7322 µs]

rsa with 4096 bit keys and a sha256 digest is our current default. the
test itself consists of a single sign + verification cycle. criterion
repeats this test as it sees fit to arrive at the above numbers.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2024-05-22 10:26:36 +02:00
Stefan Sterz
09d31a1a8b auth-api: move to Ed25519 signatures
previously we used P-256 as the curve of our choice for ec signatures.
however, in the meantime Ed25519 has become a lot more wide-spread.
this simplifies our ec generation code significantly while keeping the
same security level. Ed25519 was also specifically designed and
reviewed to avoid implementation errors likely making it a more secure
choice

note that Ed25519 as a signature scheme always uses sha512, so signing
or verifying with a chosen digest is not supported.

as this mostly affects newly generated keys, this should not break any
existing setups.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2024-05-22 10:26:35 +02:00
Stefan Sterz
8e566591d5 auth-api: move signing into the private key
this commit moves the current ticket signing code into the private key
implementation. the upside is that the caller does not need to deal
with openssl's `Signer` directly. it also simplifies and unifies the
code by using the same helper for verifying a signature and creating it.

also derive `Clone` on `PrivateKey` and `PublicKey`. as they are
essentially thin wrappers around `openssl::pkey::PKey<Private>` and
`openssl::pkey::PKey<Public>`, which can be cloned, deriving `Clone`
just makes them easier to use.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2024-05-22 10:26:33 +02:00
Thomas Lamprecht
863d760340 auth-api: bump version to 0.3.5
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-04-24 21:22:33 +02:00
Thomas Lamprecht
d73eb3dcf1 tree-wide: run cargo fmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-03-25 17:04:17 +01:00
Christoph Heiss
0475421498 auth-api: implement Display for Realm{, Ref}
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
2024-03-25 17:03:27 +01:00
Wolfgang Bumiller
2c2783451f bump proxmox-auth-api to 0.3.4
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-03-19 11:09:49 +01:00
Dietmar Maurer
a6f1b36fa6 proxmox-auth-api: use const_format to define static strings
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2024-03-18 10:19:48 +01:00
Wolfgang Bumiller
d9b783f1a8 bump proxmox-auth-api to 0.3.3
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-02-02 14:01:57 +01:00
Wolfgang Bumiller
3932e5bedf bump proxmox-auth-api to 0.3.2
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-11-27 14:46:59 +01:00
Wolfgang Bumiller
d951b3329f bump proxmox-auth-api to 0.3.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-24 11:03:49 +02:00
Wolfgang Bumiller
4ca8dbf74f auth-api: fixup examples
These were missing the new client-ip parameter in the auth
function calls which was introduced to support `PAM_RHOST`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-10 09:06:35 +02:00