Skip to content

Logging login attempts #2020

Open

Description

@killua-eu

I wanted to write a fail2ban rule for node-red. After defining some users in adminAuth in reference to #539 I expected to see errors on failed login attempts in the syslog (and successful logins too). I configured

    logging: {
        console: {
            level: "debug",
            metrics: false,
            audit: true
        }
    },

Has failed login attempt logging been merged in the end? #539 has been closed, but there's no PR. Thanks lots...

Please tell us about your environment:

  • Node-RED version: 0.19.5
  • node.js version: v10.15.0
  • npm version: 6.4.1
  • Platform/OS: Ubuntu 18.04
  • Browser: n/a

Activity

  1. knolleary commented on Jan 2, 2019

    @knolleary
    Member

    Hi,

    I've just checked 0.19.5, with audit: true set as you have it, I get the following type of event in the Node-RED log when I enter an incorrect password:

    2 Jan 22:53:21 - [audit] {"event":"auth.login.fail.credentials","username":"admin","client":"node-red-editor","scope":"","level":98,"timestamp":1546469601808}
    
  2. 917huB commented on May 4, 2019

    @917huB

    I see successful access log with IP address, i.e
    May 04 11:01:15 homeassistant Node-RED[1518]: 4 May 11:01:15 - [audit] {"event":"library.get.all","type":"flow","level":98,"user":{"username":"admin","permissions":"*"},"path":"/library/flows","ip":"192.168.20.181, 192.168.20.181","timestamp":1556992875846}

    but failed access attempts don't log the originating IP address so I cant block the offender with fail2ban, is this string configurable or can we request to add IP address?

    May 04 11:01:17 homeassistant Node-RED[1518]: 4 May 11:01:17 - [audit] {"event":"comms.auth","user":{"username":"admin","permissions":"*"},"level":98,"timestamp":1556992877375}

  3. georg90 commented on Jun 8, 2019

    @georg90

    I have the same issue with version v0.20.5 running in docker.

    The failed login gets logged, but without IP address

    8 Jun 16:14:08 - [audit] {"event":"auth.login.fail.credentials","username":"georg80","client":"node-red-editor","scope":"","level":98,"timestamp":1560010448291}
    

    success looks like this

    8 Jun 18:42:04 - [audit] {"event":"auth.login","username":"georg90","client":"node-red-editor","scope":" *","level":98,"timestamp":1560019324406}
    

    The IP is missing in both..

    my logging settings

        logging: {
            // Only console logging is currently supported
            console: {
                // Level of logging to be recorded. Options are:
                // fatal - only those errors which make the application unusable should be recorded
                // error - record errors which are deemed fatal for a particular request + fatal errors
                // warn - record problems which are non fatal + errors + fatal errors
                // info - record information about the general running of the application + warn + error + fatal errors
                // debug - record information which is more verbose than info + info + warn + error + fatal errors
                // trace - record very detailed logging + debug + info + warn + error + fatal errors
                // off - turn off all logging (doesn't affect metrics or audit)
                level: "trace",
                // Whether or not to include metric events in the log output
                metrics: false,
                // Whether or not to include audit events in the log output
                audit: true
            }
        },
    

    @917huB The log with IP is from the frontend or API?

  4. RNCTX commented on Apr 8, 2020

    @RNCTX

    If anyone stumbled on this from google like I did, it's not as badly wide-open as we were assuming. I dug into the code looking to patch the logging function to add IP addresses to the scope, but there is a flood control hard-coded at the user level in the application already.

    clientPasswordStrategy.ClientPasswordStrategy = new ClientPasswordStrategy(clientPasswordStrategy);

    I can verify that the above works after looking at my logs from starting the server via systemd...

    Apr 08 11:55:16 NAS Node-RED-Server[24289]: 8 Apr 11:55:16 - [audit] {"event":"auth.login.fail.credentials","username":"nodereduser","client":"node-red-editor","scope":"","level":98,"timestamp":
    Apr 08 11:55:17 NAS Node-RED-Server[24289]: 8 Apr 11:55:17 - [audit] {"event":"auth.login.fail.credentials","username":"nodereduser","client":"node-red-editor","scope":"","level":98,"timestamp":
    Apr 08 11:55:18 NAS Node-RED-Server[24289]: 8 Apr 11:55:18 - [audit] {"event":"auth.login.fail.credentials","username":"nodereduser","client":"node-red-editor","scope":"","level":98,"timestamp":
    Apr 08 11:55:19 NAS Node-RED-Server[24289]: 8 Apr 11:55:19 - [audit] {"event":"auth.login.fail.credentials","username":"nodereduser","client":"node-red-editor","scope":"","level":98,"timestamp":
    Apr 08 11:55:20 NAS Node-RED-Server[24289]: 8 Apr 11:55:20 - [audit] {"event":"auth.login.fail.credentials","username":"nodereduser","client":"node-red-editor","scope":"","level":98,"timestamp":
    Apr 08 11:55:21 NAS Node-RED-Server[24289]: 8 Apr 11:55:21 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:24 NAS Node-RED-Server[24289]: 8 Apr 11:55:24 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:25 NAS Node-RED-Server[24289]: 8 Apr 11:55:25 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:26 NAS Node-RED-Server[24289]: 8 Apr 11:55:26 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 11:55:26 NAS Node-RED-Server[24289]: 8 Apr 11:55:26 - [audit] {"event":"auth.login.fail.too-many-attempts","username":"nodereduser","client":"node-red-editor","level":98,"timestamp":15863
    Apr 08 12:06:30 NAS Node-RED-Server[24289]: 8 Apr 12:06:30 - [audit] {"event":"auth.login","username":"nodereduser","client":"node-red-editor","scope":"*","level":98,"timestamp":1586365590046}
    Apr 08 12:06:30 NAS Node-RED-Server[24289]: 8 Apr 12:06:30 - [audit] {"event":"comms.open","level":98,"timestamp":1586365590322}
    Apr 08 12:06:30 NAS Node-RED-Server[24289]: 8 Apr 12:06:30 - [audit] {"event":"nodes.list.get","level":98,"user":{"username":"nodereduser","permissions":"*"},"path":"/nodes","ip":"192.168.1.77",
    Apr 08 12:06:30 NAS Node-RED-Server[24289]: 8 Apr 12:06:30 - [audit] {"event":"comms.auth","user":{"username":"nodereduser","permissions":"*"},"level":98,"timestamp":1586365590393}
    Apr 08 12:06:30 NAS Node-RED-Server[24289]: 8 Apr 12:06:30 - [audit] {"event":"nodes.icons.get","level":98,"user":{"username":"nodereduser","permissions":"*"},"path":"/icons","ip":"192.168.1.77"
    Apr 08 12:06:30 NAS Node-RED-Server[24289]: 8 Apr 12:06:30 - [audit] {"event":"nodes.configs.get","level":98,"user":{"username":"nodereduser","permissions":"*"},"path":"/nodes","ip":"192.168.1.7
    Apr 08 12:06:31 NAS Node-RED-Server[24289]: 8 Apr 12:06:31 - [audit] {"event":"flows.get","level":98,"user":{"username":"nodereduser","permissions":"*"},"path":"/flows","ip":"192.168.1.77","time
    lines 462-500/500 (END)
    
    
  5. 917huB commented on Apr 8, 2020

    @917huB

    I dont see an IP address included to the fail messaging that fail2ban can use to block the source address.

  6. RNCTX commented on Apr 8, 2020

    @RNCTX

    Correct, there is not one, but there is a flood control function built into the application's login flow, see the linked function.

  7. knolleary commented on Apr 8, 2020

    @knolleary
    Member

    @RNCTX's comment has prompted me to go look at the code over the last 10 minutes. I can see why the IP address isn't included, but I can also see getting it included will require some careful reworking of the error handling.

    The audit message is currently being logged at the point we identify the password is incorrect. But at that point of the code we have no reference to the http request itself, only the credential data being provided. The audit message is logged and then a generic rejection error is passed back up the stack so the request can be refused.

    We will need to change it around so the error contains more details on the failure type, so the event can be logged at a point where we know the IP address. But we need to be very careful to ensure that change in error message doesn't change any other behaviours looked for the existing error.

  8. 917huB commented on Apr 8, 2020

    @917huB

    Thank you for taking a look. If you do take a look at adding the originating IP address to the logging, can I also ask you consider those folks may be running node-red behind a nginx or similar proxy and to consider the implications of $proxy_add_x_forwarded_for headers etc.

  9. RNCTX commented on Apr 8, 2020

    @RNCTX

    X-Forwarded-For is recorded properly in the functions where IPs are recorded, I verified that when testing the above as well.

    I'm running inside-out to a fully qualified subdomain. My internal IP is 192.168.1.77, and the reverse proxy is my router at 192.168.1.1.

    Working nginx reverse proxy config:

    server {
        listen 443;
        server_name nodered.mydomain.net;
        include /opt/etc/nginx/ssl.conf;
        error_log syslog:server=192.168.1.80,tag=nginx_home;
        access_log syslog:server=192.168.1.80,tag=nginx_home,severity=notice combined;
        proxy_buffering off;
    
        location / {
          proxy_pass http://192.168.1.80:1880;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header X-Forwarded-For $remote_addr;
        }
      }
    }
    

    With x-forwarded-for set to $remote_addr:

    8 Apr 12:06:30 - [audit] {"event":"nodes.list.get","level":98,"user":{"username":"nodereduser","permissions":"*"},"path":"/nodes","ip":"192.168.1.77","timestamp":1586365590354}
    

    Without x-forwarded-for set:

    8 Apr 11:55:11 - [audit] {"event":"auth.login.revoke","level":98,"user":{"username":"nodereduser","permissions":"*"},"path":"/auth/revoke","ip":"192.168.1.1","timestamp":1586364911563}
    
  10. added this to the 1.2 milestone on Jun 29, 2020
  11. ClementToche commented on Jul 2, 2022

    @ClementToche

    I'm running NodeRed 2.2.2 and I'm having the same missing feature.
    I would like to secure my server with fail2ban but the log still not show any IP address :
    2 Jul 15:42:41 - [audit] {"event":"auth.login.fail.credentials","username":"[email protected]","client":"node-red-editor","scope":"","level":98,"timestamp":1656769361308}

    Does someone has a patch for this ? is this scheduled to be put into version 3 of NodeRed ?

  12. hardillb commented on Jul 2, 2022

    @hardillb
    Member

    @ClementToche The problem is that at the point we know the wrong password has been provided we are deep in a PassportJS callback stack and don't have access to the requesting IP address.

    log.audit({event: "auth.login.fail.credentials",username:username,client:client.id,scope:scope});

  13. ClementToche commented on Jul 3, 2022

    @ClementToche

    @hardillb, Thanks for answering and I see the problem.
    Another solution would be to print 2 traces, 1 when a client connect to the server web front-end and 1 when credentials fails.
    Fail2Ban is able to parse 2 lines and I can easily make a regex in this way.

    To give an example, mosquitto (MQTT open source server) print those 2 lines :
    New connection from 192.168.1.10:6565 on port 8883
    Client <unknown> disconnected, not authorised.

    First line would be printed by the web server front-end when new client connects.
    And second line would be printed as already developed in NodeRed code.

    Of course, this is not a perfect solution for big server that could have 2 user connection at the very same time but this is for sure enough for personal server at home for which a little bit of security can be added.

    Do you think it is something feasible ?

  14. ClementToche commented on Jun 8, 2024

    @ClementToche

    Hello Node-RED team.
    I would like to raise that up on top of the list since it's a very old request.
    Node-RED is a very good tool that can be used for many stuff in a professional grade way but it really need the same level of quality for security requirement and this is really needed to make DDoS attack protection in place for this tool.
    Is there is any chance it can come on top of the new major 3.X version ?
    Thanks.

  15. knolleary commented on Jun 11, 2024

    @knolleary
    Member

    @ClementToche I will take another look to see how we can get the required information surfaced. As was said in previous comments, there are some architectural difficulties in getting the information in the right place so it can be logged at the right time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions