Commit Graph

538 Commits

Author SHA1 Message Date
Fabiano Fidêncio
7d37fbfdfb Merge pull request #2115 from sameo/topic/rust-nix
cargo: Use latest nix crate for all Rust code bases
2021-06-28 08:18:53 +02:00
Samuel Ortiz
f6294226e8 cargo: Use latest nix crate for all Rust code bases
Our dependencies already bring several versions of nix, we should avoid
adding even more fragementation.

Fixes #2114

Signed-off-by: Samuel Ortiz <samuel.e.ortiz@protonmail.com>
2021-06-25 03:38:37 +02:00
Maksym Pavlenko
6a93e5d593 agent: Initial watchable-bind implementation
Add support for watchable-bind storage driver. When watchable-bind storage
is present, the agent will create a watchable path in a tmpfs, and poll the
watchable-bind source to keep this new mount-point up to date.

This poll will allow the agent to present the mount-point to the
container, allowing for inotify usage by the container workload.

If a mount becomes too large, either in file count or in overall size,
we want to stop treating it as watchable, and instead just treat as a
bindmount. This'll help avoid DoS by growing tmpfs too large, as well
as limiting time spent scanning files. If a watchable-bind grows beyond
8 files (arbitrary sane number for certs/secrets) or 1MB (limit on ConfigMap size),
we treat it as a normal bind.

Fixes: #1879

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
Signed-off-by: Samuel Ortiz <samuel.e.ortiz@protonmail.com>

agent: watcher: SandboxStorages check loop cleanup
2021-06-24 10:07:06 -07:00
snir911
1faaf5f35d Merge pull request #2000 from ManaSugi/update-mount-flags
agent: Add some mount options and sort the options alphabetically
2021-06-17 11:53:11 +03:00
Manabu Sugimoto
bd27f7bab5 agent: Sort PROPAGATION and OPTIONS alphabetically to scan easily
It's hard to visually scan over the list currently.
Therefore, we should sort the list alphabetically to scan easily.

Fixes: #1999

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2021-06-16 17:23:05 +09:00
Tim Zhang
799cb27234 agent: Upgrade mio to v0.7.13 to fix epoll_fd leak problem
Fixes: #2035
Fixes: tokio-rs/tokio/#3809

Signed-off-by: Tim Zhang <tim@hyper.sh>
2021-06-15 11:35:49 +08:00
Manabu Sugimoto
e544779c61 agent: Add some mount options
Add the following mount options to catch up with the runtime spec
- silent
- loud
- (no)acl
- (no)iversion
- (no)lazytime

Fixes: #1999

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2021-06-11 15:08:46 +09:00
Manabu Sugimoto
a1247bc0bb agent: Conform to the latest nix version (0.21.0)
We need to fix some agent's code to conform to the latest nix crate
to be able to use new features of the nix.

Fixes: #1987

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2021-06-10 16:58:51 +09:00
Tim Zhang
9e3349c18e agent: Fix fd leak caused by netlink
See also: little-dude/netlink#165

Fixes: #1952

Because the author of netlink has no time to maintain the crate
(https://github.com/little-dude/netlink/issues/161), so we
need to switch the dependency to github temporarily.

Signed-off-by: Tim Zhang <tim@hyper.sh>
2021-06-03 17:23:37 +08:00
Chelsea Mafrica
33c12b6d08 Merge pull request #1929 from jodh-intel/add-agent-tracing
tracing: Add basic VSOCK tracing
2021-06-02 11:45:41 -07:00
James O. D. Hunt
a9a0eccf33 tracing: Add basic VSOCK tracing
Implement an openTelemetry custom exporter that sends trace spans to a
VSOCK socket. A VSOCK-to-span converter (such as the Kata trace
forwarder) needs to be running on the host to allow systems like Jaeger
to capture the trace spans.

By default, tracing is not enabled (meaning a NOP tracer is used). To
activate tracing, set the `agent.kata.enable_tracing=true` in the
configuration file.

The type of tracing this change introduces is "static isolated"
tracing. See [1] for further details.

> **Note:**
>
> This change only provides the foundational changes for agent
> tracing work. The feature is _not_ yet complete since it does
> not yet show the correct trace hierarchy.

Fixes: #60.

[1] - https://github.com/kata-containers/agent/blob/master/TRACING.md

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2021-06-02 18:00:05 +01:00
Tim Zhang
9bf781d704 agent: Upgrade tokio-vsock to fix fd leak of vsock socket
Fixes: #1950

The further information: rust-vsock/vsock-rs#15

Signed-off-by: Tim Zhang <tim@hyper.sh>
2021-06-02 16:03:09 +08:00
Peng Tao
c455d84571 Merge pull request #1918 from lifupan/main
cgroup: fix the issue of set mem.limit and mem.swap
2021-05-29 10:05:44 +08:00
fupan.lfp
30f4834c5b cgroup: fix the issue of set mem.limit and mem.swap
When update memory limit, we should adapt the write sequence
for memory and swap memory, so it won't fail because
the new value and the old value don't fit kernel's
validation.

Fixes: #1917

Signed-off-by: fupan.lfp <fupan.lfp@antgroup.com>
2021-05-28 15:44:14 +08:00
fupan.lfp
0ae364c8eb agent: re-enable the standard SIGPIPE behavior
The Rust standard library had suppressed the default SIGPIPE
behavior, see https://github.com/rust-lang/rust/pull/13158.
Since the parent's signal handler would be inherited by it's child
process, thus we should re-enable the standard SIGPIPE behavior as a
workaround.

Fixes: #1887

Signed-off-by: fupan.lfp <fupan.lfp@antgroup.com>
2021-05-28 15:25:05 +08:00
James O. D. Hunt
45f02227b2 tracing: Add trace points
Use the tracing crate to create automatic trace spans for the _majority_
of top-level modules.

Note that not all functions in the top-level modules can be traced:

- Some functions cannot be traced due to the requirement that all
  function parameters implement the `Debug` trait. In some cases (such
  as `netlink.rs`), objects are being passed that are defined in
  different crates and which do not implement `Debug`.
- Some functions may never return (`signal.rs`).
- Some functions are inlined.
- Some functions are very simple getter/setter functions.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2021-05-27 10:42:58 +01:00
Fabiano Fidêncio
c3f6c88668 Merge pull request #1915 from quanweiZhou/fix_start_container_failed_when_drop_all_caps
agent: fix start container failed when dropping all capabilities
2021-05-24 14:13:52 +02:00
quanweiZhou
3e4ebe10ac agent: fix start container failed when dropping all capabilities
When starting a container and dropping all capabilities,
the init child process has no permission to read the exec.fifo
file because the parent set the file mode 0o622. So change the exec.fifo file mode to 0o644.

fixes #1913

Signed-off-by: quanweiZhou <quanweiZhou@linux.alibaba.com>
2021-05-22 17:33:49 +08:00
Manabu Sugimoto
20a382c158 agent: Remove unnecessary underscore(_) variables
We should remove underscore(_) prefixed variables when ? operator is
used.

Fixes: #1903

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2021-05-21 17:45:34 +09:00
Fabiano Fidêncio
f52468bea7 agent/agent-ctl: Replace prctl crate by the capctl one
While evaluating the possibility of having kata-agent statically linked
to the GNU libc, we've ended up facing some issues with prctl.

When debugging the issues, we figured out that the crate hasn't been
maintained since 2015 and that the capctl one is a good 1:1 replacement
for what we need.

Fixes: #1844

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-05-19 20:16:26 +02:00
Fabiano Fidêncio
8aefc79314 agent: Perform a cargo update
While in the beginning of the development cycle, let's perform a `cargo
update`.

Fixes: #1883

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-05-19 09:43:17 +02:00
fupan.lfp
e5fe572f51 rustjail: separated the propagation flags from mount flags
Since the propagation flags couldn't be combinted with the
standard mount flags, and they should be used with the remount,
thus it's better to split them from the standard mount flags.

Fixes: #1699

Signed-off-by: fupan.lfp <fupan.lfp@antgroup.com>
2021-05-13 23:53:52 +08:00
Bin Liu
cc4748fa64 Merge pull request #1829 from Tim-Zhang/fix-reap
agent: avoid reaping the exit signal of execute_hook in the reaper
2021-05-12 17:24:25 +08:00
Bin Liu
15778a17e5 Merge pull request #1828 from Tim-Zhang/move-dep
agent: move the dependency tempfile to the dev-dependencies section
2021-05-12 17:21:50 +08:00
Tim Zhang
a5bb383cf3 agent: avoid reaping the exit signal of execute_hook in the reaper
Fixes: #1826

Signed-off-by: Tim Zhang <tim@hyper.sh>
2021-05-12 14:40:20 +08:00
Tim Zhang
ce7a5ba22e agent: move the dependency tempfile to the dev-dependencies section
The tempfile is only used by tests.

Fixes: #1827

Signed-off-by: Tim Zhang <tim@hyper.sh>
2021-05-12 14:39:58 +08:00
Tim Zhang
1bfc426a2b Merge pull request #1784 from liubin/fix/1783-delete-un-used-fn
agent: delete code which is no longer used
2021-05-07 14:25:26 +08:00
Fupan Li
487e165093 Merge pull request #1778 from snir911/patch_nofile
Set fixed NOFILE limit value for kata-agent
2021-05-07 13:06:10 +08:00
Snir Sheriber
a188577ebf agent: Set fixed NOFILE limit value for kata-agent
Some applications may fail if NOFILE limit is set to unlimited.
Although in some environments this value is explicitly overridden,
lets set it to a more sane value in case it doesn't.

Fixes #1715
Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
2021-05-04 15:06:11 +03:00
bin
d601ae3446 agent: delete not used comments
Delete comments meanless or make people confusion.

Fixes: #1783

Signed-off-by: bin <bin@hyper.sh>
2021-04-30 19:37:55 +08:00
bin
6038da1903 agent: delete rustjail/src/configs directory
This directory is not used anymore.

Fixes: #1783

Signed-off-by: bin <bin@hyper.sh>
2021-04-30 19:18:03 +08:00
bin
84ee8aa8b2 agent: delete not used functions
In file src/agent/rustjail/src/validator.rs,
these two functions are not used:
- get_namespace_path
- check_host_ns

Fixes: #1783

Signed-off-by: bin <bin@hyper.sh>
2021-04-30 19:17:41 +08:00
Fabiano Fidêncio
bd486f7bf3 Merge pull request #1720 from ManaSugi/update-seccomp-spec
agent: Update seccomp configuration for errnoRet and flags
2021-04-30 10:52:42 +02:00
Fabiano Fidêncio
b41d9a99b4 Merge pull request #1703 from lifupan/main_fix
fix the issue of missing set fsGroup for EphemeralStorage
2021-04-22 20:29:36 +02:00
fupan.lfp
f4c26aad00 agent: fix the issue of missing set fsGroup for EphemeralStorage
For k8s emptyDir volume, a specific fsGroup would
be set for it, thus guest should get this fsGroup
from runtime and set it properly on the EphemeralStorage
volume in guest.

Fixes: #1580

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2021-04-22 21:09:02 +08:00
David Gibson
e91591fff2 Merge pull request #1701 from dgibson/clippy
Assorted clippy fixes for Rust agent
2021-04-22 20:36:49 +10:00
Bin Liu
db4fbac1d3 Merge pull request #1722 from Tim-Zhang/use-channle-for-process-exit
agent: use channel instead of pipe(2) to send exit signal of process
2021-04-22 15:27:36 +08:00
David Gibson
0405beb2d8 agent: Remove unused Default implementation for NamespaceType
Currently we implement the Default trait for NamespaceType.  It doesn't
really make sense to have a default for this type though - you really need
to know what type of namespace you're setting.  In fact the Default
implementation is never used, so we can just drop it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:54:02 +10:00
David Gibson
7b83b7ec1f agent/uevent: Better initialize Uevent in test
We had some code that initialized a Uevent to the default value, then set
specific fields to various values.  This can be accomplished inside the one
initialized using the ..Default::default() syntax.  Making this change
stops clippy from complaining.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:57 +10:00
David Gibson
b0190a407f agent: Use vec![] macro rather than init-then-push
We have one place where we create an empty vector then immediately push
something into it.  We can do this in one step using the vec![] macro,
which stops clippy complaining.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:56 +10:00
David Gibson
1c43245e3e agent/device: Remove unneeded Result<> wrappers from uev matchers
The various type implementing the UeventMatcher trait have new() methods
which return a Result<>, however none of them can actually fail.  This is
a leftover from their development where some versions could fail to
initialize.  Remove the unneccessary wrappers to silence clippy.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:34 +10:00
David Gibson
e41cdb8b9f agent: Use str::is_empty() method in config::get_string_value()
An explicit check against "" is a bit less clear and makes clippy complain.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:29 +10:00
David Gibson
2377c0975c agent: Use CamelCase for NamespaceType values
Currently these are in all-caps, to match typical capitalization of IPC,
UTS and PID in the world at large.  However, this violates Rust's
capitalization conventions and makes clippy complain.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:24 +10:00
David Gibson
75eca6d56f agent/rustjail: Clean up error path in execute_hook()s async task
Clippy (in Rust 1.51 at least) has some complaints about this closure
inside execute_hook() because it uses explicit returns in some places
where it doesn't need them, because they're the last expression in the
function.

That isn't necessarily obvious from a glance, but we can make clippy happy
and also make things a little clearer: first we replace a somewhat verbose
'match' using Option::ok_or_else(), then rearrange the remaining code to
put all the error path first with an explicit return then the "happy" path
as the stright line exit with an implicit return.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:23 +10:00
David Gibson
6ce1e56d20 agent/rustjail: Remove an unnecessary PathBuf
PathBuf is an owned, mutable Path.  We don't need those properties in
get_value_from_cgroup() so we can use a Path instead.  This may be slightly
safer, and definitely stops clippy (version 1.51 at least) from
complaining.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:53:04 +10:00
David Gibson
3c4485ece3 agent/rustjail: Clean up some static definitions with vec! macro
DEFAULT_ALLOWED_DEVICES and DEFAULT_DEVICES are essentially global
constant lists.  They're implemented as a lazy_static! initialized Vec
values.

The code to initialize them creates an empty Vec then pushes values
onto it.  We can simplify this a bit by using the vec! macro.  This
might be slightly more efficient, and it definitely stops recent
clippy versions (e.g. 1.51) from complaining about it.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:52:59 +10:00
David Gibson
eaec5a6c06 agent/oci: Change name case to make clippy happy
Recent versions of clippy (e.g. in Rust 1.51) complain about a number
of names in the oci crate, which don't obey Rust's normal CamelCasing
conventions.

It's pretty clear that these don't obey the usual rules because they
are attempting to preserve conventional casing of existing acronyms
they incorporate ("VM", "POSIX", etc.).  However, it's been my
experience that matching the case and name conventions of your
environs is more important than matching case with external norms.

Therefore, this patch changes all the identifiers in the oci crate to
match Rust conventions.  Their users in the rustjail crate are updated
to match.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:52:54 +10:00
David Gibson
3f5fdae0d8 agent/rustjail: (trivial) Clean up comment on process_grpc_to_oci()
This comment appears to be connected specifically with this function, but
has some other items separating it for no particular reason.  It also has
a typo.  Correct both.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:52:45 +10:00
David Gibson
210f39a46f agent/rustjail: Simplify renaming imports
Functions in rustjail deal with both the local oci module's data structure
and the protocol::oci module's data structure.  Since these both cover the
OCI container config they are quite similar and have many identically named
types.

To avoid conflicts, we import many things from those modules with altered
names.  However the names we use oci* and grpc* don't fit the normal Rust
capitalization convention for types.

However by renaming the import of the 'protocols::oci' module itself to
'grpc', we can actually get rid of the many renames by just qualifying at
each use site with only a very small increase in verbosity.  As a bonus
this gets rid of multiple 'use' items scattered through the file.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-22 11:52:42 +10:00
Tim Zhang
8ecf8e5c1f agent: use channel instead of pipe to send exit signal of process
The situation is not a IPC scene, pipe(2) is too heavy.

We have tokio::sync::channel after tokio has been introduced.
The channel has better performance and easy to use.

Fixes: #1721

Signed-off-by: Tim Zhang <tim@hyper.sh>
2021-04-21 16:47:41 +08:00