这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugins/nginx-vhosts/commands
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,30 @@ EOF
dokku nginx:build-config $APP
;;

nginx:access-logs|nginx:error-logs)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"

NGINX_LOGS_TYPE=${1#nginx:}
NGINX_LOGS_TYPE=${NGINX_LOGS_TYPE%-logs}
NGINX_LOGS_PATH="/var/log/nginx/$APP-$NGINX_LOGS_TYPE.log"

if [[ $3 == "-t" ]]; then
NGINX_LOGS_ARGS="-F"
else
NGINX_LOGS_ARGS="-n 20"
fi

sudo tail "$NGINX_LOGS_ARGS" "$NGINX_LOGS_PATH"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to line this call up with what's in the sudoers file?

;;

help | nginx:help)
cat && cat<<EOF
nginx:import-ssl <app>, Imports a tarball from stdin; should contain server.crt and server.key
nginx:build-config <app>, (Re)builds nginx config for given app
nginx:access-logs <app> [-t], Show the nginx access logs for an application (-t follows)
nginx:error-logs <app> [-t], Show the nginx error logs for an application (-t follows)
EOF
;;

Expand Down
2 changes: 2 additions & 0 deletions plugins/nginx-vhosts/install
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
case "$DOKKU_DISTRO" in
ubuntu)
echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/tail" >> /etc/sudoers.d/dokku-nginx
;;

opensuse)
echo "%dokku ALL=(ALL) NOPASSWD:/sbin/service nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/tail" >> /etc/sudoers.d/dokku-nginx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be pared down to /usr/bin/tail /var/log/nginx/* and /usr/bin/tail -f /var/log/nginx/*. Test this of course. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I think about it, allowing any user with access to the dokku account to tail any file, is a security risk I don't think is worth introducing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After doing the plugin plugin, I remembered that we assume dokku will be run by root and thus we sudo su - dokku here: https://github.com/progrium/dokku/blob/63d89942438e2806c5322c2ecddbe2d008e03f42/dokku#L44-L47

Therefore I think we can just filter these commands as well to make them not sudo. I'll create a new PR based on this work.

;;
esac

Expand Down