[{"data":1,"prerenderedAt":334},["ShallowReactive",2],{"articles-page-3":3},{"articles":4,"total":333},[5,90,112,138,196,228,276],{"path":6,"title":7,"description":8,"image":9,"createdAt":10,"authorKey":11,"tags":12,"codeLinks":16,"readingTime":17,"excerpt":18},"\u002Farticles\u002F20210724-mysql-federated","MySQL FEDERATED Storage Engine and Replication","Use MySQL FEDERATED storage engine to store data on a remote MySQL server that acts as a replication master.","\u002Fimages\u002Fcovers\u002Fmysql-federated.jpg","2021-07-24","philip",[13,14,15],"mysql","sysadmin","linux",null,6,{"type":19,"value":20},"minimark",[21,51,57,81],[22,23,24,25,32,33,38,39,43,44,43,47,50],"p",{},"Back in Nov 2020, it got time to rethink the MySQL replication infrastructure for ",[26,27,31],"a",{"href":28,"rel":29},"https:\u002F\u002Fmy.onlime.ch\u002F",[30],"nofollow","Airpane Controlpanel",", our customer dashboard at ",[26,34,37],{"href":35,"rel":36},"https:\u002F\u002Fwww.onlime.ch\u002F",[30],"Onlime GmbH",". The whole application runs on a separate server, but an extract of mail account information (mail account credentials, mail mappings\u002Fforwardings) needs to get replicated to our 3 mail servers (",[40,41,42],"code",{},"mailsrv",", ",[40,45,46],{},"mx1",[40,48,49],{},"mx2","). At that time, I was using MySQL MASTER-SLAVE replication for a single database in a 4-node setup (1 master + 3 slaves).",[22,52,53,54,56],{},"For security reasons, I no longer wanted any mail server to have access to the binlog of the server that hosted our controlpanel (even though I already had that limited to a single database with mailserver related data only). I also wanted to reduce complexity a bit, just using MySQL replication for the 3 mail servers and propagating ",[40,55,42],{}," to master.",[22,58,59,60,43,63,66,67,70,71,74,75,77,78,80],{},"The mailserver data is extracted from our controlpanel database by MySQL triggers (mainly ",[40,61,62],{},"AFTER INSERT",[40,64,65],{},"AFTER UPDATE",", and ",[40,68,69],{},"BEFORE DELETE"," triggers) into a separate database ",[40,72,73],{},"mailsync",". How to get whole ",[40,76,73],{}," data stored on the remote server ",[40,79,42],{}," without using MySQL replication? I didn't want to care about this on application level.",[22,82,83,84,89],{},"That's where ",[26,85,88],{"href":86,"rel":87},"https:\u002F\u002Fdev.mysql.com\u002Fdoc\u002Frefman\u002F8.0\u002Fen\u002Ffederated-storage-engine.html",[30],"MySQL FEDERATED Storage Engine"," comes into play!",{"path":91,"title":92,"description":93,"image":94,"createdAt":95,"authorKey":11,"tags":96,"codeLinks":98,"readingTime":102,"excerpt":103},"\u002Farticles\u002F20210705-mysqldump-dependent-rows","Recursively fetch dependent rows with mysqldump","Ever wondered how to fetch a row from a MySQL database recursively, going through all foreign key (FK) constraints and fetch all dependent rows as well?","\u002Fimages\u002Fcovers\u002Fdb-model-example.jpg","2021-07-05",[13,97,14],"python",[99],{"link":100,"desc":101},"https:\u002F\u002Fgist.github.com\u002Fonlime\u002F9f8ac0fe8b32349182c35eeacf9804b5","Gist",5,{"type":19,"value":104},[105],[22,106,107,108,111],{},"How to fetch a row from a MySQL database recursively, going through all foreign key (FK) constraints and fetch all dependent rows as well? That's the question that bothered me during the last 20+ years as MySQL administrator. Isn't there a standard tool like some extended ",[40,109,110],{},"mysqldump"," that comes with that power? Short answer: No, there is no such tool. I gave up searching. It's just too complex to write a general-purpose tool that works for any kind of database schema.",{"path":113,"title":114,"description":115,"image":116,"createdAt":117,"authorKey":11,"tags":118,"codeLinks":16,"readingTime":120,"excerpt":121},"\u002Farticles\u002F20210518-fail2ban-persistent-banning","Fail2ban persistent banning","Persistent IP banning using Fail2ban's recidive jail.","\u002Fimages\u002Fcovers\u002Ffail2ban.jpg","2021-05-18",[14,15,119],"security",3,{"type":19,"value":122},[123],[22,124,125,126,131,132,137],{},"If you are using ",[26,127,130],{"href":128,"rel":129},"https:\u002F\u002Fwww.fail2ban.org",[30],"Fail2ban",", there is no standard recommended way to persistently ban IPs. Some people recommend to do this outside of Fail2ban, using e.g. ",[26,133,136],{"href":134,"rel":135},"https:\u002F\u002Fpackages.debian.org\u002Fstable\u002Fiptables-persistent",[30],"iptables-persistent",", which is actually super easy to install and configure. But let's say, we don't want to install any extras and want to accomplish the same with Fail2ban, as we already have fail2ban on every single host (which is a must!).",{"path":139,"title":140,"description":141,"image":142,"createdAt":143,"authorKey":11,"tags":144,"codeLinks":16,"readingTime":147,"excerpt":148},"\u002Farticles\u002F20210416-rspamd-forwarding-spam","Block email forwarding spam with Rspamd","Apply spam filtering to outgoing email forwardings with Rspamd.","\u002Fimages\u002Fcovers\u002Fspam-fries.jpg","2021-04-16",[145,146,14],"rspamd","email",4,{"type":19,"value":149},[150,179],[22,151,152,153,156,157,159,160,162,163,165,166,168,169,174,175,178],{},"At ",[26,154,37],{"href":35,"rel":155},[30]," we have a mail infrastructure that consists of 3 mail servers: ",[40,158,46],{},"  acts as primary MX server and provides SMTP as outgoing mail gateway for our customers. ",[40,161,49],{}," acts as secondary MX and fallback incoming mailserver. Incoming email from ",[40,164,49],{}," is forwarded to ",[40,167,46],{}," which does spam\u002Fantivirus filtering with ",[26,170,173],{"href":171,"rel":172},"https:\u002F\u002Frspamd.com\u002F",[30],"Rspamd",". Finally, the 3rd mailserver which is simply called ",[40,176,177],{},"mail"," acts as IMAP server and outgoing mailserver.",[22,180,181,182,184,185,188,189,191,192,195],{},"We allow customers to set up email forwardings on their domains. A forwarding address could have another customer email address as destination, but could also directly or indirectly (through another forwarding) point to an external email address. Spam filtering is done on ",[40,183,46],{},", but Rspamd actually just flags the email as ham\u002Fspam with a spam score and adds the ",[40,186,187],{},"X-Spamd-Result"," header with all symbols. The actual action is done on the final mailserver ",[40,190,177],{}," in the recipients mailbox via Sieve rule. The reason for this is that we want to let the customer define his own spam score (going from \"minimal\" to \"radical\" which maps to a spam score treshold) and what should happen with an email that got classified as spam (store it in ",[40,193,194],{},"Spam"," box or discard it directly).",{"path":197,"title":198,"description":199,"image":200,"createdAt":201,"authorKey":11,"tags":202,"codeLinks":203,"readingTime":17,"excerpt":207},"\u002Farticles\u002F20201222-mysql-myisam-to-innodb","MySQL MyISAM to InnoDB Conversion","How to convert thousands of MySQL tables from MyISAM to InnoDB.","\u002Fimages\u002Fcovers\u002Fmysql-storage-engines.jpg","2020-12-22",[13,97,14],[204],{"link":205,"desc":206},"https:\u002F\u002Fgitlab.com\u002Fonlime\u002Fmyisam-to-innodb","onlime\u002Fmyisam-to-innodb",{"type":19,"value":208},[209],[22,210,211,212,215,216,221,222,227],{},"Back in November 2020, I managed to convert all legacy MyISAM tables to InnoDB on all ",[26,213,37],{"href":35,"rel":214},[30]," database servers and customer webservers. MyISAM as legacy storage engine was quite okay-ish on MySQL 5.7 but started to perform really bad on MySQL 8.0. There was simply no reason to keep on using it and honestly, for the last 10 years I did never understand why people still held onto it. I had to find out that a lot of my customers just never heard of any storage engine types, and they didn't even know of any differences between ",[26,217,220],{"href":218,"rel":219},"https:\u002F\u002Fdev.mysql.com\u002Fdoc\u002Frefman\u002F8.0\u002Fen\u002Fmyisam-storage-engine.html",[30],"MyISAM"," and ",[26,223,226],{"href":224,"rel":225},"https:\u002F\u002Fdev.mysql.com\u002Fdoc\u002Frefman\u002F8.0\u002Fen\u002Finnodb-storage-engine.html",[30],"InnoDB",".",{"path":229,"title":230,"description":231,"image":232,"createdAt":233,"authorKey":11,"tags":234,"codeLinks":236,"readingTime":240,"excerpt":241},"\u002Farticles\u002F20200311-rspamd-trainer-bayes","Automated Bayesian Spam\u002FHam Training with Rspamd","Automated Bayes Spam\u002FHam training with Rspamd and Dovecot \u002F IMAPSieve.","\u002Fimages\u002Fcovers\u002Frspamd.jpg","2020-03-11",[145,235,97,146,14],"dovecot",[237],{"link":238,"desc":239},"https:\u002F\u002Fgitlab.com\u002Fonlime\u002Frspamd-trainer","onlime\u002Frspamd-trainer",7,{"type":19,"value":242},[243,273],[22,244,152,245,248,249,254,255,258,259,264,265,268,269,272],{},[26,246,37],{"href":35,"rel":247},[30]," we have migrated the mail infrastructure in Dec 2019 from good old ",[26,250,253],{"href":251,"rel":252},"https:\u002F\u002Fspamassassin.apache.org\u002F",[30],"Spamassassin"," to ",[26,256,173],{"href":171,"rel":257},[30]," which greatly improved spam filtering. Rspamd offers a nice way of Bayesian learning in ",[26,260,263],{"href":261,"rel":262},"https:\u002F\u002Frspamd.com\u002Fdoc\u002Fconfiguration\u002Fstatistic.html",[30],"Rspamd statistical module",". You can feed emails through ",[40,266,267],{},"rspamc learn_spam"," or ",[40,270,271],{},"rspamc learn_ham"," for manual spam\u002Fham training to improve Bayes hit rate.",[22,274,275],{},"In the past, we have only internally used Bayesian training. Wouldn't it be nice to let all customers help us improve the Bayes filter \u002F hit rate? Without even asking them to do so?",{"path":277,"title":278,"description":279,"image":280,"createdAt":281,"authorKey":11,"tags":282,"codeLinks":16,"readingTime":240,"excerpt":284},"\u002Farticles\u002F20180806-lxc-hidepid-process-hiding","Process hiding in LXC using hidepid capabilities of procfs","Hiding processes for other users using hidepid capabilities of procfs in an LXC container.","\u002Fimages\u002Fcovers\u002Flxc-apparmor.jpg","2018-08-06",[14,15,283,119],"lxc",{"type":19,"value":285},[286,306],[22,287,288,289,293,294,297,298,301,302,305],{},"Back in 2013, I wrote about ",[26,290,292],{"href":291},"\u002Farticles\u002F20130930-hidepid-process-hiding","Linux process hiding using hidepid capabilities of procfs",". On shared webhosting servers at ",[26,295,37],{"href":35,"rel":296},[30],", I have used the ",[40,299,300],{},"hidepid=2"," mount option for procfs (",[40,303,304],{},"\u002Fproc"," filesystem) for improved security. Like this, a regular system user (which could potentially be an evil customer that has gained SSH access and tries to spy on other's processes) does only see his own processes, all other processes are hidden.",[22,307,308,309,312,313,318,319,323,324,329,330,332],{},"This is great and super simple to enable, as it is part of the official Linux kernel for quite a while now. But things start to get a little trickier when we try to set up ",[40,310,311],{},"hidepid"," procfs mount option inside an ",[26,314,317],{"href":315,"rel":316},"https:\u002F\u002Flinuxcontainers.org\u002F",[30],"LXC container",". Enabling the mount option on the host system will not do! Inside an LXC container, a regular system user is still able to see all processes. Before ",[320,321,322],"strong",{},"LXC 2.1"," (released in Sept 2017), this was also quite doable, as we just had to create a new ",[26,325,328],{"href":326,"rel":327},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FAppArmor",[30],"AppArmor"," profile on the host system to allow the LXC container to set the ",[40,331,304],{}," mount options. But since LXC 2.1 it got super tricky. I will present both solutions below, in case you have struggled with this hard one in newer LXC versions.",29,1794961390517]