การกำหนดค่าระบบ

This document describes basic steps to set up NightPOS in production or on an internet-facing server. It follows installation, and is not generally necessary for a development systems that is not exposed on the internet.

Warning

หากคุณกำลังตั้งค่าเซิร์ฟเวอร์สาธารณะ โปรดตรวจสอบคำแนะนำ ความปลอดภัย ของเรา!

dbfilter

NightPOS is a multi-tenant system: a single NightPOS system may run and serve a number of database instances. It is also highly customizable, with customizations (starting from the modules being loaded) depending on the "current database".

นี่ไม่ใช่ปัญหาเมื่อทำงานกับแบ็กเอนด์ (เว็บลูกค้า) ในฐานะผู้ใช้บริษัทที่เข้าสู่ระบบ: สามารถเลือกฐานข้อมูลได้เมื่อเข้าสู่ระบบ และโหลดการปรับแต่งในภายหลัง

However it is an issue for non-logged users (portal, website) which aren't bound to a database: NightPOS needs to know which database should be used to load the website page or perform the operation. If multi-tenancy is not used that is not an issue, there's only one database to use, but if there are multiple databases accessible NightPOS needs a rule to know which one it should use.

นั่นคือหนึ่งในวัตถุประสงค์ของ --db-filter: ระบุว่าควรเลือกฐานข้อมูลตามชื่อโฮสต์ (โดเมน) ที่ถูกร้องขออย่างไร ค่านี้คือ นิพจน์ทั่วไป ซึ่งอาจรวมถึงชื่อโฮสต์ที่แทรกแบบไดนามิก (`` %h``) หรือโดเมนย่อยแรก (%d) ที่ใช้เข้าถึงระบบ

สำหรับเซิร์ฟเวอร์ที่โฮสต์ฐานข้อมูลหลายฐานข้อมูลในการใช้งานจริง โดยเฉพาะอย่างยิ่งหากใช้ เว็บไซต์ จะต้องตั้งค่า dbfilter จำเป็น ไม่เช่นนั้นฟีเจอร์บางอย่างจะทำงานไม่ถูกต้อง

ตัวอย่างการกำหนดค่า

  • แสดงเฉพาะฐานข้อมูลที่มีชื่อขึ้นต้นด้วย 'mycompany'

ในเซ็ท ไฟล์การกำหนดค่า:

[options]
dbfilter = ^mycompany.*$
  • แสดงเฉพาะฐานข้อมูลที่ตรงกับโดเมนย่อยแรกที่อยู่หลัง www: ตัวอย่างเช่น ฐานข้อมูล "mycompany" จะแสดงขึ้นหากคำขอขาเข้าถูกส่งไปยัง www.mycompany.com หรือ mycompany.co.uk แต่ไม่ใช่สำหรับ www2.mycompany.com หรือ helpdesk.mycompany.com

ในเซ็ท ไฟล์การกำหนดค่า:

[options]
dbfilter = ^%d$

Note

การตั้งค่า --db-filter ที่เหมาะสมเป็นส่วนสำคัญในการรักษาความปลอดภัยการปรับใช้ของคุณ เมื่อทำงานอย่างถูกต้องและจับคู่ฐานข้อมูลเดียวต่อชื่อโฮสต์ ขอแนะนำอย่างยิ่งให้บล็อกการเข้าถึงหน้าจอตัวจัดการฐานข้อมูล และใช้พารามิเตอร์เริ่มต้น --no-database-list เพื่อป้องกันการแสดงรายการฐานข้อมูลของคุณ และบล็อกการเข้าถึงหน้าจอการจัดการฐานข้อมูล ดูเพิ่มเติมเกี่ยวกับความปลอดภัย_

PostgreSQL

ตามค่าเริ่มต้น PostgreSQL อนุญาตการเชื่อมต่อผ่านซ็อกเก็ต UNIX และการเชื่อมต่อแบบย้อนกลับเท่านั้น (จาก "localhost" ซึ่งเป็นเครื่องเดียวกับที่ติดตั้งเซิร์ฟเวอร์ PostgreSQL)

UNIX socket is fine if you want NightPOS and PostgreSQL to execute on the same machine, and is the default when no host is provided, but if you want NightPOS and PostgreSQL to execute on different machines 1 it will need to listen to network interfaces 2, either:

  • Only accept loopback connections and use an SSH tunnel between the machine on which NightPOS runs and the one on which PostgreSQL runs, then configure NightPOS to connect to its end of the tunnel

  • Accept connections to the machine on which NightPOS is installed, possibly over ssl (see PostgreSQL connection settings for details), then configure NightPOS to connect over the network

ตัวอย่างการกำหนดค่า

  • อนุญาตการเชื่อมต่อ TCP บน localhost

  • อนุญาตการเชื่อมต่อ TCP จากเครือข่าย 192.168.1.x

ในเซ็ท /etc/postgresql/<YOUR POSTGRESQL VERSION>/main/pg_hba.conf:

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.1.0/24          md5

ในเซ็ท /etc/postgresql/<YOUR POSTGRESQL VERSION>/main/postgresql.conf:

listen_addresses = 'localhost,192.168.1.2'
port = 5432
max_connections = 80

Configuring NightPOS

Out of the box, NightPOS connects to a local postgres over UNIX socket via port 5432. This can be overridden using the database options when your Postgres deployment is not local and/or does not use the installation defaults.

The packaged installers will automatically create a new user (nightpos) and set it as the database user.

  • หน้าจอการจัดการฐานข้อมูลได้รับการปกป้องโดยการตั้งค่า admin_passwd การตั้งค่านี้สามารถตั้งค่าได้โดยใช้ไฟล์การกำหนดค่าเท่านั้น และจะถูกตรวจสอบก่อนดำเนินการแก้ไขฐานข้อมูล ควรตั้งค่าเป็นค่าที่สร้างขึ้นแบบสุ่มเพื่อให้แน่ใจว่าบุคคลที่สามไม่สามารถใช้อินเทอร์เฟซนี้ได้

  • การดำเนินการฐานข้อมูลทั้งหมดใช้ ตัวเลือกฐานข้อมูล รวมถึงหน้าจอการจัดการฐานข้อมูล เพื่อให้หน้าจอการจัดการฐานข้อมูลทำงานได้ ผู้ใช้ PostgreSQL จะต้องมีสิทธิ์ createdb

  • ผู้ใช้สามารถทิ้งฐานข้อมูลของตนเองได้ตลอดเวลา เพื่อให้หน้าจอการจัดการฐานข้อมูลไม่ทำงานโดยสมบูรณ์ ผู้ใช้ PostgreSQL จะต้องถูกสร้างขึ้นด้วย no-createdb และฐานข้อมูลจะต้องเป็นของผู้ใช้ PostgreSQL อื่น

    Warning

    ผู้ใช้ PostgreSQL ต้องไม่ เป็นผู้ใช้ระดับสูง

ตัวอย่างการกำหนดค่า

  • เชื่อมต่อกับเซิร์ฟเวอร์ PostgreSQL บน 192.168.1.2

  • พอร์ต 5432

  • using an 'nightpos' user account,

  • โดยมี 'pwd' เป็นรหัสผ่าน

  • กรองเฉพาะ db ที่มีชื่อขึ้นต้นด้วย 'mycompany'

ในเซ็ท ไฟล์การกำหนดค่า:

[options]
admin_passwd = mysupersecretpassword
db_host = 192.168.1.2
db_port = 5432
db_user = nightpos
db_password = pwd
dbfilter = ^mycompany.*$

SSL Between NightPOS and PostgreSQL

Since NightPOS 11.0, you can enforce ssl connection between NightPOS and PostgreSQL. in NightPOS the db_sslmode control the ssl security of the connection with value chosen out of 'disable', 'allow', 'prefer', 'require', 'verify-ca' or 'verify-full'

PostgreSQL Doc

เซิร์ฟเวอร์ในตัว

NightPOS includes built-in HTTP, cron, and live-chat servers, using either multi-threading or multi-processing.

เซิร์ฟเวอร์ แบบมัลติเธรด เป็นเซิร์ฟเวอร์ที่เรียบง่ายกว่าซึ่งส่วนใหญ่ใช้สำหรับการพัฒนา การสาธิต และความเข้ากันได้กับระบบปฏิบัติการต่างๆ (รวมถึง Windows) เธรดใหม่จะถูกสร้างขึ้นสำหรับทุกคำขอ HTTP ใหม่ แม้แต่สำหรับการเชื่อมต่อที่มีอายุการใช้งานยาวนาน เช่น websocket เธรด cron daemonic พิเศษก็ถูกสร้างขึ้นเช่นกัน เนื่องจากข้อจำกัดของ Python (GIL) จึงไม่สามารถใช้ฮาร์ดแวร์ให้เกิดประโยชน์สูงสุดได้

เซิร์ฟเวอร์แบบมัลติเธรดเป็นเซิร์ฟเวอร์เริ่มต้นสำหรับคอนเทนเนอร์นักเทียบท่าด้วย มันถูกเลือกโดยปล่อยตัวเลือก --workers ออกหรือตั้งค่าเป็น 0

เซิร์ฟเวอร์ การประมวลผลหลายตัว เป็นเซิร์ฟเวอร์เต็มรูปแบบที่ใช้สำหรับการผลิตเป็นหลัก จะไม่รับผิดชอบต่อข้อจำกัด Python (GIL) เดียวกันในการใช้ทรัพยากร และด้วยเหตุนี้จึงใช้ฮาร์ดแวร์ให้เกิดประโยชน์สูงสุด กลุ่มคนทำงานถูกสร้างขึ้นเมื่อเริ่มต้นเซิร์ฟเวอร์ ระบบปฏิบัติการจะจัดคิวคำขอ HTTP ใหม่จนกว่าจะมีคนทำงานพร้อมที่จะประมวลผล ผู้ปฏิบัติงาน HTTP ที่ขับเคลื่อนด้วยเหตุการณ์พิเศษสำหรับไลฟ์แชทนั้นถูกสร้างขึ้นบนพอร์ตอื่น คนทำงาน cron พิเศษก็เกิดขึ้นเช่นกัน เก็บเกี่ยวกระบวนการที่กำหนดค่าได้จะตรวจสอบการใช้ทรัพยากรและสามารถหยุด/รีสตาร์ทผู้ปฏิบัติงานที่ไม่สำเร็จได้

เซิร์ฟเวอร์ที่มีการประมวลผลหลายตัวเลือกใช้ มันถูกเลือกโดยการตั้งค่าตัวเลือก --workers เป็นจำนวนเต็มที่ไม่ใช่ค่าว่าง

Note

เนื่องจากได้รับการปรับแต่งอย่างมากสำหรับเซิร์ฟเวอร์ Linux เซิร์ฟเวอร์ที่มีการประมวลผลหลายรายการจึงไม่พร้อมใช้งานบน Windows

การคำนวณจำนวนคนงาน

  • หลักทั่วไป : (#CPU * 2) + 1

  • คนทำงาน Cron ต้องการ CPU

  • คนงาน 1 คน ~= 6 ผู้ใช้พร้อมกัน

การคำนวณขนาดหน่วยความจำ

  • เราถือว่าคำขอ 20% เป็นคำขอจำนวนมาก ในขณะที่ 80% เป็นคำขอที่เรียบง่ายกว่า

  • ซึ่งทำงานหนัก เมื่อฟิลด์ที่คำนวณทั้งหมดได้รับการออกแบบมาอย่างดี คำขอ SQL จะได้รับการออกแบบมาอย่างดี ... คาดว่าจะใช้ RAM ประมาณ 1GB

  • ในสถานการณ์เดียวกัน ส่วนของงานที่เบากว่านั้นคาดว่าจะใช้ RAM ประมาณ 150MB

RAM ที่ต้องการ = #worker * ( (light_worker_ratio * light_worker_ram_estimation) + (heavy_worker_ratio * heavy_worker_ram_estimation) )

ไลฟ์แชท

In multi-processing, a dedicated LiveChat worker is automatically started and listens on the --gevent-port. By default, the HTTP requests will keep accessing the normal HTTP workers instead of the LiveChat one. You must deploy a proxy in front of NightPOS and redirect incoming requests whose path starts with /websocket/ to the LiveChat worker. You must also start NightPOS in --proxy-mode so it uses the real client headers (such as hostname, scheme, and IP) instead of the proxy ones.

ตัวอย่างการกำหนดค่า

  • เซิร์ฟเวอร์ที่มี 4 CPU, 8 เธรด

  • ผู้ใช้พร้อมกัน 60 คน

  • ผู้ใช้ 60 ราย / 6 = 10 <- จำนวนคนงานที่ต้องการตามทฤษฎี

  • (4 * 2) + 1 = 9 <- จำนวนคนงานสูงสุดตามทฤษฎี

  • เราจะใช้คนงาน 8 คน + 1 คนสำหรับ cron นอกจากนี้เรายังใช้ระบบตรวจสอบ เพื่อวัดโหลด cpu และตรวจสอบว่าอยู่ระหว่าง 7 ถึง 7.5 หรือไม่

  • RAM = 9 * ((0.8*150) + (0.2*1024)) ~= 3GB RAM for NightPOS

ใน the configuration file:

[options]
limit_memory_hard = 1677721600
limit_memory_soft = 629145600
limit_request = 8192
limit_time_cpu = 600
limit_time_real = 1200
max_cron_threads = 1
workers = 8

HTTPS

Whether it's accessed via website/web client or web service, NightPOS transmits authentication information in cleartext. This means a secure deployment of NightPOS must use HTTPS3. SSL termination can be implemented via just about any SSL termination proxy, but requires the following setup:

  • Enable NightPOS's proxy mode. This should only be enabled when NightPOS is behind a reverse proxy

  • ตั้งค่าพร็อกซีการยกเลิก SSL (ตัวอย่างการยกเลิก Nginx)

  • ตั้งค่าพร็อกซีเอง (ตัวอย่างพร็อกซี Nginx)

  • พร็อกซีการยกเลิก SSL ของคุณควรเปลี่ยนเส้นทางการเชื่อมต่อที่ไม่ปลอดภัยไปยังพอร์ตที่ปลอดภัยโดยอัตโนมัติ

ตัวอย่างการกำหนดค่า

  • เปลี่ยนเส้นทางคำขอ http ไปยัง https

  • Proxy requests to nightpos

ในเซ็ท ไฟล์การกำหนดค่า:

proxy_mode = True

in /etc/nginx/sites-enabled/nightpos.conf set:

#nightpos server
upstream nightpos {
  server 127.0.0.1:8069;
}
upstream nightposchat {
  server 127.0.0.1:8072;
}
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

# http -> https
server {
  listen 80;
  server_name nightpos.mycompany.com;
  rewrite ^(.*) https://$host$1 permanent;
}

server {
  listen 443 ssl;
  server_name nightpos.mycompany.com;
  proxy_read_timeout 720s;
  proxy_connect_timeout 720s;
  proxy_send_timeout 720s;

  # SSL parameters
  ssl_certificate /etc/ssl/nginx/server.crt;
  ssl_certificate_key /etc/ssl/nginx/server.key;
  ssl_session_timeout 30m;
  ssl_protocols TLSv1.2;
  ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  ssl_prefer_server_ciphers off;

  # log
  access_log /var/log/nginx/nightpos.access.log;
  error_log /var/log/nginx/nightpos.error.log;

  # Redirect websocket requests to nightpos gevent port
  location /websocket {
    proxy_pass http://nightposchat;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
    proxy_cookie_flags session_id samesite=lax secure;  # requires nginx 1.19.8
  }

  # Redirect requests to nightpos backend server
  location / {
    # Add Headers for nightpos proxy mode
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_redirect off;
    proxy_pass http://nightpos;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
    proxy_cookie_flags session_id samesite=lax secure;  # requires nginx 1.19.8
  }

  # common gzip
  gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
  gzip on;
}

การทำให้ HTTPS แข็งแกร่งขึ้น

เพิ่มส่วนหัว Strict-Transport-Security ให้กับคำขอทั้งหมด เพื่อป้องกันไม่ให้เบราว์เซอร์ส่งคำขอ HTTP ธรรมดาไปยังโดเมนนี้ คุณจะต้องรักษาบริการ HTTPS ที่ใช้งานได้โดยมีใบรับรองที่ถูกต้องบนโดเมนนี้ตลอดเวลา ไม่เช่นนั้นผู้ใช้ของคุณจะเห็นการแจ้งเตือนด้านความปลอดภัยหรือไม่สามารถเข้าถึงได้เลย

บังคับใช้การเชื่อมต่อ HTTPS ในช่วงหนึ่งปีสำหรับผู้เยี่ยมชมทุกคนใน NGINX ด้วยบรรทัด:

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

สามารถกำหนดการกำหนดค่าเพิ่มเติมสำหรับคุกกี้ session_id ได้ คุณสามารถเพิ่มแฟล็ก 'ปลอดภัย' เพื่อให้แน่ใจว่าจะไม่ส่งผ่าน HTTP และ 'SameSite=Lax' เพื่อป้องกัน CSRF ที่ได้รับการรับรองความถูกต้อง

# requires nginx 1.19.8
proxy_cookie_flags session_id samesite=lax secure;

NightPOS as a WSGI Application

It is also possible to mount NightPOS as a standard WSGI application. NightPOS provides the base for a WSGI launcher script as nightpos-wsgi.example.py. That script should be customized (possibly after copying it from the setup directory) to correctly set the configuration directly in odoo.tools.config rather than through the command-line or a configuration file.

However the WSGI server will only expose the main HTTP endpoint for the web client, website and webservice API. Because NightPOS does not control the creation of workers anymore it can not setup cron or livechat workers

คนงาน Cron

Starting one of the built-in NightPOS servers next to the WSGI server is required to process cron jobs. That server must be configured to only process crons and not HTTP requests using the --no-http cli option or the http_enable = False configuration file setting.

บนระบบที่คล้ายกับ Linux ขอแนะนำให้ใช้เซิร์ฟเวอร์ที่มีการประมวลผลหลายตัวบนเซิร์ฟเวอร์แบบมัลติเธรด เพื่อให้ได้รับประโยชน์จากการใช้ฮาร์ดแวร์ที่ดีขึ้นและความเสถียรที่เพิ่มขึ้น กล่าวคือ การใช้ --workers=-1 และ --max-cron-threads=n ตัวเลือก cli

ไลฟ์แชท

จำเป็นต้องใช้เซิร์ฟเวอร์ WSGI ที่เข้ากันได้กับ gevent เพื่อการทำงานที่ถูกต้องของฟีเจอร์ไลฟ์แชท เซิร์ฟเวอร์นั้นควรจะสามารถรองรับการเชื่อมต่อที่มีอายุการใช้งานยาวนานพร้อมกันจำนวนมากได้ แต่ไม่ต้องการพลังการประมวลผลมากนัก คำขอทั้งหมดที่เส้นทางเริ่มต้นด้วย /websocket/ ควรถูกส่งไปยังเซิร์ฟเวอร์นั้น ควรใช้เซิร์ฟเวอร์ WSGI ปกติ (ตามเธรด/ตามกระบวนการ) สำหรับคำขออื่นทั้งหมด

The NightPOS cron server can also be used to serve the live chat requests. Just drop the --no-http cli option from the cron server and make sure requests whose path starts with /websocket/ are directed to this server, either on the --http-port (multi-threading server) or on the --gevent-port (multi-processing server).

ให้บริการไฟล์ static และไฟล์แนบ

For development convenience, NightPOS directly serves all static files and attachments in its modules. This may not be ideal when it comes to performances, and static files should generally be served by a static HTTP server.

ให้บริการไฟล์ static

NightPOS static files are located in each module's static/ folder, so static files can be served by intercepting all requests to /MODULE/static/FILE, and looking up the right module (and file) in the various addons paths.

ขอแนะนำให้ตั้งค่าส่วนหัว Content-Security-Policy: default-src 'none'' บนรูปภาพทั้งหมดที่ส่งโดยเว็บเซิร์ฟเวอร์ ซึ่งไม่จำเป็นอย่างยิ่งเนื่องจากผู้ใช้ไม่สามารถแก้ไข/แทรกเนื้อหาภายในโฟลเดอร์ static/ ของโมดูล และรูปภาพที่มีอยู่ถือเป็นที่สิ้นสุด (ไม่ได้ดึงทรัพยากรใหม่ด้วยตนเอง) อย่างไรก็ตาม ถือเป็นแนวปฏิบัติที่ดี

เมื่อใช้การกำหนดค่า NGINX (https) ข้างต้น ควรเพิ่มบล็อก แผนที่ และ ตำแหน่ง ต่อไปนี้เพื่อให้บริการไฟล์คงที่ผ่าน NGINX

map $sent_http_content_type $content_type_csp {
    default "";
    ~image/ "default-src 'none'";
}

server {
    # the rest of the configuration

    location @nightpos {
        # copy-paste the content of the / location block
    }

    # Serve static files right away
    location ~ ^/[^/]+/static/.+$ {
        # root and try_files both depend on your addons paths
        root ...;
        try_files ... @nightpos;
        expires 24h;
        add_header Content-Security-Policy $content_type_csp;
    }
}

คำสั่ง root และ try_files ที่แท้จริงนั้นขึ้นอยู่กับการติดตั้งของคุณ โดยเฉพาะใน --addons-path

Example

Say NightPOS has been installed via the debian packages for Community and Enterprise, and that the --addons-path is '/usr/lib/python3/dist-packages/nightpos/addons'.

root และ try_files ควรเป็น:

root /usr/lib/python3/dist-packages/nightpos/addons;
try_files $uri @nightpos;

ให้บริการไฟล์แนบ

Attachments are files stored in the filestore which access is regulated by NightPOS. They cannot be directly accessed via a static web server as accessing them requires multiple lookups in the database to determine where the files are stored and whether the current user can access them or not.

Nevertheless, once the file has been located and the access rights verified by NightPOS, it is a good idea to serve the file using the static web server instead of NightPOS. For NightPOS to delegate serving files to the static web server, the X-Sendfile (apache) or X-Accel (nginx) extensions must be enabled and configured on the static web server. Once it is set up, start NightPOS with the --x-sendfile CLI flag (this unique flag is used for both X-Sendfile and X-Accel).

Note

  • ส่วนขยาย X-Sendfile สำหรับ apache (และเว็บเซิร์ฟเวอร์ที่เข้ากันได้) ไม่ต้องการการกำหนดค่าเพิ่มเติมใดๆ

  • ส่วนขยาย X-Accel สำหรับ NGINX ไม่ จำเป็นต้องมีการกำหนดค่าเพิ่มเติมต่อไปนี้:

    location /web/filestore {
        internal;
        alias /path/to/nightpos/data-dir/filestore;
        add_header Content-Security-Policy $upstream_http_content_security_policy;
        add_header X-Content-Type-Options nosniff;
    }
    

    In case you don't know what is the path to your filestore, start NightPOS with the --x-sendfile option and navigate to the /web/filestore URL directly via NightPOS (don't navigate to the URL via NGINX). This logs a warnings, the message contains the configuration you need.

ความปลอดภัย

สำหรับผู้เริ่มต้น โปรดทราบว่าการรักษาความปลอดภัยของระบบข้อมูลนั้นเป็นกระบวนการที่ต่อเนื่อง ไม่ใช่การดำเนินการเพียงครั้งเดียว คุณมีความปลอดภัยเท่าจุดอ่อนที่สุดในสภาพแวดล้อมของคุณเท่านั้น

ดังนั้น โปรดอย่าถือว่าส่วนนี้เป็นรายการมาตรการขั้นสูงสุดที่จะป้องกันปัญหาด้านความปลอดภัยทั้งหมด มีจุดมุ่งหมายเพียงเพื่อสรุปสิ่งสำคัญแรกที่คุณควรรวมไว้ในแผนปฏิบัติการด้านความปลอดภัยของคุณ ส่วนที่เหลือจะมาจากแนวทางปฏิบัติด้านความปลอดภัยที่ดีที่สุดสำหรับระบบปฏิบัติการและการเผยแพร่ของคุณ แนวทางปฏิบัติที่ดีที่สุดในแง่ของผู้ใช้ รหัสผ่าน และการจัดการการควบคุมการเข้าถึง และอื่นๆ

เมื่อปรับใช้เซิร์ฟเวอร์ที่เชื่อมต่อกับอินเทอร์เน็ต โปรดพิจารณาหัวข้อที่เกี่ยวข้องกับความปลอดภัยต่อไปนี้:

  • ตั้งรหัสผ่านผู้ดูแลระบบระดับสูงที่รัดกุมเสมอ และจำกัดการเข้าถึงหน้าการจัดการฐานข้อมูลทันทีที่ตั้งค่าระบบ โปรดดู ความปลอดภัยของผู้จัดการฐานข้อมูล

  • เลือกการเข้าสู่ระบบที่ไม่ซ้ำกันและรหัสผ่านที่รัดกุมสำหรับบัญชีผู้ดูแลระบบทั้งหมดในทุกฐานข้อมูล อย่าใช้ 'ผู้ดูแลระบบ' เป็นการเข้าสู่ระบบ อย่าใช้การล็อกอินเหล่านั้นสำหรับการดำเนินงานในแต่ละวัน เพียงเพื่อการควบคุม/จัดการการติดตั้งเท่านั้น ห้าม ใช้รหัสผ่านเริ่มต้นใดๆ เช่น ผู้ดูแลระบบ/ผู้ดูแลระบบ แม้แต่กับฐานข้อมูลการทดสอบ/ชั่วคราวก็ตาม

  • อย่า ติดตั้งข้อมูลสาธิตบนเซิร์ฟเวอร์ที่เชื่อมต่อกับอินเทอร์เน็ต ฐานข้อมูลที่มีข้อมูลสาธิตประกอบด้วยการเข้าสู่ระบบและรหัสผ่านเริ่มต้นที่สามารถใช้เพื่อเข้าสู่ระบบของคุณและก่อให้เกิดปัญหาร้ายแรง แม้แต่ในระบบชั่วคราว/การพัฒนา

  • ใช้ตัวกรองฐานข้อมูลที่เหมาะสม ( --db-filter) เพื่อจำกัดการมองเห็นฐานข้อมูลของคุณตามชื่อโฮสต์ โปรดดู dbfilter คุณยังอาจใช้ -d เพื่อจัดทำรายการฐานข้อมูลที่มีอยู่ (คั่นด้วยเครื่องหมายจุลภาค) ของคุณเองเพื่อกรอง แทนที่จะปล่อยให้ระบบดึงข้อมูลทั้งหมดจากแบ็กเอนด์ฐานข้อมูล

  • เมื่อ db_name และ db_filter ได้รับการกำหนดค่าแล้ว และตรงกับฐานข้อมูลเดียวต่อชื่อโฮสต์ คุณควรตั้งค่าตัวเลือกการกำหนดค่า list_db เป็น False เพื่อป้องกันการแสดงรายการฐานข้อมูลทั้งหมด และเพื่อบล็อก เข้าถึงหน้าจอการจัดการฐานข้อมูล (ซึ่งแสดงเป็น --no-database-list ตัวเลือกบรรทัดคำสั่ง)

  • Make sure the PostgreSQL user (--db_user) is not a super-user, and that your databases are owned by a different user. For example they could be owned by the postgres super-user if you are using a dedicated non-privileged db_user. See also Configuring NightPOS.

  • Keep installations updated by regularly installing the latest builds, either via GitHub or by downloading the latest version from https://www.nightpos.com/page/download or http://nightly.nightpos.com

  • กำหนดค่าเซิร์ฟเวอร์ของคุณในโหมดหลายกระบวนการด้วยขีดจำกัดที่เหมาะสมซึ่งตรงกับการใช้งานทั่วไปของคุณ (หน่วยความจำ/CPU/หมดเวลา) ดูเพิ่มเติม เซิร์ฟเวอร์ในตัว

  • Run NightPOS behind a web server providing HTTPS termination with a valid SSL certificate, in order to prevent eavesdropping on cleartext communications. SSL certificates are cheap, and many free options exist. Configure the web proxy to limit the size of requests, set appropriate timeouts, and then enable the proxy mode option. See also HTTPS.

  • หากคุณต้องการอนุญาตให้เข้าถึง SSH ระยะไกลไปยังเซิร์ฟเวอร์ของคุณ ตรวจสอบให้แน่ใจว่าได้ตั้งรหัสผ่านที่รัดกุมสำหรับบัญชี ทั้งหมด ไม่ใช่แค่ root ขอแนะนำอย่างยิ่งให้ปิดการใช้งานการตรวจสอบสิทธิ์โดยใช้รหัสผ่านโดยสิ้นเชิง และอนุญาตเฉพาะการตรวจสอบสิทธิ์กุญแจสาธารณะเท่านั้น นอกจากนี้ ให้พิจารณาจำกัดการเข้าถึงผ่าน VPN โดยอนุญาตเฉพาะ IP ที่เชื่อถือได้ในไฟร์วอลล์ และ/หรือใช้งานระบบตรวจจับแบบ brute-force เช่น fail2ban หรือเทียบเท่า

  • พิจารณาติดตั้งการจำกัดอัตราที่เหมาะสมบนพร็อกซีหรือไฟร์วอลล์ของคุณ เพื่อป้องกันการโจมตีแบบ brute-force และการโจมตีแบบปฏิเสธบริการ ดูเพิ่มเติม การปิดกั้นการโจมตีแบบ Brute Force สำหรับมาตรการเฉพาะ

    ผู้ให้บริการเครือข่ายหลายรายจัดให้มีการบรรเทาการโจมตีแบบ Distributed Denial of Service (DDOS) โดยอัตโนมัติ แต่มักเป็นบริการเสริม ดังนั้นคุณควรปรึกษากับผู้ให้บริการเครือข่ายเหล่านั้น

  • เมื่อใดก็ตามที่เป็นไปได้ ให้โฮสต์อินสแตนซ์การสาธิต/การทดสอบ/การแสดงแบบสาธารณะของคุณบนเครื่องที่แตกต่างจากเครื่องที่ใช้งานจริง และใช้มาตรการรักษาความปลอดภัยเช่นเดียวกับการผลิต

  • If your public-facing NightPOS server has access to sensitive internal network resources or services (e.g. via a private VLAN), implement appropriate firewall rules to protect those internal resources. This will ensure that the NightPOS server cannot be used accidentally (or as a result of malicious user actions) to access or disrupt those internal resources. Typically this can be done by applying an outbound default DENY rule on the firewall, then only explicitly authorizing access to internal resources that the NightPOS server needs to access. Systemd IP traffic access control may also be useful to implement per-process network access control.

  • If your public-facing NightPOS server is behind a Web Application Firewall, a load-balancer, a transparent DDoS protection service (like CloudFlare) or a similar network-level device, you may wish to avoid direct access to the NightPOS system. It is generally difficult to keep the endpoint IP addresses of your NightPOS servers secret. For example they can appear in web server logs when querying public systems, or in the headers of emails posted from NightPOS. In such a situation you may want to configure your firewall so that the endpoints are not accessible publicly except from the specific IP addresses of your WAF, load-balancer or proxy service. Service providers like CloudFlare usually maintain a public list of their IP address ranges for this purpose.

  • หากคุณโฮสต์ลูกค้าหลายราย ให้แยกข้อมูลและไฟล์ของลูกค้าออกจากกันโดยใช้คอนเทนเนอร์หรือเทคนิค "การกักขัง" ที่เหมาะสม

  • ตั้งค่าการสำรองข้อมูลรายวันของฐานข้อมูลและข้อมูลพื้นที่จัดเก็บไฟล์ของคุณ และคัดลอกไปยังเซิร์ฟเวอร์การเก็บถาวรระยะไกลที่ไม่สามารถเข้าถึงได้จากเซิร์ฟเวอร์เอง

  • Deploying NightPOS on Linux is strongly recommended over Windows. Should you choose nevertheless to deploy on a Windows platform, a thorough security hardening review of the server should be conducted and is outside of the scope of this guide.

การปิดกั้นการโจมตีแบบ Brute Force

For internet-facing deployments, brute force attacks on user passwords are very common, and this threat should not be neglected for NightPOS servers. NightPOS emits a log entry whenever a login attempt is performed, and reports the result: success or failure, along with the target login and source IP.

รายการบันทึกจะมีแบบฟอร์มดังต่อไปนี้

เข้าสู่ระบบไม่สำเร็จ:

2018-07-05 14:56:31,506 24849 INFO db_name odoo.addons.base.res.res_users: Login failed for db:db_name login:admin from 127.0.0.1

เข้าสู่ระบบสำเร็จ:

2018-07-05 14:56:31,506 24849 INFO db_name odoo.addons.base.res.res_users: Login successful for db:db_name login:admin from 127.0.0.1

บันทึกเหล่านี้สามารถวิเคราะห์ได้อย่างง่ายดายด้วยระบบป้องกันการบุกรุก เช่น fail2ban

ตัวอย่างเช่น ข้อกำหนดตัวกรอง failed2ban ต่อไปนี้ควรตรงกับการเข้าสู่ระบบที่ไม่สำเร็จ:

[Definition]
failregex = ^ \d+ INFO \S+ \S+ Login failed for db:\S+ login:\S+ from <HOST>
ignoreregex =

สามารถใช้กับคำจำกัดความของคุกเพื่อป้องกัน IP ที่ถูกโจมตีบน HTTP(S)

ต่อไปนี้คือลักษณะที่ปรากฏสำหรับการบล็อก IP เป็นเวลา 15 นาที เมื่อตรวจพบการพยายามเข้าสู่ระบบที่ไม่สำเร็จเกินกว่า 10 ครั้งจาก IP เดียวกันภายใน 1 นาที:

[nightpos-login]
enabled = true
port = http,https
bantime = 900  ; 15 min ban
maxretry = 10  ; if 10 attempts
findtime = 60  ; within 1 min  /!\ Should be adjusted with the TZ offset
logpath = /var/log/nightpos.log  ;  set the actual nightpos log path here

ความปลอดภัยของผู้จัดการฐานข้อมูล

Configuring NightPOS mentioned admin_passwd in passing.

การตั้งค่านี้ใช้กับหน้าจอการจัดการฐานข้อมูลทั้งหมด (เพื่อสร้าง ลบ ดัมพ์ หรือกู้คืนฐานข้อมูล)

หากหน้าจอการจัดการต้องไม่สามารถเข้าถึงได้เลย คุณควรตั้งค่าตัวเลือกการกำหนดค่า list_db เป็น False เพื่อบล็อกการเข้าถึงการเลือกฐานข้อมูลและหน้าจอการจัดการทั้งหมด

Warning

ขอแนะนำอย่างยิ่งให้ปิดการใช้งานตัวจัดการฐานข้อมูลสำหรับระบบที่เชื่อมต่อกับอินเทอร์เน็ต! มีไว้เพื่อเป็นเครื่องมือในการพัฒนา/สาธิต เพื่อให้ง่ายต่อการสร้างและจัดการฐานข้อมูลอย่างรวดเร็ว ไม่ได้ออกแบบมาเพื่อใช้ในการผลิต และอาจเปิดเผยฟีเจอร์ที่เป็นอันตรายแก่ผู้โจมตีด้วยซ้ำ นอกจากนี้ยังไม่ได้ออกแบบมาเพื่อจัดการกับฐานข้อมูลขนาดใหญ่ และอาจทำให้เกิดขีดจำกัดของหน่วยความจำ

ในระบบที่ใช้งานจริง ผู้ดูแลระบบควรดำเนินการจัดการฐานข้อมูลเสมอ รวมถึงการจัดเตรียมฐานข้อมูลใหม่และการสำรองข้อมูลอัตโนมัติ

ตรวจสอบให้แน่ใจว่าได้ตั้งค่าพารามิเตอร์ db_name ที่เหมาะสม (และเป็นทางเลือก db_filter ด้วย) เพื่อให้ระบบสามารถระบุฐานข้อมูลเป้าหมายสำหรับแต่ละคำขอ ไม่เช่นนั้นผู้ใช้จะถูกบล็อกเนื่องจากจะไม่ได้รับอนุญาตให้เลือก ฐานข้อมูลนั้นเอง

หากต้องเข้าถึงหน้าจอการจัดการได้จากชุดเครื่องที่เลือกเท่านั้น ให้ใช้ฟีเจอร์ของพร็อกซีเซิร์ฟเวอร์เพื่อบล็อกการเข้าถึงทุกเส้นทางที่ขึ้นต้นด้วย /web/database ยกเว้น (อาจจะ) /web/database/selector ซึ่งแสดงหน้าจอการเลือกฐานข้อมูล

หากควรปล่อยให้หน้าจอการจัดการฐานข้อมูลสามารถเข้าถึงได้ การตั้งค่า admin_passwd จะต้องเปลี่ยนจากค่าเริ่มต้น admin: รหัสผ่านนี้จะถูกตรวจสอบก่อนที่จะอนุญาตการดำเนินการแก้ไขฐานข้อมูล

ควรเก็บไว้อย่างปลอดภัย และควรสร้างขึ้นแบบสุ่ม เช่น

$ python3 -c 'import base64, os; print(base64.b64encode(os.urandom(24)))'

ซึ่งสร้างสตริงที่พิมพ์ได้แบบสุ่มหลอก 32 ตัวอักษร

รีเซ็ตรหัสผ่านหลัก

There may be instances where the master password is misplaced, or compromised, and needs to be reset. The following process is for system administrators of an NightPOS on-premise database detailing how to manually reset and re-encrypt the master password.

ดูเพิ่มเติม

NightPOS Accounts

When creating a new on-premise database, a random master password is generated. NightPOS recommends using this password to secure the database. This password is implemented by default, so there is a secure master password for any NightPOS on-premise deployment.

Warning

When creating an NightPOS on-premise database the installation is accessible to anyone on the internet, until this password is set to secure the database.

The master password is specified in the NightPOS configuration file (nightpos.conf or nightposrc (hidden file)). The NightPOS master password is needed to modify, create, or delete a database through the graphical user interface (GUI).

ค้นหาไฟล์การกำหนดค่า

First, open the NightPOS configuration file (nightpos.conf or nightposrc (hidden file)).

The configuration file is located at: c:\ProgramFiles\NightPOS{VERSION}\server\nightpos.conf

เปลี่ยนรหัสผ่านเก่า

เมื่อเปิดไฟล์ที่เหมาะสมแล้ว ให้ดำเนินการแก้ไขรหัสผ่านเก่าในไฟล์กำหนดค่าเป็นรหัสผ่านชั่วคราว

หลังจากค้นหาไฟล์การกำหนดค่าแล้ว ให้เปิดโดยใช้ (GUI) ซึ่งสามารถทำได้โดยเพียงดับเบิลคลิกที่ไฟล์ จากนั้น อุปกรณ์ควรมีค่าเริ่มต้น GUI เพื่อเปิดไฟล์

จากนั้น แก้ไขบรรทัดรหัสผ่านหลัก admin_passwd = $pbkdf2-sha… เป็น admin_passwd = newpassword1234 เป็นต้น รหัสผ่านนี้สามารถเป็นอะไรก็ได้ ตราบใดที่มันถูกบันทึกไว้ชั่วคราว ตรวจสอบให้แน่ใจว่าได้แก้ไขอักขระทั้งหมดหลัง =

Example

บรรทัดแสดงดังนี้: admin_passwd = $pbkdf2-sh39dji295.59mptrfW.9z6HkA$w9j9AMVmKAP17OosCqDxDv2hjsvzlLpF8Rra8I7p/b573hji540mk/.3ek0lg%kvkol6k983mkf/40fjki79m

บรรทัดที่แก้ไขจะแสดงดังนี้: admin_passwd = newpassword1234

Important

จำเป็นอย่างยิ่งที่จะต้องเปลี่ยนรหัสผ่านเป็นอย่างอื่น แทนที่จะเรียกใช้การรีเซ็ตรหัสผ่านใหม่โดยเพิ่มเครื่องหมายอัฒภาค ; ที่จุดเริ่มต้นของบรรทัด สิ่งนี้ทำให้มั่นใจได้ว่าฐานข้อมูลมีความปลอดภัยตลอดกระบวนการรีเซ็ตรหัสผ่านทั้งหมด

Restart NightPOS server

After setting the temporary password, a restart of the NightPOS server is required.

To restart the NightPOS server, first, type services into the Windows Search bar. Then, select the Services application, and scroll down to the NightPOS service.

Next, right click on NightPOS, and select Start or Restart. This action manually restarts the NightPOS server.

ใช้เว็บอินเตอร์เฟสเพื่อเข้ารหัสรหัสผ่านอีกครั้ง

ขั้นแรก ไปที่ /web/database/manager หรือ http://server_ip:port/web/database/manager ในเบราว์เซอร์

Note

แทนที่ server_ip ด้วยที่อยู่ IP ของฐานข้อมูล แทนที่ port ด้วยพอร์ตที่มีหมายเลขที่ฐานข้อมูลสามารถเข้าถึงได้

จากนั้นคลิก ตั้งรหัสผ่านหลัก และพิมพ์รหัสผ่านชั่วคราวที่เลือกไว้ก่อนหน้านี้ลงในช่อง รหัสผ่านหลัก ทำตามขั้นตอนนี้ พิมพ์ รหัสผ่านหลักใหม่ รหัสผ่านหลักใหม่ จะถูกแฮช (หรือเข้ารหัส) เมื่อคลิกปุ่ม ดำเนินการต่อ

ณ จุดนี้ รหัสผ่านได้รับการรีเซ็ตเรียบร้อยแล้ว และรหัสผ่านใหม่เวอร์ชันแฮชจะปรากฏในไฟล์การกำหนดค่า

ดูเพิ่มเติม

For more information on NightPOS database security, see this documentation: ความปลอดภัยของผู้จัดการฐานข้อมูล.

เบราว์เซอร์ที่รองรับ

NightPOS supports the latest version of the following browsers.

  • Google Chrome

  • Mozilla Firefox

  • Microsoft Edge

  • Apple Safari

1

to have multiple NightPOS installations use the same PostgreSQL database, or to provide more computing resources to both software.

2

ในทางเทคนิคแล้ว เครื่องมืออย่าง socat สามารถใช้กับซ็อกเก็ตพร็อกซี UNIX ข้ามเครือข่ายได้ แต่ส่วนใหญ่ใช้สำหรับซอฟต์แวร์ที่สามารถใช้ได้ผ่านซ็อกเก็ต UNIX เท่านั้น

3

หรือสามารถเข้าถึงได้ผ่านเครือข่ายสวิตช์แพ็กเก็ตภายในเท่านั้น แต่ต้องใช้สวิตช์ที่ปลอดภัย การป้องกันการปลอมแปลง ARP และขัดขวางการใช้ WiFi แม้แต่บนเครือข่ายสวิตช์แพ็กเก็ตที่ปลอดภัย ขอแนะนำให้ปรับใช้ผ่าน HTTPS และค่าใช้จ่ายที่เป็นไปได้จะลดลง เนื่องจากใบรับรอง "ที่ลงนามด้วยตนเอง" จะปรับใช้ในสภาพแวดล้อมที่มีการควบคุมได้ง่ายกว่าบนอินเทอร์เน็ต