Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security: Configuration Restrictions #119

Open
aiwaniuk opened this issue Aug 5, 2022 · 3 comments
Open

Security: Configuration Restrictions #119

aiwaniuk opened this issue Aug 5, 2022 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aiwaniuk
Copy link

aiwaniuk commented Aug 5, 2022

https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#configuration-restrictions

This is very hard thing to implement in a secure way, but if not implemented properly then it may even decrease security of environment: Agent operator assuming it works correctly, can possibly ignore other protection layers (like not running as root/user with access to important files).

Doing it on config validation level introduces some risks:

  • validation need to properly handle dir traversal cases, like: "log_file: /allowed_dir/../etc/passwd"
  • validation need to handle symlinks (for example log_file: /allowed_dir/symlink_file, symlink_file -> /etc/passwd) and if this is done only on config apply level then symlink_file location may change latter
  • also many Agents probably will be build using some collection plugins with different configuration schemes and writing generic validation will be hard (it need to be written to each plugin separately)
  • also some plugins may not even have path to files configurable, but hardcoded in executable, then it will require knowledge that some plugin is accessing some file

Doing it on runtime:
This can be done by implementing some common API to work with filesystem and apply all validation on that level. But this is also error prone, agent developers need to somehow enforce that regular API for accessing files is not used.
Similar feature was present in PHP (https://www.php.net/manual/en/ini.core.php#ini.open-basedir, https://externals.io/message/105606) and it was a lot of pain from security point of view.

Restrictions on accessing system API:
This is something that may work. Sandboxing agent process and perform checks when executables are accessing system API (for interaction with filesystem/executing executables).

Other things that it is worth to restrict next to accessing filesystem and executing commands:
SSRF bugs: If something supports some collection from url (or process some urls from configs), it may be also worth to restrict these somehow, to avoid situation when send configuration will have link for example to AWS metadata (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html): http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access which contains AWS creds for role assigned with instance

If we want to include recommendation for implementing restrictions on directories/executables sandbox approach should be recommended instead of config file validation. I believe this will allow to avoid a lot of pain from Agent implementers who will decide to implement configuration restrictions.

@tigrannajaryan tigrannajaryan added enhancement New feature or request help wanted Extra attention is needed labels Jul 6, 2023
@tigrannajaryan
Copy link
Member

@aiwaniuk good comments. The configuration is just one of the protection layers and is a weak one if we are honest and like you said very hard to implement in presence of pluggable collection components. It is probably only adequate for simple agents where the entire codebase is tightly controlled and can be guaranteed to follow whatever restrictions are put in the configuration.

I would definitely want to know how we can do better and how for example the sandboxing can work.

@aiwaniuk
Copy link
Author

Sandboxing:
General idea here is to do some filtering on system calls done by process and ensure these are not accessing files not allowlisted. Since this is done on system calls level, all code in agent plugins will go through this path.
In Linux system there are few methods that may allow doing this:

  • secomp/eBPF
  • AppArmor
  • namespaces (process may be setup in a way that only allowlisted locations are visible (mounted) in filesystem)

some examples that implements such things:

some addiational resources: https://developers.google.com/code-sandboxing

I'm not familiar with other systems like Windows.

@tigrannajaryan
Copy link
Member

Thanks @aiwaniuk

I think for something complex like that we would want to see an experimental implementation to help us understand how exactly we should modify the spec to adopt it. Ideally we would want to see a working implementation in opamp-go Agent example.

I already added "help wanted" label so if anyone wants to give it a try it is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants