logstash-plugins / logstash-output-file

Apache License 2.0
23 stars 53 forks source link

dir_mode and file_mode are interpreted as decimal instead of octal numbers #78

Closed micoq closed 5 years ago

micoq commented 5 years ago

The values of dir_mode or the file_mode are always interpreted as decimal number regardless of the leading zero in the configuration.

For, example, with this configuration:

file {
  path => "/tmp/test/test.log"
  file_mode => 0640
  dir_mode => 0750
}

Logstash will create directories with permissions set to chmod 1356 and files with permissions set to chmod 1200

01200 == 640
01356 == 750

Logstash version: 6.4.2 OS: RHEL7

ThorbenJ commented 5 years ago

This issue still exists in LS 7.0.1 (on Debian 9)

In the logs you will see many: org.jruby.exceptions.SystemCallError: (EACCES) Permission denied

Once saw how messed up the file/dir permissions were, I guessed that octal was not being processed properly and manually made the conversion to decimal:

    file {
        path => "..../file.log.gz"
        dir_mode => 488
        file_mode => 424
        gzip => true
        codec => json_lines { }
    }

The bug is more egregious due to the documentation using octal values in the given examples and there being no explicit mention of decimal or octal: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-file.html

It is far more usual/common to give unix permission in octal rather than decimal.

At the very minimum the documentation needs correcting, if not the plugin/config parser.

-T

guyboertje commented 5 years ago

I wonder if this occurred when we switched to using the Java config parsing from the Ruby based parsing?

guyboertje commented 5 years ago

I looked into this.

I tested LS 5.6.10 and 7.0.0, it seems as if the Java execution when parsing the config fails to take the leading 0 into account.

In 5.6.10, 0640 is parsed as as the decimal number 416 but in 7.0.0 it is parsed as 640 in decimal - clearly wrong.

I will create a bug report on the main Logstash repo as this is not related to the file output plugin and the bug report was missed by the LS core folks.

guyboertje commented 5 years ago

Closing. LS bug report created. https://github.com/elastic/logstash/issues/10826