Linux Capability
This article shows configuration and dependent gem installation instructions for enabling Linux capabilities on Fluentd core.
Linux capabilities grant privileges to processes and executables that are otherwise reserved for the root user (UID 0). You can use these in conjunction with Fluentd plugins to enable the underlying Ruby executable read access to input sources.
Prerequisites
gccandmakeetc. for building C extension sourceslibcap-ng packageand its development packagelibcap-ng-devon Debian GNU/Linux and Ubuntulibcap-ng-develon CentOS 7/8, Fedora 33, AmazonLinux 2
pkg-config packagefor linkinglibcap-nglibraryRuby and its development packages
ruby-devon Debian GNU/Linux and Ubunturuby-develon CentOS 7/8, Fedora 33, AmazonLinux 2
Fluentd v1.12 or later
Install capability handling gem
Fluentd uses the capng_c gem to handle Linux capabilities.
Add this line to your Fluentd' or td-agent's Gemfile:
And then execute:
Or install it yourself as for Fluentd:
Or install it yourself as for td-agent:
Note: capng_c uses pkg-config to link the libcap-ng library. If you couldn't handle Linux capability with capng_c installation, please confirm pgk-config package is installed on your box.
Capability handling on in_tail
in_tailThe Fluentd core plugin in_tail handles the following Linux capabilities:
CAP_DAC_READ_SEARCH(:dac_read_searchonin_tailcode)CAP_DAC_OVERRIDE(:dac_overrideonin_tailcode)
Set up cap_dac_read_search or cap_dac_override to use the Ruby executable:
Using CAP_DAC_READ_SEARCH
Using CAP_DAC_OVERRIDE
Example setting up capability for rbenv-ed Ruby
Actual Example for Linux capability handling in in_tail
When adding cap_dac_override (partial privileges for rw file) and cap_dac_read_search (partial privileges for read only), Fluentd/td-agent can handle to read 640 permission files such as /var/log/syslog:
This file cannot be read by ordinary users:
Attach dac_read_search for using Ruby executable binary:
And prepare the following configuration:
Make and change ownership directory:
Then, run as an ordinary user with cap_dac_read_search capability attached Ruby:
Fluentd, which is running by a non-root user, does not complain with Permission denied. Users can retrieve root files' contents on a non-root process, yay!
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Capability handling on docker container
If you would like to collect logs from a file as a non-root user, you can use CAP_DAC_READ_SEARCH Linux capabilities. However, CAP_DAC_READ_SEARCH now cannot be used on docker container by default.
When using CAP_DAC_READ_SEARCH in a Docker container, you need to add the --cap-add DAC_READ_SEARCH option to the docker run command. Or, if you are using docker compose, you need to add cap_add to the service definition.
Please refer to the Docker documentation for more information:
Last updated
Was this helpful?