Author Topic: build up SMTP with postfix &cyrus sasl authd &authen with ldap and how to secure  (Read 8837 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2141
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
วันนี้ มีโจทย์ให้ทำ SMTP เพิ่มเติมครับ โดยให้สามารถ ใช้งาน

      - Cyrus_sasl2.1.23 + Cyrus_sasl_authd_v2.1.25 + openldap ได้

เริ่มเลยผมใช้กับ Cyrus sasl  version 2.1.23 นะครับ
เหมือนว่าลง ใช้ กับ version 2.1.25 แล้วไม่สามารถทำการ authentication ได้
เลยทดลอง downgrade cyrus_sasl ลงมาเป็น 2.1.23 ก็ใช้งานได้ครับผม

เริ่มจาก Install OS = FreeBSD 8.2 Amd 64 bit ครับ

อัฟเดท port ให้เรียบร้อยซะ
#portsnap fetch
#portsnap extract

เริ่มทำการ install postfix ผมใช้ version 2.7 ครับ เลยใช้ option "PCRE, SASL2,TLS,OPENLDAP"
#make config
#cd /usr/ports/mail/postfix27
#make install clean

ทำการลง clamav version ใหม่ล่าสุด ณ เวลานี้ clamav 0.97.4
#cd /usr/ports/security/clamav
#make install clean

ทำการลง Spam Assasin เพื่อตรวจเชค Spam ครับผม
#cd /usr/ports/japanese/p5-Mail-SpamAssassin
#make install clean

ทำการลง Amavisd-new เพื่อเป็นตัวจัดการ clamav และ spam
#cd /usr/ports/security/amavisd-new
#make install clean

ทำการลง Perl module ที่จำเป็นต้องใช้งาน

#perl -MCPAN -e shell
>install Net::LDAP
>install DBI
>install DBD::mysql

เสร็จแล้วทำการลง DBD-mysql ของ perl ครับ
#cd /usr/ports/databases/p5-DBD-mysql50
#make install clean

ทำการลง Cyrus sasl version 2.1.23 นะครับ
#cd /usr/ports/security/cyrus-sasl2
#make install clean

ทำการลง  Cyrus_sasl_saslauth เพื่อใช้ authen กับ LDAP
#cd /usr/ports/security/cyrus-sasl2-saslauthd
#make config
เลือก  openldap
#make install clean

ทำการลง openldap client เพื่อ connect openldap server
#cd /usr/ports/net/openldap24-client
choose ""fetch"" only
#make install clean

ทำการ config "main.cf" และ "master.cf" ตามแบบฉบับ อิอิ
#cd /usr/local/etc/postfix
#cp main.cf /home/golf/backup_config/main.cf_beforema_20120218
#cp master.cf /home/golf/backup_config/master.cf_beforema_20120218

Restart postfix service ซะหน่อย
#/usr/local/etc/rc.d/postfix restart


เพิ่ม config ข้างล่างนี้ไปยังไฟล์

#vi /usr/local/lib/sasl2/smtpd.conf
#cp /usr/local/lib/sasl2/smtpd.conf   /usr/lib/sasl2/smtpd.conf

###### Begin copy ########

# with this postfix use SASL to permit
# relay be sure that you use SMTP-AUTH over TLS
# /etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd
saslauthd_path: /var/run/saslauthd/mux
saslauthd_version: 2
mech_list: LOGIN


###### End copy ########

ทำการ config ให้ cyrus_saslauth ทำงานกับ ldap ตอน start service ทุกครั้ง
#cd /usr/local/etc/rc.d
#vi saslauthd

เปลี่ยนจาก

saslauthd_flags=${saslauthd_flags:-""-a pam""}  # Flags to saslauthd program

เป็น

saslauthd_flags=${saslauthd_flags:-""-a ldap -O /usr/local/etc/saslauthd.conf""}  # Flags to saslauthd program"

ทำการ restart service cyrus_saslauthd 1 รอบ
#/usr/local/etc/rc.d/saslauthd restart

เชคดูว่าเริ่มทำงานกับ ldapป่ะ
#ps auxw | grep sasl

ต้องขึ้นเป็น
root   70084  0.0  0.3 18860  3372  ??  Is   Tue01PM   0:00.00 /usr/local/sbin/saslauthd -a ldap -O /usr/local/etc/saslauthd.conf
root   70085  0.0  0.3 18860  3372  ??  I    Tue01PM   0:00.00 /usr/local/sbin/saslauthd -a ldap -O /usr/local/etc/saslauthd.conf
root   70086  0.0  0.3 18860  2932  ??  I    Tue01PM   0:00.00 /usr/local/sbin/saslauthd -a ldap -O /usr/local/etc/saslauthd.conf
root   70087  0.0  0.3 18860  2928  ??  I    Tue01PM   0:00.00 /usr/local/sbin/saslauthd -a ldap -O /usr/local/etc/saslauthd.conf
root   70088  0.0  0.3 18860  2928  ??  I    Tue01PM   0:00.00 /usr/local/sbin/saslauthd -a ldap -O /usr/local/etc/saslauthd.conf


ทำการ test authen ด้วย LDAP ผ่าน command testsaslauthd
#testsaslauthd -u golftest@xxxx.co.th -p XxXxXxX
ถ้าเจอข้อความแบบข้างล่างแสดงว่า ทำงานได้แล้ววววว
0: OK ""Success.""


สุดท้ายลองเทสผ่าน outlook แล้ว ใช้งาน Outgoing authentication email ด้วยนะครับ ก็จะใช้งานผ่าน saslauth ได้ปกติ
« Last Edit: กรกฎาคม 17, 2014, 05:05:08 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2141
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: build up SMTP with postfix , cyrus sasl authd , authen with ldap
« Reply #1 on: มีนาคม 21, 2012, 02:30:17 PM »
ถ้ามีปัญหา เกี่ยวกับการใช้งาน ก็โฟสถามไว้ได้นะครับ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2141
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: build up SMTP with postfix , cyrus sasl authd , authen with ldap
« Reply #2 on: มีนาคม 21, 2012, 02:48:59 PM »
สำหรับ cyrus_sasl version 2.1.25

จะทำให้ postfix ขึ้น error "535 5.7.8 Error: authentication failed: no mechanism available"

นี้ตลอดเลยครับ เลยต้อง downgrade ลงมาก่อน รอทาง cyrus แก้ bug ก่อน อิอิ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2141
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: build up SMTP with postfix , cyrus sasl authd , authen with ldap
« Reply #3 on: กรกฎาคม 17, 2014, 05:01:13 PM »
ในกรณีที่ใช้งาน Postfix เป็น MTA แล้วต้องการจูนนิ่งการตั้งค่าของการป้องกัน spam mail วิธีการเชค mail connection เพื่อลดจำนวนเมลสแปม
Postfix refresher - basic anti-spam features.

    reject_unknown_reverse_client_hostname - rejects the email if the IP of the sending server does not have a reverse DNS (ptr) record.
    reject_invalid_helo_hostname - rejects the email if the sending server uses invalid characters in the helo/ehlo host name.
    reject_non_fqdn_helo_hostname - rejects the email if the sending server does not use a fully qualified domain name as the helo/ehlo host name. Bad: "mxsrv-13". Good: "mxsrv-13.foo.com"
    reject_unknown_helo_hostname - rejects the email if the sending server uses a helo/ehlo host name that does not resolve to a public IP address. Bad: "mx1.foo.local". Good: "mx1.foo.local"
    reject_unknown_client_hostname - rejects the email if the IP address and host name of the sending server does not have Forward Confirmed reverse DNS (FCrDNS), sometimes called full-circle DNS.

So what is FCrDNS?
You have forward confirmed reverse DNS when a "dig" or "nslookup" command
returns results that agree with each other when looking up an IP and the resultant host name.

For example:
nslookup 209.85.220.210 returns mail-vc0-f210.google.com
nslookup mail-vc0-f210.google.com returns 209.85.220.210
So, we can be confident that 209.85.220.210 really is controlled by google.

http://www.victor-ratajczyk.com/post/2012/05/08/Google-admins-have-pudgy-fingers-postfix-FCrDNS-and-valid-helo-names.aspx
« Last Edit: กรกฎาคม 17, 2014, 05:05:20 PM by golfreeze »