Forum OpenACS Q&A: 5.0: Installation: missing clue (running on port 80)

It seems much more difficult to run aolserver 4 on port 80 than aolserver 3 was. I could not find out how. Using e.g. /usr/local/aolserver/bin/nsd -t /var/lib/aolserver/service0/etc/config.tcl -u service0 -g web does not work. [15/Feb/2004:07:40:52][26632.16384][-main-] Error: nssock: failed to listen on 217.120.32.121:80: Permission denied

It says here: https://openacs.org/doc/openacs-5-0-0/maintenance-web.html#install-openacs-keepalive

"Running AOLserver on Port 80
If you want your webserver to be http://yourserver.com, it must run on port 80, the default HTTP port. You set this in the config.tcl file. You will need to start the service as root. If you follow the instructions above for automating startup, this will be taken care of, but if you ever start the server from the command line, be sure to su - first.

Port 80 is a privileged port. Only certain users can claim it. When you start nsd as root, it obtains the port, and then changes to run as whatever user you specify in the server configuration file. This ensures a high level of security, as the server, once started, is not running as root. This mean that if someone was able to exploit your web server to execute a command on your server, they would not be able to gain root access."

I have been looking for an answer for more than an hour. It must be there somewhere.

Hans,

see the AOLserver documentation. Or the AOLserver usage information:

Usage: /usr/local/aolserver/bin/nsd [-h|V] [-i|f] [-u <user>] [-g <group>] [-r <path>] [-b <address:port>|-B <file>] [-s <server>] \
-t <file>

  -h  help (this message)
  -V  version and release information
  -i  inittab mode
  -f  foreground mode
  -d  debugger-friendly mode (ignore SIGINT)
  -u  run as <user>
  -g  run as <group>
  -r  chroot to <path>
  -b  bind <address:port>
  -B  bind address:port list from <file>
  -s  use server named <server> in config file
  -t  read config from <file> (REQUIRED)

You need to provide -b <address:port>. Or if you are planning on using both HTTP and HTTPS -B <file> where <file> contains:

<address:http_port>
<address:https_port>

/Bart

Collapse
Posted by Vinod Kurup on
AOLserver 4 requires privileged ports to be prebound on the command line. So, try:
# /usr/local/aolserver/bin/nsd -t /var/lib/aolserver/service0/etc/config.tcl -u service0 -g web -b 217.120.32.121:80
The AOLserver documentation hasn't been updated with this new info (AFAIK), but the OpenACS docs have.
Collapse
Posted by Hans Gaasenbeek on
This -b argument was in /var/lib/aolserver/service0/etc/daemontools/run but I did not remove the commented line above it. This caused it not to take the argument. Now it does.

But... there is a different problem now. When registering, users get a notification email stating they have registered in www.mysite.com:8000 instead of www.mysite.com. It did run on port 8000 for a short time, but I changed it. In config.tcl I have port 80 defined. I cannot find - within ACS - where to change this. Any help appreciated!

Collapse
Posted by Tilmann Singer on
It's  a parameter of acs-kernel: SystemURL.
Thanks. I have been able to change it.

But now: when using svc -u /service/service0 the site comes up, but when it restarts (e.g. after installing software) nsd is running, but not listening. Error:

[15/Feb/2004:20:43:58][22135.16384][-main-] Error: nssock: failed to listen on 212.120.32.124:80: permission denied

(I changed the IP address in this example).

I don't understand why it cannot listen. I have this problem when using svc as root or as a normal user. Maybe it is not possible to use daemontools with aolserver on port 80??? Why is it not in the docs? It is a nightmare. I suppose in the end most sites will use port 80, so this is not very strange? I think I should use sudo.

It cannot be solved by adding "sudo" after "exec" in the "run" script (/var/lib/aolserver/service0/daemontools/run. I am really at a loss. Maybe I should configure /etc/sudoers or something like it? I do not understand why it is not in the docs. Maybe it should be added. Even daemontools cannot start aolserver (4) on a priviliged port, so it should execute the startup command sudo'd root.
Collapse
8: nasty little fix (response to 1)
Posted by Hans Gaasenbeek on
Had to put this in /etc/sudoers:

localhost:~# more /etc/sudoers
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
service0 ALL= NOPASSWD: ALL

Probably, there is a better way, e.g. only allowing certain commands, but I am not sure how to do it. I have not the time to read endless manuals before I can start aolserver automagically...

Collapse
9: Re: nasty little fix (response to 8)
Posted by Bart Teeuwisse on
Hans,

It is very well possible to run AOLserver with daemontools on port 80. I do it all the time. Probably a configuration issue on your end.

/Bart

Collapse
10: Re: nasty little fix (response to 9)
Posted by Joel Aufrecht on
https://openacs.org/doc/openacs-5-0-0/openacs.html

"If you want to use port 80, there are complications. First, AOLserver must be root to use system ports such as 80, but refuses to run as root for security reasons. Thus you must start as root and specify a non-root user ID and Group ID which AOLserver will switch to after claiming the port. To do so, find the UID and GID of the service0 user via grep service0  /etc/passwd and then put those numbers into the command line via -u 501 -g 502. Second, if you are root then killall will affect all OpenACS services on the machine, so if there's more than one you'll have to do ps -auxw | grep nsd and selectively kill by job number."

Collapse
11: Re: nasty little fix (response to 10)
Posted by Guan Yang on
pgrep -fl and pkill -fl are your friends.
i've done this sudo trick on debian testing (aka sarge) and i can start it from the command line without a problem, but when i install a package and go to the page http://service0/acs-admin/server-restart i get this at start up:

[15/Feb/2004:20:48:10][6358.16384][-main-] Notice: nsmain: AOLserver/4.0 running
[15/Feb/2004:20:48:10][6358.16384][-main-] Notice: nsmain: security info: uid=1002, euid=1002, gid=103, egid=103
[15/Feb/2004:20:48:10][6358.32771][-sched-] Notice: sched: starting
[15/Feb/2004:20:48:10][6358.16384][-main-] Error: nssock: failed to listen on 67.119.161.85:80: Permission denied
[15/Feb/2004:20:48:10][6358.131081][-driver-] Notice: starting
[15/Feb/2004:20:48:10][6358.131081][-driver-] Notice: driver: accepting connections

why would a restart from the web server side give this error but running the run command as the service0 user work? Also i can do a killall nsd and daemontools starts it up just fine. Anybody have any ideas how to solve this?
Collapse
Posted by Vinod Kurup on
Hi Matthew,

There was a shutdown problem in AOLserver 4 that has only been recently fixed. Prior to the fix, it would take a kill -9 (or perhaps 2 kill's) to shutdown the AOLserver, thus causing the inability to bind to your desired port on restart. If you're not running AOLserver 4.01 or higher, then I'd try that.

Vinod, that didn't work. as i said it works fine from the command prompt. i had previously followed the openacs instructions and after your recommendation i downloaded the 4.0.1 and "upgraded" to it. the same problem persists. Is there any more info i should provide in order to get to the bottom of this?

i've fixed the problem on my system, and even made it unnecessary for me to sudo in the /var/lib/aolserver/service0/etc/daemontools/run command - which should be good for security. All i need to do is add sleep before the process (which seems to give nsd enough time to fully shut itself down before daemontools restarts it). So now my run file looks like this:

#!/bin/sh

sleep 1
exec /usr/local/aolserver/bin/nsd-postgres -it /var/lib/aolserver/service0/etc/config.tcl -u service0 -g group0 -b 192.168.0.XXX:80
This thread gave me the final pieces of the "ports below 1024 on Aolserver 4" and nsopenssl puzzle.

In case its helpful for some-one else, here are the pieces:

  1. The daemontools "run" or the command line nsd -t list must include either a
    • -b {Ipaddress:port} or a
    • -B {filename}.

    If you modify the run file, all comments between the config.tcl and the -b have to be removed, or it will not load. [thanks Hans]
    The -B is used if you have multiple {Ipaddress:port} pairs. If you want to use http and https, you need to include each as an {Ipaddress:port} pair. [thanks Bart]
  2. For an ssl connection, Aolserver 4 must be used with Scottg's latest nsopenssl (I'm using version 3beta12). This requires a "with threads" version of OpenSSL, see details at scottg.net, or in the nsopenssl README.
  3. For a single ip address, the following contribution will implement it. [thanks Matthew G]
#---------------------------------------------------------------------
#
# OpenSSL, nsopenssl and aolserver 4
#
#---------------------------------------------------------------------
#
# SSL contexts. Define the ssl contexts for this server.

ns_section "ns/server/${server}/module/nsopenssl/sslcontexts"
ns_param ssl_incoming_requests_context   "SSL context used for regular user access to the website"
ns_param ssl_outgoing_context            "SSL context used for outgoing script socket connections"

ns_section "ns/server/${server}/module/nsopenssl/defaults"
ns_param server               ssl_incoming_requests_context
ns_param client               ssl_outgoing_context

ns_section "ns/server/${server}/module/nsopenssl/sslcontext/ssl_incoming_requests_context"
ns_param Role                  server
ns_param ModuleDir             ${serverroot}/etc/certs
ns_param CertFile              certfile.pem
ns_param KeyFile               keyfile.pem
#ns_param CADir                 ca-client/dir
#ns_param CAFile                ca-client/ca-client.crt
ns_param Protocols             "SSLv3, TLSv1"
ns_param CipherSuite           "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP"
ns_param PeerVerify            false
ns_param PeerVerifyDepth       3
ns_param Trace                 true

# SSL drivers. Each driver defines a port and a named SSL context to associate with it.

ns_section "ns/server/${server}/module/nsopenssl/ssldrivers"
ns_param ssl_incoming_requests_driver "Driver for regular user access to the website"

ns_section "ns/server/${server}/module/nsopenssl/ssldriver/ssl_incoming_requests_driver"
ns_param sslcontext            ssl_incoming_requests_context
ns_param port                  $httpsport
ns_param hostname              $hostname
ns_param address               $address
Collapse
Posted by Vinod Kurup on
You can also include more than 1 bind parameter by using commas to separate the addresses.
nsd -t config.tcl -b 0.0.0.0:80,0.0.0.0:443
Collapse
18: Re: nasty little fix (response to 10)
Posted by Hans Gaasenbeek on
Yes, I read that, and, yes, I tried it but, no, that does not do the trick.