Commit Graph

2871 Commits

Author SHA1 Message Date
Fabian Grünbichler
cce052e97f build: track d/control in git
and check build-dependencies before building..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-30 15:13:01 +01:00
Wolfgang Bumiller
6b0dabefd4 file logger: remove test.log after test as well
and a doc formatting fixup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 14:13:21 +01:00
Wolfgang Bumiller
09b2a5961e bump proxmox to 0.8.0
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 11:18:57 +01:00
Wolfgang Bumiller
194f2605e4 minor clippy lints
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 11:18:37 +01:00
Wolfgang Bumiller
3d29fbf15e introduce FdRef and BorrowedFd
Types used to reprecent borrowed raw file descriptors.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 10:48:05 +01:00
Wolfgang Bumiller
2216b348a1 make_tmp_file: properly guard file descriptor
and return an Fd

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 09:43:00 +01:00
Fabian Grünbichler
b210ad69eb run 'cargo fmt'
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-27 11:43:55 +01:00
Fabian Grünbichler
97509b63ad fix clippy warnings
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-27 11:43:21 +01:00
Dietmar Maurer
1d2a0d9e81 bump version to 0.7.2-1 2020-11-24 13:24:11 +01:00
Dietmar Maurer
e7cb1f20d0 implement cli command alias feature 2020-11-24 12:44:54 +01:00
Dietmar Maurer
474fae5b3d fix typo 2020-11-24 12:44:03 +01:00
Wolfgang Bumiller
bba65fe051 bump proxmox to 0.7.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-19 09:17:26 +01:00
Wolfgang Bumiller
08d6e20c63 tools: refactor hex parsing
deduplicate parsing into a `hex_to_bin_exact`

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-19 09:16:50 +01:00
Wolfgang Bumiller
46c71f7da3 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-16 14:21:45 +01:00
Fabian Grünbichler
85b5be8133 rest: check for disabled token (user)
when authenticating a token, and not just when authenticating a
user/ticket.

Reported-By: Dominik Jäger <d.jaeger@proxmox.com>

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-11 12:21:29 +01:00
Thomas Lamprecht
e6edbb5c3b daemon: rename method, endless loop, bail on exec error
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-11 10:14:01 +01:00
Dominik Csapak
d75579790c daemon: add hack for sd_notify
sd_notify is not synchronous, iow. it only waits until the message
reaches the queue not until it is processed by systemd

when the process that sent such a message exits before systemd could
process it, it cannot be associated to the correct pid

so in case of reloading, we send a message with 'MAINPID=<newpid>'
to signal that it will change. if now the old process exits before
systemd knows this, it will not accept the 'READY=1' message from the
child, since it rejects the MAINPID change

since there is no (AFAICS) library interface to check the unit status,
we use 'systemctl is-active <SERVICE_NAME>' to check the state until
it is not 'reloading' anymore.

on newer systemd versions, there is 'sd_notify_barrier' which would
allow us to wait for systemd to have all messages from the current
pid to be processed before acknowledging to the child, but on buster
the systemd version is to old...

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-11-11 09:43:00 +01:00
Wolfgang Bumiller
055793c481 api-macro: support raw method parameters
Support raw parameter name identifiers (eg. `r#type`)

    #[api(
        input: {
            properties: {
                type: {
                    type: String,
                    description: "Foo",
                },
            },
        },
    )]
    fn foo(r#type: String) { code... }

The "r#type" parameter in the fn decl will match the "type"
parameter name in the input property list.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-10 13:53:06 +01:00
Thomas Lamprecht
0c816fe383 bump proxmox-api-macro version to 0.2.3
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-05 12:13:05 +01:00
Thomas Lamprecht
0f802c8667 proxmox: loosen version requirement to api macro crate
allow updates of minor api-macro releases, breaking ones should get
the first or second version tuple bumped anyway.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-05 12:13:05 +01:00
Fabian Ebner
63b9f31c7b fix prefix for nested commands
Fixes a regression from commit f50a627f34
which resulted in re-using the prefix without sub-commands when calling
handle_simple_command(_future)

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-05 11:18:03 +01:00
Dominik Csapak
df9b42db3f tools/daemon: fix reload with open connections
instead of await'ing the result of 'create_service' directly,
poll it together with the shutdown_future

if we reached that, fork_restart the new daemon, and await
the open future from 'create_service'

this way the old process still handles open connections until they finish,
while we already start a new process that handles new incoming connections

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-05 11:14:56 +01:00
Thomas Lamprecht
5d7ae1f38c api: factor out auth logger and use for all API authentication failures
we have information here not available in the access log, especially
if the /api2/extjs formatter is used, which encapsulates errors in a
200 response.

So keep the auth log for now, but extend it use from create ticket
calls to all authentication failures for API calls, this ensures one
can also fail2ban tokens.

Do that logging in a central place, which makes it simple but means
that we do not have the user ID information available to include in
the log.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-04 17:26:34 +01:00
Wolfgang Bumiller
8a9a87bbf4 tfa: make AuthResponse fields public
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-04 13:21:41 +01:00
Thomas Lamprecht
4031710b36 server: implement access log rotation with re-open via command socket
re-use the future we already have for task log rotation to trigger
it.

Move the FileLogger in ApiConfig into an Arc, so that we can actually
update it and REST using the new one.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:53:30 +01:00
Thomas Lamprecht
6e2e7e66c5 command socket: make create_control_socket private
this is internal for now, use the comanndo socket struct
implementation, and ideally not a new one but the existing ones
created in the proxy and api daemons.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:50:24 +01:00
Thomas Lamprecht
3dd23fd3ba server: add CommandoSocket where multiple users can register commands
This is a preparatory step to replace the task control socket with it
and provide a "reopen log file" command for the rest server.

Kept it simple by disallowing to register new commands after the
socket gets spawned, this avoids the need for locking.

If we really need that we can always wrap it in a Arc<RWLock<..>> or
something like that, or even nicer, register at compile time.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:32:22 +01:00
Thomas Lamprecht
67769843da tools: file logger: avoid some possible unwraps in log method
writing to a file can explode quite easily.
time formatting to rfc3339 should be more robust, but it has a few
conditions where it could fail, so catch that too (and only really
do it if required).

The writes to stdout are left as is, it normally is redirected to
journal which is in memory, and thus breaks later than most stuff,
and at that point we probably do not care anymore anyway.

It could make sense to actually return a result here..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:32:22 +01:00
Wolfgang Bumiller
ad8fc652f6 make u2f registration challenge Deserialize
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-02 13:07:38 +01:00
Wolfgang Bumiller
a6f8f84632 make u2f attestation certificate optional
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-02 12:49:47 +01:00
Thomas Lamprecht
66b9170dda file logger: allow reopening file
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 10:03:10 +01:00
Wolfgang Bumiller
31b7620f20 bump proxmox to 0.7.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-30 15:15:32 +01:00
Wolfgang Bumiller
6255336f04 totp: rename step to period
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-30 15:13:42 +01:00
Thomas Lamprecht
95ac6d87c3 server/rest: accept also = as token separator
Like we do in Proxmox VE

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-30 13:34:26 +01:00
Thomas Lamprecht
7b2f5672c5 server/rest: user constants for HTTP headers
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-30 13:33:36 +01:00
Fabian Grünbichler
e57660691d api tokens: add authorization method
and properly decode secret (which is a no-op with the current scheme).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-30 13:15:14 +01:00
Fabian Grünbichler
971dc0e6bc REST: extract and handle API tokens
and refactor handling of headers in the REST server while we're at it.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-29 15:14:27 +01:00
Fabian Grünbichler
ed512bc26f replace Userid with Authid
in most generic places. this is accompanied by a change in
RpcEnvironment to purposefully break existing call sites.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-29 15:11:39 +01:00
Wolfgang Bumiller
0cd88fd832 bump proxmox to 0.6.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 15:04:07 +01:00
Wolfgang Bumiller
8cbf9cb7c8 add proxmox::tools::tfa
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 15:01:26 +01:00
Wolfgang Bumiller
05749ab419 test fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 14:51:22 +01:00
Fabian Grünbichler
51f5acea22 rpcenv: rename user to auth_id
since it does no longer store just a userid, but potentially an API
token identifier as well

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 13:59:24 +01:00
Thomas Lamprecht
7d34e6f3a4 api macro: reuse generated default const for "unwrap_or"
Instead of setting a default value to a const and inside an
.unwrap_or_else closure, lets set it only to the const and reuse that
later in .unwrap_or

To achieve that we move the "unrwap_or" code for param plumbing code generation
a bit later so that we have easy access to the generated const name.
As all this code is related to optional/default-value stuff it does read still
relatively OK with that change, IMO.

This has the advantage of not getting a warning like:

>  warning: constant is never used: `API_METHOD_EXAMPLE_FOO_PARAM_DEFAULT_FORCE`
>   --> src/api2/node/foo.rs
>    |
> XY |             force: {
>    |             ^^^^^
>    = note: `#[warn(dead_code)]` on by default

When one has a API endpoint like:

> #[api(
>     input: {
>         properties: {
>             force: {
>                 type: bool,
>                 optional: true,
>                 default: false,
>             },
>         },
>     },
>     ...
> )]
> /// Example
> fn example_foo(force: bool) -> Result<(), Error> {
>     if force {
>         // do something
>     }
>     Ok(())
> }

It effectively changes the output for optional parameters with a default set
and no Option<T> from

> let p = p.unwrap_or_else(|| #default_value);

to

> let p = p.unwrap_or(#const_name_for_default);

where the "#const_name_for_default" is a pub const with value
"#default_value"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-27 09:17:12 +01:00
Thomas Lamprecht
7575f890ed tools fs: fix comment typo and strange glyph
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-20 18:46:50 +02:00
Fabian Grünbichler
9af79677b2 REST: rename token to csrf_token
for easier differentiation with (future) api_token

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-19 14:02:19 +02:00
Wolfgang Bumiller
fe652c9263 bump proxmox version to 0.5.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-19 12:32:51 +02:00
Wolfgang Bumiller
9cd97f9851 proxmox::tools::fs: remove deprecated functions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-19 12:32:37 +02:00
Fabian Grünbichler
32bb67cf60 build: bump nix dependency
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-19 12:12:33 +02:00
Fabian Grünbichler
daab5a9faf proxmox: bump nix dependency
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-19 12:11:50 +02:00
Thomas Lamprecht
f10a722eda file logger: add option to make the backup user the log file owner
and use that in ApiConfig to avoid that it is owned by root if the
proxmox-backup-api process creates it first.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-19 10:37:26 +02:00