Wednesday, March 6, 2019

Apache SSL reverse proxy with two name virtual host




I have an Apache reverse proxy that correctly proxies an https internal server. It is configured to use a wildcard self signed certificate and to be a name-based virtual host with ServerName directive.



I am trying to add a second https internal server to proxy, I copied the configuration from the first server, changed ServerName , but it does not work: If I try to connect to the name of the second server, it always proxies me to the first.



Here is the configuration:



NameVirtualHost *:443



ServerAdmin webmaster@siteX.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP

SSLCertificateFile /etc/apache2/siteX-cert/wildcard.siteX.com.crt
SSLCertificateKeyFile /etc/apache2/siteX-cert/wildcard.siteX.com.key
SSLCACertificateFile /etc/apache2/siteX-cert/my-ca.crt

ServerName "website.siteX.com"


CustomLog "/var/log/apache2/website.siteX.com-ssl-access.log" combined
ErrorLog "/var/log/apache2/website.siteX.com-ssl-error.log"

# We're not an open proxy
ProxyRequests off

# Proxying is available for anyone

Order deny,allow
Allow from all



# The site we're proxying through
ProxyPass / https://10.3.0.16/
ProxyPassReverse / https://10.3.0.16/

# Allows the proxying of an SSL connection
SSLProxyEngine On



ServerAdmin webmaster@siteX.com

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP

SSLCertificateFile /etc/apache2/siteX-cert/wildcard.siteX.com.crt
SSLCertificateKeyFile /etc/apache2/siteX-cert/wildcard.siteX.com.key
SSLCACertificateFile /etc/apache2/siteX-cert/my-ca.crt

ServerName "website2.siteX.com"


CustomLog "/var/log/apache2/website.siteX.com-ssl-access.log" combined
ErrorLog "/var/log/apache2/website.siteX.com-ssl-error.log"

#We're not an open proxy
ProxyRequests off

# Proxying is available for anyone

Order deny,allow

Allow from all


# The site we're proxying through
ProxyPass / https://10.3.0.26/
ProxyPassReverse / https://10.3.0.26/

# Allows the proxying of an SSL connection
SSLProxyEngine On



Answer



I switched to Nginx and managed to get the two https sites working, with a quite simple configuration:



ssl_certificate  /etc/nginx/siteX-cert/wildcard.siteX.com.crt;
ssl_certificate_key /etc/nginx/siteX-cert/wildcard.siteX.com.key;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;


server {
listen 443 ssl;
server_name website.siteX.com;
ssl on;
location / {
proxy_pass https://10.3.0.16/;
}
}


server {
listen 443 ssl;
server_name website2.siteX.com;
ssl on;
location / {
proxy_pass https://10.3.0.26/;
}
}

Tuesday, March 5, 2019

email - postfix: Cannot assign requested address

I have app that uses postfix. When i send an email from one user to another, works well, as you can see here




Sep 28 14:34:04 webcat-node-77f77644-vhq94 postfix/smtpd[546]: connect
from localhost[127.0.0.1] Sep 28 14:34:04 webcat-node-77f77644-vhq94

postfix/smtpd[546]: EA382280CA4: client=localhost[127.0.0.1] Sep 28
14:34:04 webcat-node-77f77644-vhq94 postfix/cleanup[551]: EA382280CA4:
message-id=<504605561.1538145244923.JavaMail.root@webcat-node-77f77644-vhq94> Sep 28 14:34:04 webcat-node-77f77644-vhq94 postfix/qmgr[146]:
EA382280CA4: from=, size=1232, nrcpt=1 (queue
active) Sep 28 14:34:04 webcat-node-77f77644-vhq94 postfix/smtpd[546]:
disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=1 data=1
quit=1 commands=5 Sep 28 14:34:06 webcat-node-77f77644-vhq94
postfix/smtp[552]: EA382280CA4: to=,
relay=smtp.gmail.com[74.125.133.108]:587, delay=1.1,
delays=0.01/0.03/0.4/0.69, dsn=2.0.0, status=sent (250 2.0.0 OK

1538145246 h71-v6sm1532424wmg.4 - gsmtp) Sep 28 14:34:06
webcat-node-77f77644-vhq94 postfix/qmgr[146]: EA382280CA4: removed




The problem comes when someone uses the feedback feature in my app.




Sep 28 14:28:21 webcat-node-77f77644-vhq94 postfix/smtpd[531]: connect
from localhost[127.0.0.1] Sep 28 14:28:21 webcat-node-77f77644-vhq94
postfix/smtpd[531]: A0507280CA4: client=localhost[127.0.0.1] Sep 28

14:28:21 webcat-node-77f77644-vhq94 postfix/cleanup[535]: A0507280CA4:
message-id=<634841788.1538144901634.JavaMail.root@webcat-node-77f77644-vhq94> Sep 28 14:28:21 webcat-node-77f77644-vhq94 postfix/qmgr[146]:
A0507280CA4: from=, size=702, nrcpt=1 (queue active)
Sep 28 14:28:21 webcat-node-77f77644-vhq94 postfix/smtpd[531]:
disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=1 data=1
quit=1 commands=5 Sep 28 14:28:21 webcat-node-77f77644-vhq94
postfix/smtp[536]: connect to
smtp.gmail.com[2a00:1450:400c:c06::6c]:587: Cannot assign requested
address Sep 28 14:28:22 webcat-node-77f77644-vhq94 postfix/smtp[536]:
A0507280CA4: to=,

relay=smtp.gmail.com[74.125.71.108]:587, delay=1.1,
delays=0.01/0.02/0.34/0.78, dsn=2.0.0, status=sent (250 2.0.0 OK
1538144902 u4-v6sm3253917wro.47 - gsmtp) Sep 28 14:28:22
webcat-node-77f77644-vhq94 postfix/qmgr[146]: A0507280CA4: removed




This is the content of my main.cf :



smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no


append_dot_mydomain = no

readme_directory = no
compatibility_level = 2

smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = myDomain
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = gdfg, $myhostname, localhost.localdomain, localhost
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0

recipient_delimiter = +
inet_protocols = all
inet_interfaces = all
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_use_tls = yes
myorigin = /etc/mailname

How can I manage Dell H700 RAID controllers from the Linux command line?



Previous PERC controllers could all be managed/monitored by the LSI MegaCLI tools. The latest release of those tools does not appear to recognize my H700 card:



$ sudo /opt/MegaRAID/MegaCli/MegaCli64 -adpCount 


Controller Count: 0.


Are there any options aside from installing the massive OMSA suite?



-Ben


Answer



You didn't mention which "latest release" you used. I just tried this and it seems to work fine now. The Dell H700 is using this chipset:




# lspci -v | grep LSI
01:00.0 RAID bus controller: LSI Logic / Symbios Logic LSI MegaSAS 9260 (rev 05)


Visit the support section of LSI's site, the 9260 is part of the "MegaRAID Value Line". That took me to MegaRAID SAS 9260-8i, click on the "Downloads" tab from there. I downloaded "MegaCLI - Linux (MegaRAID Release 5.0)", version 8.01.06 from 28-FEB-11. Unzip the package, then install/run it like this:



# rpm -i Lib_Utils-1.00-08.noarch.rpm MegaCli-8.01.06-1.i386.rpm 
# /opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL

Adapter #0


==============================================================================
Versions
================
Product Name : PERC H700 Integrated
Serial No : 0000000
FW Package Build: 12.10.0-0025


I blanked the serial number here for privacy reasons. You might need to do a firmware upgrade to your card as well to make it compatible. I wouldn't be surprised that this didn't work when you tried it and has only been fixed since. I try to hold off buying these new controllers from Dell until as long as possible after they've been released because of issues like that.



Monday, March 4, 2019

mysql - Nginx Load Balancer Optimum Specs




I have 3 Nginx servers and each of them should handle about 2k users (concurrent connections). In front of them I have Nginx load balancer.



That's 4 Virtual machines, sharing same subnet and same physical machine. I would like to know, what VM specifications should I use for load balancer?



I have no experience with load balancing and have never done any tests, so I while I know what specs I need for my App Servers, I have no idea what should I use for nginx load balancer. Right now I'm thinking about 4 cores / 4GB RAM / 4GB HDD. What that be enough for load balancer?



Offtopic queston: Is it possible to configure mysql so that when one mysql DB is updated, so is another. Sort of like master/slave configuration or something like that?


Answer



In order to have some redundancy and avoiding single point of failure (like the droid station was in Phantom Menace) you actually should have 2 balancers and VRRP/CARP between them. So, it's 8k connections in total. The specs you are proposing will fit. I think even 2-cored CPUs will be enough.




And I see no point creating 4 VM on one physical. When this physical node will die, so will the VMs. If we talk about a VM setup, you should use at least 2 physical nodes for 4 VMs - 2 balancers and 2 backends. If you have only one machine, using it in old-fashioned server way will do the same. It's single failure point anyway.



Mysql: Yes, it's called replication.


Sunday, March 3, 2019

How can I search Domain Integrated DNS Entries




Example:




  1. I have a server named server1.domain.local

  2. I have lots of CNAME entries in various forward lookup zones pointed to server1.domain.local

  3. I want to decomission server1, and have a new server, server2, that is going to replace it.



I need to change all of my CNAMEs that point to server1.domain.local to point to server2.domain.local.




I know I can create server1.domain.local as another CNAME, but I would prefer to just find all the entries and change them individually.



How can I go about finding all references in all forward lookup zones to server.domain.local?


Answer



The dnscmd utility from the Windows Support Tools is probably your best bet. You can get a list of all the DNS zones with the command: dnscmd [servername] /EnumZones. You can enumerate all the CNAME records in each zone with the command: dnscmd [servername] /EnumRecords [zone name] . /TYPE CNAME.



In theory you could chain these two together in a script, process the output, and make the changes you want automatically (also using dnscmd with the /RecordDelete and /RecordAdd commands). That's an exercise I'll leave to you (for now).



Edit: Okay-- I couldn't resist. Here's that script. It will only echo the commands that actually make changes. If it does what you want then you can pull the echo commands out and let 'er rip.




@echo off

set SERVER_TO_REPLACE=server1.domain.com
set REPLACEMENT_VALUE=server2.domain.com

rem Quick and dirty list of Primary zones that aren't Reverse zones
for /F "usebackq" %%i in (`dnscmd %1 /EnumZones ^| find " Primary" ^| find /v " Rev"`) do call :process_zone %1 %%i
goto end

:process_zone

rem Quick and dirty enumeration of all CNAME records in a zone
for /F "usebackq tokens=1,3,4" %%i in (`dnscmd %1 /EnumRecords %2 . /TYPE CNAME ^| find " CNAME"`) do call :process_RR %1 %2 %%i %%j %%k
goto end

:process_RR
rem Check a record and alter it if necessary
if /I "%5" EQU "%SERVER_TO_REPLACE%" (
echo dnscmd %1 /RecordDelete %2 %3 %4 %5 /f
echo dnscmd %1 /RecordAdd %2 %3 %4 %REPLACEMENT_VALUE%
)


:end

Friday, March 1, 2019

centos - Can View Website on Localhost and By IP on machine but nothing from other machines



I have a centos apache2 webserver which is running and I can view the localhost website from localhost or by http://192.168.0.167 (its IP) through a browser on the machine itself, but if I try to view it by its IP on another machine through a browser on the network I can't load the website. Also pinging the machine from another machine works fine. I'm able to connect to the machine via SSH as well with no trouble.



"iptables -L" output:



Chain INPUT (policy ACCEPT)

target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Chain RH-Firewall-1-INPUT (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere icmp any
ACCEPT esp -- anywhere anywhere
ACCEPT ah -- anywhere anywhere
ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
ACCEPT udp -- anywhere anywhere udp dpt:ipp
ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED

ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Answer



In runtime:



iptables -I RH-Firewall-1-INPUT 7 -p tcp --dport 80 -j ACCEPT


startup in /etc/sysconfig/iptables


Docker returns connection error after being setup as cron job

I have a docker container on ubuntu 16.04 and I want to run a docker command periodically. After checking the command runs successfully from the command line I've setup a crontab with the following:




*/1 * * * * sudo docker run {image-name} python3 /{path-to-scrip}/script.py


This seems to work ok until the script outputs something after which point the crons don't run and it stops docker from working with the following message:



docker: Error response from daemon: connection error: desc = "transport: dial unix /var/run/docker/containerd/docke
r-containerd.sock: connect: connection refused".


I've read that stdout may be the problem and I've tried the following in crontab:




*/1 * * * * sudo docker run {image-name} python3 /{path-to-scrip}/script.py > /home/logs 2>&1


This didn't fix the problem and the logs file remains empty.



This is running on a virtual machine and restarting the instance gets me back to square one where docker runs.



I'm not the most experienced sys admin and suspect I've made a naive mistake, but I don't know how to progress this? What should I have done to setup the cron?




Additional info



I'm not sure if it's relevant, but this is running on a google cloud engine instance and the firewall is set to prohibit all external connections.



Update



After a hunch I've got it running on CentOS7, the cron job worked for a number of hours, but then the script gave an error. The error is something to be expected from the script, but this has lead to the same docker message and cron no longer works.



Further update
From this thread I decided to run docker inspect --format '{{json .State }}' {container id for failed run} - this shows the following:




    {"Status":"running","Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":8204,"ExitCode":0,"Error":"","StartedAt":"2018-01-02T03:1
5:03.016836367Z","FinishedAt":"0001-01-01T00:00:00Z"}


I guess I just need to figure out how to stop the process from running in order to shut the container down.

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...