Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Don't call chown() unless necessary. - #621

Merged
jeffkaufman merged 1 commit into
apache:masterfrom
jart:dont-chown
Feb 18, 2014
Merged

jeffkaufman merged 1 commit into
apache:masterfrom
jart:dont-chown

Conversation

@jart

@jart jart commented Feb 16, 2014

Copy link
Copy Markdown
Contributor

Right now it's impossible to AppArmor NGINX when this module is enabled because you've got a mandatory chown() call. Worse yet, the nginx process exits if the chown() call fails. This means that you have to add capability chown to your NGINX AppArmor config. But granting chown to the application would undermine the security of the AppArmor sandbox. Hence this patch.

Here's a screenshot of NGINX not starting due to this bug:

screen shot 2014-02-15 at 9 39 20 pm

If you're not familiar with AppArmor, this config file /etc/apparmor.d/usr.local.nginx.sbin.nginx should hopefully help you understand it better.

#include <tunables/global>

/usr/local/nginx/sbin/nginx {
  #include <abstractions/base>
  #include <abstractions/nameservice>
  #include <abstractions/openssl>
  #include <abstractions/user-tmp>

  capability dac_override,
  capability setgid,
  capability setuid,
  capability mknod,

  /etc/nginx/** r,
  owner /etc/ssl/** r,
  /home/nginx/** r,
  /home/ows/ows/occupywallst/occupywallst/media/** r,
  /home/recordings/** r,
  /home/soundboards/**.mp3 r,
  /home/soundboards/**.ogg r,
  /opt/celebcall/static/** r,
  /run/nginx.pid rw,
  /usr/local/nginx/conf/** r,
  /usr/local/nginx/html/** r,
  /usr/local/nginx/logs/** rw,
  owner /usr/local/nginx/proxy_temp/** rw,
  /usr/local/nginx/sbin/nginx mr,
  /var/cache/nginx/** rw,
  /var/cache/pagespeed/** rwlk,
  /var/log/pagespeed/** rw,
  /var/log/nginx/* w,
  /var/run/nginx.pid rw,
}

@jeffkaufman

Copy link
Copy Markdown
Contributor

Makes sense: don't call chown if we already own it.

LGTM.

Could you sign our CLA? https://developers.google.com/open-source/cla/individual

@jart

jart commented Feb 18, 2014

Copy link
Copy Markdown
Contributor Author

I'm a Googler. Is it necessary?

@jeffkaufman

Copy link
Copy Markdown
Contributor

Verified that jart works for Google; merging.

jeffkaufman added a commit that referenced this pull request Feb 18, 2014
Security Fix: Don't call chown() unless necessary.
@jeffkaufman
jeffkaufman merged commit bf6c6c0 into apache:master Feb 18, 2014
@jart
jart deleted the dont-chown branch February 19, 2014 02:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants