@rakay-technology/kraft 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +263 -0
- package/dist/bare-HL2GUYE2.js +27 -0
- package/dist/bowser-HNOTPGJO.js +2825 -0
- package/dist/chunk-3CJLKL6E.js +124 -0
- package/dist/chunk-3NQQXMDR.js +2098 -0
- package/dist/chunk-42WQABXM.js +439 -0
- package/dist/chunk-5GPXMTE4.js +25 -0
- package/dist/chunk-AJ4QZLZ2.js +1069 -0
- package/dist/chunk-AO252K7Z.js +137 -0
- package/dist/chunk-BQMFIXHI.js +975 -0
- package/dist/chunk-DM3PKWDC.js +2453 -0
- package/dist/chunk-DOD2BXHQ.js +1364 -0
- package/dist/chunk-DRK3MEDS.js +2870 -0
- package/dist/chunk-EW4PHKB2.js +13914 -0
- package/dist/chunk-HMJUFZK7.js +340 -0
- package/dist/chunk-I2TOOF2A.js +517 -0
- package/dist/chunk-I3DPMTSF.js +29 -0
- package/dist/chunk-JSCZT76F.js +2588 -0
- package/dist/chunk-MNV2QFHW.js +138 -0
- package/dist/chunk-MOLPYPVH.js +2529 -0
- package/dist/chunk-N4OALTFK.js +295 -0
- package/dist/chunk-OFXBNFNL.js +458 -0
- package/dist/chunk-ONKEYSMY.js +1388 -0
- package/dist/chunk-PDW4L3NV.js +17 -0
- package/dist/chunk-PNNXWA2A.js +1947 -0
- package/dist/chunk-PNRPKRJU.js +11105 -0
- package/dist/chunk-PVOWHIND.js +26781 -0
- package/dist/chunk-PXKCZB2I.js +46 -0
- package/dist/chunk-PZVKPCKE.js +475 -0
- package/dist/chunk-QWHBRY2K.js +4945 -0
- package/dist/chunk-RFOBMHQ7.js +338 -0
- package/dist/chunk-RHLNVZMS.js +28 -0
- package/dist/chunk-RVER2EOO.js +577 -0
- package/dist/chunk-S3QBGGVP.js +81 -0
- package/dist/chunk-TAML5WMA.js +198 -0
- package/dist/chunk-THTEUDBC.js +3188 -0
- package/dist/chunk-WYNM7L22.js +329 -0
- package/dist/chunk-XGCG4MD5.js +102 -0
- package/dist/chunk-XVKUFMIB.js +148 -0
- package/dist/chunk-XZYFZ6A5.js +50 -0
- package/dist/chunk-Y7PVJUXJ.js +2275 -0
- package/dist/chunk-YRSZPVMB.js +306 -0
- package/dist/chunk-YZUKHG3S.js +362 -0
- package/dist/chunk-ZVFS4LUA.js +116 -0
- package/dist/chunk-ZWLDLTJP.js +1417 -0
- package/dist/detect-676SNZK4.js +48 -0
- package/dist/dist-es-2YRDXMUU.js +73 -0
- package/dist/dist-es-CCVZEFRZ.js +91 -0
- package/dist/dist-es-EDUSMF6Q.js +488 -0
- package/dist/dist-es-IOH6G4GM.js +380 -0
- package/dist/dist-es-KWSMDPIP.js +26 -0
- package/dist/dist-es-UYDDOVZ3.js +173 -0
- package/dist/dist-es-XUOR4NQN.js +321 -0
- package/dist/docker-GOT3Q7DJ.js +41 -0
- package/dist/docker-edge-executor-VO6JHHW2.js +19 -0
- package/dist/edge-import-NFCHIW7G.js +50 -0
- package/dist/edge-preflight-QUJ757C6.js +45 -0
- package/dist/ensure-container-edge-Q7IZXHGM.js +38 -0
- package/dist/event-streams-TR4GAC53.js +46 -0
- package/dist/executor-GKXKN52K.js +42 -0
- package/dist/host-channel-preflight-Z6HYSPKO.js +48 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9469 -0
- package/dist/loadSso-UGF4JMRK.js +581 -0
- package/dist/local-executor-OMMDKXCM.js +13 -0
- package/dist/nginx-VITTWZZU.js +42 -0
- package/dist/node-bootstrap.js +277 -0
- package/dist/node-entry.js +55 -0
- package/dist/noop-CLLJHCPL.js +11 -0
- package/dist/openresty-lua-6I3Z6PEQ.js +90 -0
- package/dist/privilege-UQAI2HV4.js +20 -0
- package/dist/server/engine/ChangeLog +2289 -0
- package/dist/server/engine/Documentations +5 -0
- package/dist/server/engine/LICENSE +674 -0
- package/dist/server/engine/README.md +34 -0
- package/dist/server/engine/conf/amavisd +150 -0
- package/dist/server/engine/conf/clamav +71 -0
- package/dist/server/engine/conf/core +632 -0
- package/dist/server/engine/conf/dovecot +151 -0
- package/dist/server/engine/conf/fail2ban +72 -0
- package/dist/server/engine/conf/global +698 -0
- package/dist/server/engine/conf/iredapd +52 -0
- package/dist/server/engine/conf/logwatch +28 -0
- package/dist/server/engine/conf/postfix +97 -0
- package/dist/server/engine/conf/postgresql +93 -0
- package/dist/server/engine/conf/spamassassin +39 -0
- package/dist/server/engine/dialog/config_via_dialog.sh +258 -0
- package/dist/server/engine/dialog/optional_components.sh +122 -0
- package/dist/server/engine/dialog/pgsql_config.sh +52 -0
- package/dist/server/engine/dialog/virtual_domain_config.sh +94 -0
- package/dist/server/engine/functions/amavisd.sh +267 -0
- package/dist/server/engine/functions/backend.sh +85 -0
- package/dist/server/engine/functions/clamav.sh +100 -0
- package/dist/server/engine/functions/cleanup.sh +393 -0
- package/dist/server/engine/functions/dovecot.sh +583 -0
- package/dist/server/engine/functions/fail2ban.sh +209 -0
- package/dist/server/engine/functions/iredapd.sh +356 -0
- package/dist/server/engine/functions/optional_components.sh +24 -0
- package/dist/server/engine/functions/packages.sh +522 -0
- package/dist/server/engine/functions/packages_freebsd.sh +179 -0
- package/dist/server/engine/functions/postfix.sh +457 -0
- package/dist/server/engine/functions/postgresql.sh +239 -0
- package/dist/server/engine/functions/spamassassin.sh +49 -0
- package/dist/server/engine/functions/system_accounts.sh +128 -0
- package/dist/server/engine/iRedMail.sh +144 -0
- package/dist/server/engine/pkgs/get_all.sh +338 -0
- package/dist/server/engine/pkgs/pkgs.freebsd.sha256 +3 -0
- package/dist/server/engine/pkgs/pkgs.openbsd.sha256 +6 -0
- package/dist/server/engine/pkgs/pkgs.sha256 +1 -0
- package/dist/server/engine/samples/amavisd/amavisd.conf +702 -0
- package/dist/server/engine/samples/amavisd/amavisd.mysql +278 -0
- package/dist/server/engine/samples/amavisd/amavisd.pgsql +253 -0
- package/dist/server/engine/samples/amavisd/amavisd.schema +942 -0
- package/dist/server/engine/samples/amavisd/default_spam_policy.sql +46 -0
- package/dist/server/engine/samples/dovecot/dovecot-2.4-mariadb.conf +758 -0
- package/dist/server/engine/samples/dovecot/dovecot-2.4-openldap.conf +767 -0
- package/dist/server/engine/samples/dovecot/dovecot-2.4-pgsql.conf +762 -0
- package/dist/server/engine/samples/dovecot/dovecot-last-login.conf +50 -0
- package/dist/server/engine/samples/dovecot/dovecot-ldap.conf +21 -0
- package/dist/server/engine/samples/dovecot/dovecot-share-folder.conf +22 -0
- package/dist/server/engine/samples/dovecot/dovecot-sql.conf +28 -0
- package/dist/server/engine/samples/dovecot/dovecot-used-quota.conf +13 -0
- package/dist/server/engine/samples/dovecot/dovecot.conf +484 -0
- package/dist/server/engine/samples/dovecot/dovecot.sieve +7 -0
- package/dist/server/engine/samples/dovecot/dovecot2-quota-warning.sh +38 -0
- package/dist/server/engine/samples/dovecot/sql/imap_share_folder.mysql +16 -0
- package/dist/server/engine/samples/dovecot/sql/last_login.mysql +12 -0
- package/dist/server/engine/samples/dovecot/sql/used_quota.mysql +26 -0
- package/dist/server/engine/samples/dovecot/systemd/override.conf +3 -0
- package/dist/server/engine/samples/fail2ban/action.d/banned_db.conf +9 -0
- package/dist/server/engine/samples/fail2ban/bin/fail2ban_banned_db +268 -0
- package/dist/server/engine/samples/fail2ban/fail2ban.local +17 -0
- package/dist/server/engine/samples/fail2ban/filter.d/dovecot.iredmail.conf +5 -0
- package/dist/server/engine/samples/fail2ban/filter.d/postfix-pregreet.iredmail.conf +16 -0
- package/dist/server/engine/samples/fail2ban/filter.d/postfix.iredmail.conf +18 -0
- package/dist/server/engine/samples/fail2ban/filter.d/roundcube.iredmail.conf +9 -0
- package/dist/server/engine/samples/fail2ban/jail.d/dovecot.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/nginx-http-auth.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/postfix-pregreet.local +9 -0
- package/dist/server/engine/samples/fail2ban/jail.d/postfix.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/roundcube.local +9 -0
- package/dist/server/engine/samples/fail2ban/jail.d/sogo.local +8 -0
- package/dist/server/engine/samples/fail2ban/jail.d/sshd.local +11 -0
- package/dist/server/engine/samples/fail2ban/jail.local +6 -0
- package/dist/server/engine/samples/fail2ban/openbsd/rc +27 -0
- package/dist/server/engine/samples/fail2ban/sql/fail2ban.mysql +49 -0
- package/dist/server/engine/samples/fail2ban/sql/fail2ban.pgsql +48 -0
- package/dist/server/engine/samples/firewall/firewalld/services/ssh.xml +6 -0
- package/dist/server/engine/samples/firewall/firewalld/zones/iredmail.xml +15 -0
- package/dist/server/engine/samples/firewall/iptables/ip6tables.init.debian +362 -0
- package/dist/server/engine/samples/firewall/iptables/ip6tables.rules +53 -0
- package/dist/server/engine/samples/firewall/iptables/iptables.init.debian +363 -0
- package/dist/server/engine/samples/firewall/iptables/iptables.rules +54 -0
- package/dist/server/engine/samples/firewall/nftables.conf +58 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/dovecot.conf +3 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/iredapd.conf +1 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/mlmmjadmin.conf +1 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/php-fpm.conf +2 -0
- package/dist/server/engine/samples/freebsd/newsyslog.conf.d/slapd.conf +1 -0
- package/dist/server/engine/samples/freebsd/syslog.d/dovecot.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/fail2ban.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/iredapd.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/mlmmjadmin.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/php-fpm.conf +2 -0
- package/dist/server/engine/samples/freebsd/syslog.d/slapd.conf +2 -0
- package/dist/server/engine/samples/iredmail/iredmail.mysql +491 -0
- package/dist/server/engine/samples/iredmail/iredmail.pgsql +465 -0
- package/dist/server/engine/samples/iredmail/iredmail.schema +456 -0
- package/dist/server/engine/samples/iredmail/used_quota_triggers_dovecot_2.3.pgsql +40 -0
- package/dist/server/engine/samples/iredmail/used_quota_triggers_dovecot_2.4.pgsql +18 -0
- package/dist/server/engine/samples/logrotate/dovecot +13 -0
- package/dist/server/engine/samples/logrotate/iredapd +13 -0
- package/dist/server/engine/samples/logrotate/mlmmjadmin +13 -0
- package/dist/server/engine/samples/logrotate/openldap +19 -0
- package/dist/server/engine/samples/logrotate/php-fpm +13 -0
- package/dist/server/engine/samples/openbsd/ldapd.conf +58 -0
- package/dist/server/engine/samples/openbsd/pf.conf +28 -0
- package/dist/server/engine/samples/postfix/command_filter.pcre +3 -0
- package/dist/server/engine/samples/postfix/freebsd/mailer.conf +9 -0
- package/dist/server/engine/samples/postfix/helo_access.pcre +180 -0
- package/dist/server/engine/samples/postfix/ldap/catchall_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/recipient_bcc_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/recipient_bcc_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/relay_domains.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_bcc_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_bcc_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_dependent_relayhost_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_dependent_relayhost_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/sender_login_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/transport_maps_domain.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/transport_maps_user.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_alias_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_group_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_group_members_maps.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_mailbox_domains.cf +11 -0
- package/dist/server/engine/samples/postfix/ldap/virtual_mailbox_maps.cf +12 -0
- package/dist/server/engine/samples/postfix/main.cf +282 -0
- package/dist/server/engine/samples/postfix/main.cf.amavisd +7 -0
- package/dist/server/engine/samples/postfix/main.cf.dovecot +8 -0
- package/dist/server/engine/samples/postfix/main.cf.ldap +39 -0
- package/dist/server/engine/samples/postfix/main.cf.mlmmj +5 -0
- package/dist/server/engine/samples/postfix/main.cf.mysql +39 -0
- package/dist/server/engine/samples/postfix/main.cf.pgsql +39 -0
- package/dist/server/engine/samples/postfix/main.cf.postscreen +30 -0
- package/dist/server/engine/samples/postfix/master.cf +101 -0
- package/dist/server/engine/samples/postfix/mysql/catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/domain_alias_catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/domain_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/recipient_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/recipient_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/relay_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/sender_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/sender_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/sender_dependent_relayhost_maps.cf +6 -0
- package/dist/server/engine/samples/postfix/mysql/sender_login_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/transport_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/transport_maps_maillist.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/transport_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/virtual_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/virtual_mailbox_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/mysql/virtual_mailbox_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/domain_alias_catchall_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/domain_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/recipient_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/recipient_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/relay_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_bcc_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_bcc_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_dependent_relayhost_maps.cf +6 -0
- package/dist/server/engine/samples/postfix/pgsql/sender_login_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/transport_maps_domain.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/transport_maps_maillist.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/transport_maps_user.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/virtual_alias_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/virtual_mailbox_domains.cf +5 -0
- package/dist/server/engine/samples/postfix/pgsql/virtual_mailbox_maps.cf +5 -0
- package/dist/server/engine/samples/postfix/postscreen_access.cidr +6 -0
- package/dist/server/engine/samples/postgresql/sql/add_first_domain_and_user.sql +34 -0
- package/dist/server/engine/samples/postgresql/sql/grant_permissions.sql +14 -0
- package/dist/server/engine/samples/postgresql/sql/init_vmail_db.sql +15 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-dovecot.conf +23 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-fail2ban.conf +2 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-iredapd.conf +12 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-mlmmjadmin.conf +12 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-openldap.conf +2 -0
- package/dist/server/engine/samples/rsyslog.d/1-iredmail-phpfpm.conf +3 -0
- package/dist/server/engine/samples/spamassassin/local.cf +186 -0
- package/dist/server/engine/samples/spamassassin/razor.conf +1 -0
- package/dist/server/engine/samples/systemd/clamd.service.d/override.conf +2 -0
- package/dist/server/engine/samples/systemd/mariadb.service.d/override.conf +3 -0
- package/dist/server/engine/samples/systemd/slapd.service.d/override.conf +6 -0
- package/dist/server/engine/samples/yum/CentOS-Linux-AppStream.repo +6 -0
- package/dist/server/engine/samples/yum/CentOS-Linux-PowerTools.repo +6 -0
- package/dist/server/engine/samples/yum/CentOS-Stream-AppStream.repo +7 -0
- package/dist/server/engine/samples/yum/CentOS-Stream-PowerTools.repo +7 -0
- package/dist/server/engine/samples/yum/symas-openldap.repo +6 -0
- package/dist/server/engine/tools/add_enabled_service.py +60 -0
- package/dist/server/engine/tools/backup_mysql.sh +238 -0
- package/dist/server/engine/tools/backup_openldap.sh +230 -0
- package/dist/server/engine/tools/backup_pgsql.sh +217 -0
- package/dist/server/engine/tools/backup_sogo.sh +156 -0
- package/dist/server/engine/tools/create_mail_user_OpenLDAP.py +335 -0
- package/dist/server/engine/tools/create_mail_user_OpenLDAP.sh +287 -0
- package/dist/server/engine/tools/create_mail_user_SQL.sh +127 -0
- package/dist/server/engine/tools/enable_postscreen.sh +144 -0
- package/dist/server/engine/tools/fail2ban_unban_ip.sh +39 -0
- package/dist/server/engine/tools/find_sasl_login_ip.sh +20 -0
- package/dist/server/engine/tools/find_top_sasl_usernames.sh +28 -0
- package/dist/server/engine/tools/generate_ssl_keys.sh +85 -0
- package/dist/server/engine/tools/kill_high_cpu_sogo_process.sh +32 -0
- package/dist/server/engine/tools/ldap_assign_user_to_groups.py +151 -0
- package/dist/server/engine/tools/ldap_move_members_to_another_group.py +129 -0
- package/dist/server/engine/tools/migrate_sql_alias_table.py +177 -0
- package/dist/server/engine/update/0.9.8/amavisd.mysql +29 -0
- package/dist/server/engine/update/0.9.8/amavisd.pgsql +39 -0
- package/dist/server/engine/update/0.9.8/iredmail.mysql +53 -0
- package/dist/server/engine/update/0.9.8/iredmail.pgsql +61 -0
- package/dist/server/engine/update/0.9.9/iredmail.mysql +2 -0
- package/dist/server/engine/update/0.9.9/iredmail.pgsql +2 -0
- package/dist/server/engine/update/1.0/iredmail.mysql +2 -0
- package/dist/server/engine/update/1.0/iredmail.pgsql +2 -0
- package/dist/server/engine/update/1.2/last_login.mysql +16 -0
- package/dist/server/engine/update/1.4.0/iredmail.mysql +22 -0
- package/dist/server/engine/update/1.4.0/iredmail.pgsql +20 -0
- package/dist/server/engine/update/1.4.1/iredmail.mysql +3 -0
- package/dist/server/engine/update/1.4.1/iredmail.pgsql +3 -0
- package/dist/server/engine/update/1.4.1/sogo.mysql +11 -0
- package/dist/server/engine/update/1.4.1/sogo.pgsql +30 -0
- package/dist/server/engine/update/1.4.1/update-ldap.py +66 -0
- package/dist/server/engine/update/1.4.2/iredmail.mysql +9 -0
- package/dist/server/engine/update/1.4.2/iredmail.pgsql +9 -0
- package/dist/server/engine/update/1.4.2/sogo.pgsql +30 -0
- package/dist/server/engine/update/1.6.0/sogo_view.pgsql +27 -0
- package/dist/server/engine/update/1.6.3/iredmail.mysql +1 -0
- package/dist/server/engine/update/1.7.0/fail2ban.mysql +11 -0
- package/dist/server/engine/update/1.7.0/fail2ban.pgsql +12 -0
- package/dist/server/engine/update/1.7.1/amavisd.mysql +1 -0
- package/dist/server/engine/update/1.7.2/vmail.mysql +30 -0
- package/dist/server/engine/update/1.7.3/deleted_mailboxes.mysql +43 -0
- package/dist/server/engine/update/1.7.3/iredadmin.mysql +26 -0
- package/dist/server/engine/update/1.7.3/vmail.mysql +79 -0
- package/dist/server/engine/update/1.7.3/vmail.pgsql +9 -0
- package/dist/server/engine/update/README.md +1 -0
- package/dist/server/engine/update/ldap/README.md +39 -0
- package/dist/server/engine/update/ldap/update-ldap-dovecot-2.3.py +69 -0
- package/dist/server/index.js +349016 -0
- package/dist/server/lua/geo_country.lua +127 -0
- package/dist/server/lua/maxminddb.lua +403 -0
- package/dist/server/lua/mgmt_api.lua +654 -0
- package/dist/server/lua/pipe_stream.lua +103 -0
- package/dist/server/lua/rules_guard.lua +132 -0
- package/dist/server/lua/rules_lib.lua +176 -0
- package/dist/server/lua/site_logger.lua +405 -0
- package/dist/server/lua/webhook_handler.lua +126 -0
- package/dist/server/migrations/0000_init.sql +666 -0
- package/dist/server/migrations/0001_brief_tomorrow_man.sql +47 -0
- package/dist/server/migrations/0002_funny_dazzler.sql +2 -0
- package/dist/server/migrations/0003_third_killer_shrike.sql +1 -0
- package/dist/server/migrations/0004_session_active_org_not_null.sql +10 -0
- package/dist/server/migrations/0005_warm_amazoness.sql +3 -0
- package/dist/server/migrations/0006_lumpy_joystick.sql +1 -0
- package/dist/server/migrations/0007_outgoing_maginty.sql +2 -0
- package/dist/server/migrations/0008_frozen_cutover.sql +3 -0
- package/dist/server/migrations/0009_credits_billing.sql +142 -0
- package/dist/server/migrations/0010_credit_grant_dedupe.sql +14 -0
- package/dist/server/migrations/0011_remove_credit_ledger.sql +23 -0
- package/dist/server/migrations/0012_smart_deploys_and_git_rollback.sql +81 -0
- package/dist/server/migrations/0013_fix_check_run_rollup_unique.sql +38 -0
- package/dist/server/migrations/0014_default_rollback_git.sql +9 -0
- package/dist/server/migrations/0015_billing_idempotency_grants.sql +41 -0
- package/dist/server/migrations/0016_github_auth_high_findings.sql +30 -0
- package/dist/server/migrations/0017_spooky_rumiko_fujikawa.sql +6 -0
- package/dist/server/migrations/0018_calm_shatterstar.sql +1 -0
- package/dist/server/migrations/0019_rename_workspace_install_to_prepare.sql +1 -0
- package/dist/server/migrations/0020_uneven_the_renegades.sql +13 -0
- package/dist/server/migrations/0021_shiny_firestar.sql +2 -0
- package/dist/server/migrations/0022_version_on_success_backfill.sql +6 -0
- package/dist/server/migrations/0023_productive_gorilla_man.sql +17 -0
- package/dist/server/migrations/0024_sleepy_peter_quill.sql +2 -0
- package/dist/server/migrations/0025_smooth_blue_shield.sql +1 -0
- package/dist/server/migrations/0026_mail_backup_source.sql +11 -0
- package/dist/server/migrations/0027_opposite_anthem.sql +6 -0
- package/dist/server/migrations/0028_stale_rogue.sql +18 -0
- package/dist/server/migrations/0029_bouncy_loners.sql +16 -0
- package/dist/server/migrations/0030_bright_darkstar.sql +6 -0
- package/dist/server/migrations/0031_conscious_catseye.sql +13 -0
- package/dist/server/migrations/0032_wet_mimic.sql +51 -0
- package/dist/server/migrations/0033_eminent_molly_hayes.sql +2 -0
- package/dist/server/migrations/0034_nervous_surge.sql +1 -0
- package/dist/server/migrations/0035_thankful_morgan_stark.sql +1 -0
- package/dist/server/migrations/0036_gorgeous_scalphunter.sql +17 -0
- package/dist/server/migrations/0037_clever_makkari.sql +28 -0
- package/dist/server/migrations/0038_young_magneto.sql +1 -0
- package/dist/server/migrations/0039_secret_lady_ursula.sql +15 -0
- package/dist/server/migrations/0040_sharp_red_wolf.sql +16 -0
- package/dist/server/migrations/0041_round_spyke.sql +4 -0
- package/dist/server/migrations/0042_dapper_havok.sql +1 -0
- package/dist/server/migrations/0043_fast_sharon_ventura.sql +15 -0
- package/dist/server/migrations/0044_amused_shape.sql +8 -0
- package/dist/server/migrations/0045_amusing_korath.sql +1 -0
- package/dist/server/migrations/0046_white_harrier.sql +35 -0
- package/dist/server/migrations/0047_sloppy_strong_guy.sql +2 -0
- package/dist/server/migrations/0048_funny_emma_frost.sql +2 -0
- package/dist/server/migrations/0049_nappy_piledriver.sql +3 -0
- package/dist/server/migrations/0050_add_service_deployment_image_digest.sql +1 -0
- package/dist/server/migrations/0051_add_update_status.sql +19 -0
- package/dist/server/migrations/0052_add_notice_target.sql +2 -0
- package/dist/server/migrations/0053_colossal_sandman.sql +14 -0
- package/dist/server/migrations/0054_add_instance_smtp.sql +5 -0
- package/dist/server/migrations/0055_rainy_klaw.sql +22 -0
- package/dist/server/migrations/0056_moaning_daredevil.sql +2 -0
- package/dist/server/migrations/0057_complete_prism.sql +18 -0
- package/dist/server/migrations/0058_add_server_is_local.sql +1 -0
- package/dist/server/migrations/0059_legal_fixer.sql +18 -0
- package/dist/server/migrations/0060_add_route_strategy_host_port.sql +3 -0
- package/dist/server/migrations/0061_notification_default_multi_kind.sql +3 -0
- package/dist/server/migrations/0062_add_incoming_webhook.sql +21 -0
- package/dist/server/migrations/0063_add_migration_logs.sql +1 -0
- package/dist/server/migrations/0064_add_migration_partial.sql +2 -0
- package/dist/server/migrations/0065_custom_app_template.sql +14 -0
- package/dist/server/migrations/0066_ensure_migration_partial_columns.sql +2 -0
- package/dist/server/migrations/0067_webhook_delivery.sql +28 -0
- package/dist/server/migrations/0068_add_migration_target_volumes.sql +1 -0
- package/dist/server/migrations/0069_add_project_composite_routes.sql +1 -0
- package/dist/server/migrations/0070_forward_git_to_server.sql +1 -0
- package/dist/server/migrations/0071_gh_device_token.sql +3 -0
- package/dist/server/migrations/0072_gh_device_token_method.sql +1 -0
- package/dist/server/migrations/0073_project_volumes_object_storage.sql +3 -0
- package/dist/server/migrations/0074_project_compose_path.sql +1 -0
- package/dist/server/migrations/0075_service_command_argv.sql +1 -0
- package/dist/server/migrations/0076_rollback_retention.sql +17 -0
- package/dist/server/migrations/0077_domain_redirect.sql +13 -0
- package/dist/server/migrations/0078_grant_source_scope.sql +30 -0
- package/dist/server/migrations/0079_project_readiness.sql +18 -0
- package/dist/server/migrations/0080_deployment_error_classification.sql +26 -0
- package/dist/server/migrations/0081_project_readiness_repair.sql +34 -0
- package/dist/server/migrations/0082_edge_target_verification.sql +39 -0
- package/dist/server/migrations/0083_service_incident.sql +84 -0
- package/dist/server/migrations/0084_analytics_daily_rollup.sql +72 -0
- package/dist/server/migrations/0085_resource_usage.sql +68 -0
- package/dist/server/migrations/0086_remote_infra_updates.sql +41 -0
- package/dist/server/migrations/0087_server_container_version_columns.sql +17 -0
- package/dist/server/migrations/0088_audit_source_and_settings.sql +27 -0
- package/dist/server/migrations/0089_auto_scan_infra.sql +7 -0
- package/dist/server/migrations/0090_project_collect_paths.sql +18 -0
- package/dist/server/migrations/0091_project_server_id.sql +26 -0
- package/dist/server/migrations/0092_project_internal_alias.sql +13 -0
- package/dist/server/migrations/0093_service_incident_org_index.sql +13 -0
- package/dist/server/migrations/0094_backup_restore_meta.sql +15 -0
- package/dist/server/migrations/0095_backup_restore_cancel.sql +19 -0
- package/dist/server/migrations/0096_backup_policy_retention_defaults.sql +20 -0
- package/dist/server/migrations/0097_update_status_upstream_only.sql +35 -0
- package/dist/server/migrations/0098_instance_product_mode.sql +12 -0
- package/dist/server/migrations/0099_mail_webmail_project.sql +24 -0
- package/dist/server/migrations/0100_server_ssh_private_key.sql +11 -0
- package/dist/server/migrations/0101_mail_resume_step.sql +12 -0
- package/dist/server/migrations/0102_project_workload_axes.sql +19 -0
- package/dist/server/migrations/0103_dns_credential.sql +41 -0
- package/dist/server/migrations/0104_instance_host_control.sql +15 -0
- package/dist/server/migrations/0105_mail_inbound_rules.sql +80 -0
- package/dist/server/migrations/0106_mcp_call_tracking.sql +23 -0
- package/dist/server/migrations/0107_build_minute_metering_indexes.sql +20 -0
- package/dist/server/migrations/0108_credential.sql +68 -0
- package/dist/server/migrations/0109_service_build_args.sql +9 -0
- package/dist/server/migrations/0110_service_deployment_host_ports.sql +18 -0
- package/dist/server/migrations/0111_host_port_claim.sql +381 -0
- package/dist/server/migrations/0112_backup_run_execution_lease.sql +12 -0
- package/dist/server/migrations/0113_docker_migration_execution_lease.sql +11 -0
- package/dist/server/migrations/0114_build_session_execution_lease_index.sql +6 -0
- package/dist/server/migrations/0115_orphan_target_key.sql +3 -0
- package/dist/server/migrations/0116_domain_ssl_challenge.sql +2 -0
- package/dist/server/migrations/0117_github_installation_workspace_scope.sql +24 -0
- package/dist/server/migrations/0118_git_sources.sql +66 -0
- package/dist/server/migrations/0119_backup_run_batch.sql +8 -0
- package/dist/server/migrations/0120_domain_primary_unique.sql +24 -0
- package/dist/server/migrations/0121_host_port_claim_overlap.sql +14 -0
- package/dist/server/migrations/0122_data_transfer_staging.sql +45 -0
- package/dist/server/migrations/0123_drop_cloud_infra.sql +7 -0
- package/dist/server/migrations/0124_mail_dmarc_report.sql +23 -0
- package/dist/server/migrations/0125_server_security_snapshot.sql +22 -0
- package/dist/server/migrations/meta/0000_snapshot.json +4848 -0
- package/dist/server/migrations/meta/0001_snapshot.json +4991 -0
- package/dist/server/migrations/meta/0002_snapshot.json +5013 -0
- package/dist/server/migrations/meta/0003_snapshot.json +5020 -0
- package/dist/server/migrations/meta/0004_snapshot.json +5020 -0
- package/dist/server/migrations/meta/0005_snapshot.json +5039 -0
- package/dist/server/migrations/meta/0006_snapshot.json +5045 -0
- package/dist/server/migrations/meta/0007_snapshot.json +5057 -0
- package/dist/server/migrations/meta/0016_snapshot.json +6053 -0
- package/dist/server/migrations/meta/0017_snapshot.json +6091 -0
- package/dist/server/migrations/meta/0018_snapshot.json +6098 -0
- package/dist/server/migrations/meta/0019_snapshot.json +6098 -0
- package/dist/server/migrations/meta/0020_snapshot.json +6201 -0
- package/dist/server/migrations/meta/0021_snapshot.json +6213 -0
- package/dist/server/migrations/meta/0022_snapshot.json +6213 -0
- package/dist/server/migrations/meta/0023_snapshot.json +6331 -0
- package/dist/server/migrations/meta/0024_snapshot.json +6343 -0
- package/dist/server/migrations/meta/0025_snapshot.json +6350 -0
- package/dist/server/migrations/meta/0026_snapshot.json +6440 -0
- package/dist/server/migrations/meta/0027_snapshot.json +6447 -0
- package/dist/server/migrations/meta/0028_snapshot.json +6581 -0
- package/dist/server/migrations/meta/0029_snapshot.json +6710 -0
- package/dist/server/migrations/meta/0030_snapshot.json +6748 -0
- package/dist/server/migrations/meta/0031_snapshot.json +6859 -0
- package/dist/server/migrations/meta/0032_snapshot.json +7222 -0
- package/dist/server/migrations/meta/0033_snapshot.json +7249 -0
- package/dist/server/migrations/meta/0034_snapshot.json +7255 -0
- package/dist/server/migrations/meta/0035_snapshot.json +7262 -0
- package/dist/server/migrations/meta/0036_snapshot.json +7392 -0
- package/dist/server/migrations/meta/0037_snapshot.json +7602 -0
- package/dist/server/migrations/meta/0038_snapshot.json +7609 -0
- package/dist/server/migrations/meta/0039_snapshot.json +7714 -0
- package/dist/server/migrations/meta/0040_snapshot.json +7820 -0
- package/dist/server/migrations/meta/0041_snapshot.json +7833 -0
- package/dist/server/migrations/meta/0042_snapshot.json +7839 -0
- package/dist/server/migrations/meta/0043_snapshot.json +7938 -0
- package/dist/server/migrations/meta/0044_snapshot.json +7982 -0
- package/dist/server/migrations/meta/0045_snapshot.json +7989 -0
- package/dist/server/migrations/meta/0046_snapshot.json +8263 -0
- package/dist/server/migrations/meta/0047_snapshot.json +8275 -0
- package/dist/server/migrations/meta/0048_snapshot.json +8289 -0
- package/dist/server/migrations/meta/0049_snapshot.json +8308 -0
- package/dist/server/migrations/meta/0050_snapshot.json +8314 -0
- package/dist/server/migrations/meta/0051_snapshot.json +8460 -0
- package/dist/server/migrations/meta/0052_snapshot.json +8472 -0
- package/dist/server/migrations/meta/0053_snapshot.json +8556 -0
- package/dist/server/migrations/meta/0054_snapshot.json +8586 -0
- package/dist/server/migrations/meta/0055_snapshot.json +8756 -0
- package/dist/server/migrations/meta/0056_snapshot.json +8777 -0
- package/dist/server/migrations/meta/0057_snapshot.json +8904 -0
- package/dist/server/migrations/meta/0058_snapshot.json +8911 -0
- package/dist/server/migrations/meta/0059_snapshot.json +9061 -0
- package/dist/server/migrations/meta/0060_snapshot.json +9081 -0
- package/dist/server/migrations/meta/_journal.json +888 -0
- package/dist/server/pglite/pglite.data +0 -0
- package/dist/server/pglite/pglite.wasm +0 -0
- package/dist/setup-JWKZIECM.js +25 -0
- package/dist/signin-3M3UPB6K.js +667 -0
- package/dist/ssh-client-NWQVRCV7.js +29 -0
- package/dist/sso-oidc-3VDIYOEJ.js +834 -0
- package/dist/sts-B3WIYLXR.js +1426 -0
- package/dist/up-P5DMQ5YO.js +55 -0
- package/package.json +58 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
-- pipe_stream.lua
|
|
2
|
+
-- content_by_lua: SSE endpoint for real-time request log streaming.
|
|
3
|
+
-- GET /logs/stream?domain=example.com
|
|
4
|
+
-- Internal only - 127.0.0.1:9145
|
|
5
|
+
--
|
|
6
|
+
-- Reads the SAME ring buffer site_logger.lua writes (rlog:{domain}:seq +
|
|
7
|
+
-- rlog:{domain}:{slot}), by a PER-CONNECTION cursor. Nothing is consumed: N
|
|
8
|
+
-- concurrent watchers each walk the ring independently and none steals another's
|
|
9
|
+
-- frames. This is what replaced the old single-subscriber log_pipe:q queue —
|
|
10
|
+
-- a containerized edge tails this over `docker exec curl`, and a curl that
|
|
11
|
+
-- outlives its client (the daemon buffers its stdout, so no EPIPE) can no longer
|
|
12
|
+
-- drain the queue out from under the next reader.
|
|
13
|
+
|
|
14
|
+
local sh = ngx.shared.request_data
|
|
15
|
+
if not sh then
|
|
16
|
+
ngx.status = 503
|
|
17
|
+
ngx.say("shared dict unavailable")
|
|
18
|
+
return ngx.exit(503)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
local domain = ngx.var.arg_domain
|
|
22
|
+
if not domain or domain == "" then
|
|
23
|
+
ngx.status = 400
|
|
24
|
+
ngx.say("missing ?domain= parameter")
|
|
25
|
+
return ngx.exit(400)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
domain = domain:lower()
|
|
29
|
+
if domain:sub(1, 4) == "www." then domain = domain:sub(5) end
|
|
30
|
+
|
|
31
|
+
-- MUST match site_logger.lua's RING — same slot arithmetic on both ends.
|
|
32
|
+
local RING = 1000
|
|
33
|
+
local SEQ_KEY = "rlog:" .. domain .. ":seq"
|
|
34
|
+
local slot_key = function(seq) return "rlog:" .. domain .. ":" .. (seq % RING) end
|
|
35
|
+
|
|
36
|
+
ngx.header["Content-Type"] = "text/event-stream"
|
|
37
|
+
ngx.header["Cache-Control"] = "no-cache, no-store"
|
|
38
|
+
ngx.header["Connection"] = "keep-alive"
|
|
39
|
+
ngx.header["X-Accel-Buffering"] = "no"
|
|
40
|
+
|
|
41
|
+
-- Send initial SSE comment so the first flush has data.
|
|
42
|
+
-- Without this, ngx.flush on an empty buffer sends chunked-EOF (0\r\n\r\n)
|
|
43
|
+
-- and terminates the response immediately.
|
|
44
|
+
ngx.print(": connected\n\n")
|
|
45
|
+
if not ngx.flush(true) then return end
|
|
46
|
+
|
|
47
|
+
-- Start at the current head: stream only requests that arrive AFTER connect.
|
|
48
|
+
-- History up to this point is served separately by /logs/recent, and the client
|
|
49
|
+
-- dedups the two by the deterministic `{host}:{seq}` id, so a row seen by both
|
|
50
|
+
-- collapses to one.
|
|
51
|
+
local cursor = tonumber(sh:get(SEQ_KEY)) or 0
|
|
52
|
+
local started = ngx.now()
|
|
53
|
+
local last_hb = started
|
|
54
|
+
|
|
55
|
+
while true do
|
|
56
|
+
-- Max 1 hour per connection.
|
|
57
|
+
if ngx.now() - started > 3600 then return end
|
|
58
|
+
|
|
59
|
+
local head = tonumber(sh:get(SEQ_KEY)) or 0
|
|
60
|
+
|
|
61
|
+
-- If we've fallen more than a full ring behind, the oldest unread slots have
|
|
62
|
+
-- already been overwritten. Jump to the oldest slot still holding its own
|
|
63
|
+
-- entry (head-RING maps to head's slot, so head-RING+1 is the oldest live one)
|
|
64
|
+
-- and skip the lost range — same bound the old 2000-entry queue had.
|
|
65
|
+
if cursor < head - RING then cursor = head - RING end
|
|
66
|
+
|
|
67
|
+
local sent = 0
|
|
68
|
+
while cursor < head and sent < 100 do
|
|
69
|
+
local next_seq = cursor + 1
|
|
70
|
+
local entry = sh:get(slot_key(next_seq))
|
|
71
|
+
if entry then
|
|
72
|
+
ngx.print("event: request\ndata: ", entry, "\n\n")
|
|
73
|
+
sent = sent + 1
|
|
74
|
+
cursor = next_seq
|
|
75
|
+
elseif next_seq < head then
|
|
76
|
+
-- A later seq already exists, so this can't be the incr(seq)→set(slot)
|
|
77
|
+
-- write window: the slot is genuinely lost (expired or wrapped). Skip it.
|
|
78
|
+
cursor = next_seq
|
|
79
|
+
else
|
|
80
|
+
-- next_seq == head: the newest entry's slot may not be written yet
|
|
81
|
+
-- (the microsecond window between incr(seq) and set(slot)). Retry it
|
|
82
|
+
-- next cycle without advancing.
|
|
83
|
+
break
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
if sent > 0 then
|
|
88
|
+
if not ngx.flush(true) then return end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
local now = ngx.now()
|
|
92
|
+
|
|
93
|
+
-- Heartbeat every 15s. Its flush is also how a dead client is detected: once
|
|
94
|
+
-- the reader (a `docker exec curl`) goes away and its socket closes, this
|
|
95
|
+
-- flush fails and the connection tears down here.
|
|
96
|
+
if now - last_hb > 15 then
|
|
97
|
+
ngx.print(": ping\n\n")
|
|
98
|
+
if not ngx.flush(true) then return end
|
|
99
|
+
last_hb = now
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
ngx.sleep(0.05)
|
|
103
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
-- rules_guard.lua
|
|
2
|
+
-- access_by_lua driver: enforce per-route rules (method · IP/CIDR allow-deny ·
|
|
3
|
+
-- country allow/ban · bad user-agent · hotlink · rate-limit) for the request's
|
|
4
|
+
-- host. Rules are pushed reload-free by mgmt_api `POST /rules`; the DB
|
|
5
|
+
-- `route_rule` table is the source of truth. All parsing/compiling/matching
|
|
6
|
+
-- lives in kraft.rules_lib (loaded ONCE per worker) — this file is re-run
|
|
7
|
+
-- every request so it stays minimal. See rules_lib.lua for the compiled shape.
|
|
8
|
+
--
|
|
9
|
+
-- Enforcement uses the connecting peer (ngx.var.remote_addr); front a real_ip
|
|
10
|
+
-- config if behind a trusted proxy. No user-supplied value is ever used as a
|
|
11
|
+
-- Lua pattern or written into a response header.
|
|
12
|
+
|
|
13
|
+
local rules = ngx.shared.rules
|
|
14
|
+
if not rules then return end
|
|
15
|
+
|
|
16
|
+
-- Rate-limit counters live in their OWN dict so a high-cardinality flood (a new
|
|
17
|
+
-- rl: key per source IP per second) can't LRU-evict the rulesets and silently
|
|
18
|
+
-- disable enforcement. Fall back to `rules` on a box whose config predates the
|
|
19
|
+
-- separate dict (still works, just shares the zone until the next reload).
|
|
20
|
+
local counters = ngx.shared.rl_counters or rules
|
|
21
|
+
|
|
22
|
+
local host = ngx.var.host
|
|
23
|
+
if not host then return end
|
|
24
|
+
|
|
25
|
+
local raw = rules:get(host)
|
|
26
|
+
if not raw then return end -- fast path: nothing configured for this host
|
|
27
|
+
|
|
28
|
+
local lib = require "kraft.rules_lib"
|
|
29
|
+
local entries = lib.get(host, raw)
|
|
30
|
+
local n = #entries
|
|
31
|
+
if n == 0 then return end
|
|
32
|
+
|
|
33
|
+
-- ── Longest matching pathPrefix wins ──
|
|
34
|
+
local uri = ngx.var.uri or "/"
|
|
35
|
+
local chosen, chosen_len = nil, -1
|
|
36
|
+
for i = 1, n do
|
|
37
|
+
local e = entries[i]
|
|
38
|
+
local p = e.pathPrefix
|
|
39
|
+
if p == nil or p == "" or p == "/" then
|
|
40
|
+
if chosen_len < 0 then chosen, chosen_len = e, 0 end
|
|
41
|
+
elseif uri == p or string.sub(uri, 1, #p) == p then
|
|
42
|
+
if #p > chosen_len then chosen, chosen_len = e, #p end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
if not chosen then return end
|
|
46
|
+
|
|
47
|
+
local spec = chosen.spec
|
|
48
|
+
local deny_status = spec.blockStatus or 403
|
|
49
|
+
|
|
50
|
+
local ips = ngx.var.remote_addr or "0.0.0.0"
|
|
51
|
+
local ipi = lib.ipv4_to_int(ips)
|
|
52
|
+
|
|
53
|
+
-- Country resolved at most once per request (only when a country rule exists).
|
|
54
|
+
local country_cache
|
|
55
|
+
local function country_of()
|
|
56
|
+
if country_cache == nil then
|
|
57
|
+
local ok, geo = pcall(require, "kraft.geo_country")
|
|
58
|
+
country_cache = (ok and geo and geo.get_country_code(ips)) or false
|
|
59
|
+
end
|
|
60
|
+
return country_cache or nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
-- ── 1. Access: method allow-list, IP allow/deny, country allow-list ──
|
|
64
|
+
local access = spec.access
|
|
65
|
+
if access then
|
|
66
|
+
if access.methods and not access.methods[ngx.req.get_method()] then
|
|
67
|
+
return ngx.exit(deny_status)
|
|
68
|
+
end
|
|
69
|
+
if lib.match_compiled(access.deny, ipi, ips) then return ngx.exit(deny_status) end
|
|
70
|
+
if access.allow and not lib.match_compiled(access.allow, ipi, ips) then
|
|
71
|
+
return ngx.exit(deny_status)
|
|
72
|
+
end
|
|
73
|
+
-- Allow-list: an unresolved country is not on the list → blocked (default-deny).
|
|
74
|
+
if access.allowCountries and not access.allowCountries[country_of() or ""] then
|
|
75
|
+
return ngx.exit(deny_status)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
-- ── 2. Ban: IP/CIDR, country, user-agent ──
|
|
80
|
+
local ban = spec.ban
|
|
81
|
+
if ban then
|
|
82
|
+
if lib.match_compiled(ban.ips, ipi, ips) or lib.match_compiled(ban.cidrs, ipi, ips) then
|
|
83
|
+
return ngx.exit(deny_status)
|
|
84
|
+
end
|
|
85
|
+
if ban.countries then
|
|
86
|
+
local cc = country_of()
|
|
87
|
+
-- Fail CLOSED (matches the allow-list above): if geo is unavailable we
|
|
88
|
+
-- cannot prove the client is NOT from a banned country, so block rather
|
|
89
|
+
-- than silently letting banned traffic through. A blocked host is a loud
|
|
90
|
+
-- signal to fix geo; fail-open would be a silent security hole.
|
|
91
|
+
if not cc then
|
|
92
|
+
ngx.log(ngx.WARN, "rules_guard: country ban active but geo unavailable — blocking (fail-closed)")
|
|
93
|
+
return ngx.exit(deny_status)
|
|
94
|
+
end
|
|
95
|
+
if ban.countries[cc] then return ngx.exit(deny_status) end
|
|
96
|
+
end
|
|
97
|
+
if ban.emptyUA or ban.uas then
|
|
98
|
+
local ua = ngx.var.http_user_agent
|
|
99
|
+
if ban.emptyUA and (ua == nil or ua == "") then return ngx.exit(deny_status) end
|
|
100
|
+
if ban.uas and ua and ua ~= "" then
|
|
101
|
+
local ual = string.lower(ua)
|
|
102
|
+
for i = 1, #ban.uas do
|
|
103
|
+
if string.find(ual, ban.uas[i], 1, true) then return ngx.exit(deny_status) end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
-- ── 3. Hotlink: only listed referer hosts (empty referer per allowEmpty) ──
|
|
110
|
+
local hot = spec.hotlink
|
|
111
|
+
if hot then
|
|
112
|
+
local ref = ngx.var.http_referer
|
|
113
|
+
if ref == nil or ref == "" then
|
|
114
|
+
if not hot.allowEmpty then return ngx.exit(deny_status) end
|
|
115
|
+
else
|
|
116
|
+
local rhost = string.match(ref, "^%w+://([^/]+)") -- authority
|
|
117
|
+
if rhost then rhost = string.lower(string.match(rhost, "^([^:]+)") or rhost) end -- strip :port
|
|
118
|
+
if not (rhost and hot.referers[rhost]) then return ngx.exit(deny_status) end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
-- ── 4. Rate limit — fixed 1s window per (host, path, ip) ──
|
|
123
|
+
local rl = spec.rl
|
|
124
|
+
if rl then
|
|
125
|
+
local key = "rl:" .. host .. ":" .. (chosen.pathPrefix or "/") .. ":" .. ips
|
|
126
|
+
.. ":" .. math.floor(ngx.now())
|
|
127
|
+
local c = counters:incr(key, 1, 0, 2) -- init 0, 2s TTL → self-expiring buckets
|
|
128
|
+
if c and c > rl.limit then
|
|
129
|
+
ngx.header["Retry-After"] = "1"
|
|
130
|
+
return ngx.exit(rl.status)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
-- rules_lib.lua
|
|
2
|
+
-- Per-worker helpers + parsed-rule cache for rules_guard.lua (access phase).
|
|
3
|
+
-- Loaded ONCE per worker via require("kraft.rules_lib"). The access file is
|
|
4
|
+
-- re-executed on every request, so all parsing/compiling/matching lives here to
|
|
5
|
+
-- avoid re-creating closures and re-decoding JSON on the hot path.
|
|
6
|
+
--
|
|
7
|
+
-- Shared-dict value `rules[host]` = JSON array of { pathPrefix, spec } where
|
|
8
|
+
-- spec matches @repo/core RouteRuleSpec. parse() decodes + precompiles CIDRs to
|
|
9
|
+
-- integers, lowercases UA/referer needles, and builds O(1) sets for
|
|
10
|
+
-- countries/methods ONCE; the compiled result is LRU-cached per host and reused
|
|
11
|
+
-- until the raw string changes (rule edits are rare, requests are hot).
|
|
12
|
+
--
|
|
13
|
+
-- SECURITY: nothing here turns a rule value into Lua code or a Lua pattern.
|
|
14
|
+
-- Strings are compared with `==`/set-lookups; user-agent matching is
|
|
15
|
+
-- string.find(hay, needle, 1, true) — PLAIN, never a regex.
|
|
16
|
+
|
|
17
|
+
local cjson = require "cjson.safe"
|
|
18
|
+
local lrucache = require "resty.lrucache"
|
|
19
|
+
|
|
20
|
+
local M = {}
|
|
21
|
+
|
|
22
|
+
local cache = lrucache.new(1024) -- compiled rules, per worker, ~1024 hosts
|
|
23
|
+
|
|
24
|
+
-- ── IPv4 helpers ──
|
|
25
|
+
local function ipv4_to_int(s)
|
|
26
|
+
local a, b, c, d = string.match(s, "^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
|
|
27
|
+
if not a then return nil end
|
|
28
|
+
a, b, c, d = tonumber(a), tonumber(b), tonumber(c), tonumber(d)
|
|
29
|
+
if a > 255 or b > 255 or c > 255 or d > 255 then return nil end
|
|
30
|
+
return a * 16777216 + b * 65536 + c * 256 + d
|
|
31
|
+
end
|
|
32
|
+
M.ipv4_to_int = ipv4_to_int
|
|
33
|
+
|
|
34
|
+
-- Precompile a CIDR / bare-IP string into a cheap match descriptor.
|
|
35
|
+
local function compile_cidr(s)
|
|
36
|
+
local base, bits = string.match(s, "^([^/]+)/(%d+)$")
|
|
37
|
+
if base then
|
|
38
|
+
bits = tonumber(bits)
|
|
39
|
+
local basei = ipv4_to_int(base)
|
|
40
|
+
if not basei or bits < 0 or bits > 32 then return { exact = s } end
|
|
41
|
+
if bits == 0 then return { all = true } end
|
|
42
|
+
local div = 2 ^ (32 - bits) -- compare the top `bits` bits
|
|
43
|
+
return { net = math.floor(basei / div), div = div }
|
|
44
|
+
end
|
|
45
|
+
local i = ipv4_to_int(s)
|
|
46
|
+
if i then return { ip = i } end
|
|
47
|
+
return { exact = s } -- IPv6 / unparseable → literal string compare
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
local function compile_list(list)
|
|
51
|
+
if type(list) ~= "table" then return nil end
|
|
52
|
+
local out, n = {}, 0
|
|
53
|
+
for _, s in ipairs(list) do
|
|
54
|
+
if type(s) == "string" and s ~= "" then
|
|
55
|
+
n = n + 1
|
|
56
|
+
out[n] = compile_cidr(s)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
return n > 0 and out or nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
-- Match a client (int form `ipi`, may be nil for non-IPv4; raw `ips`) against a
|
|
63
|
+
-- compiled CIDR/IP list.
|
|
64
|
+
local function match_compiled(compiled, ipi, ips)
|
|
65
|
+
if not compiled then return false end
|
|
66
|
+
for i = 1, #compiled do
|
|
67
|
+
local c = compiled[i]
|
|
68
|
+
if c.all then
|
|
69
|
+
return true
|
|
70
|
+
elseif c.ip then
|
|
71
|
+
if ipi and ipi == c.ip then return true end
|
|
72
|
+
elseif c.net then
|
|
73
|
+
if ipi and math.floor(ipi / c.div) == c.net then return true end
|
|
74
|
+
elseif c.exact == ips then
|
|
75
|
+
return true
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
return false
|
|
79
|
+
end
|
|
80
|
+
M.match_compiled = match_compiled
|
|
81
|
+
|
|
82
|
+
local function lower_list(list)
|
|
83
|
+
if type(list) ~= "table" then return nil end
|
|
84
|
+
local out, n = {}, 0
|
|
85
|
+
for _, s in ipairs(list) do
|
|
86
|
+
if type(s) == "string" and s ~= "" then
|
|
87
|
+
n = n + 1
|
|
88
|
+
out[n] = string.lower(s)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
return n > 0 and out or nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
-- Build an O(1) lookup set from a string list (optionally lowercased).
|
|
95
|
+
local function to_set(list, lower)
|
|
96
|
+
if type(list) ~= "table" then return nil end
|
|
97
|
+
local set, any = {}, false
|
|
98
|
+
for _, s in ipairs(list) do
|
|
99
|
+
if type(s) == "string" and s ~= "" then
|
|
100
|
+
set[lower and string.lower(s) or s] = true
|
|
101
|
+
any = true
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
return any and set or nil
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
-- Compile one RouteRuleSpec into a fast-match shape.
|
|
108
|
+
local function compile_spec(spec)
|
|
109
|
+
if type(spec) ~= "table" then return { blockStatus = 403 } end
|
|
110
|
+
local out = {}
|
|
111
|
+
|
|
112
|
+
local rl = spec.rateLimit
|
|
113
|
+
local rps = rl and tonumber(rl.rps)
|
|
114
|
+
if rps and rps > 0 then
|
|
115
|
+
out.rl = {
|
|
116
|
+
limit = math.floor(rps) + math.floor(tonumber(rl.burst) or 0),
|
|
117
|
+
status = tonumber(rl.status) or 429,
|
|
118
|
+
}
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
local ban = spec.ban
|
|
122
|
+
if type(ban) == "table" then
|
|
123
|
+
out.ban = {
|
|
124
|
+
ips = compile_list(ban.ips),
|
|
125
|
+
cidrs = compile_list(ban.cidrs),
|
|
126
|
+
countries = to_set(ban.countries),
|
|
127
|
+
uas = lower_list(ban.userAgents),
|
|
128
|
+
emptyUA = ban.emptyUserAgent == true,
|
|
129
|
+
}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
local acc = spec.access
|
|
133
|
+
if type(acc) == "table" then
|
|
134
|
+
out.access = {
|
|
135
|
+
allow = compile_list(acc.allowCidrs),
|
|
136
|
+
deny = compile_list(acc.denyCidrs),
|
|
137
|
+
allowCountries = to_set(acc.allowCountries),
|
|
138
|
+
methods = to_set(acc.methods),
|
|
139
|
+
}
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
local hot = spec.hotlink
|
|
143
|
+
if type(hot) == "table" then
|
|
144
|
+
local refs = to_set(hot.allowReferers, true)
|
|
145
|
+
if refs then
|
|
146
|
+
out.hotlink = { referers = refs, allowEmpty = hot.allowEmpty ~= false }
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
out.blockStatus = (type(spec.block) == "table" and tonumber(spec.block.status)) or 403
|
|
151
|
+
return out
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
local function parse(raw)
|
|
155
|
+
local entries = cjson.decode(raw)
|
|
156
|
+
if type(entries) ~= "table" then return {} end
|
|
157
|
+
local out, n = {}, 0
|
|
158
|
+
for _, e in ipairs(entries) do
|
|
159
|
+
if type(e) == "table" then
|
|
160
|
+
n = n + 1
|
|
161
|
+
out[n] = { pathPrefix = e.pathPrefix, spec = compile_spec(e.spec) }
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
return out
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
-- LRU-cached parse: reuse the compiled form until the raw dict string changes.
|
|
168
|
+
function M.get(host, raw)
|
|
169
|
+
local hit = cache:get(host)
|
|
170
|
+
if hit and hit.raw == raw then return hit.parsed end
|
|
171
|
+
local parsed = parse(raw)
|
|
172
|
+
cache:set(host, { raw = raw, parsed = parsed })
|
|
173
|
+
return parsed
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
return M
|