However what is unusual to me is that every time a phone registers with Kamailio, that is forwarded to Asterisk (as expected), yet Asterisk replies with 401 Unauthorized. Oddly enough the phone registers and can still make calls. What worries me is that as we scale to 100's of cps, this seemingly erroneous message may slow down Asterisk because it's trying to handle authentication for users which have already been authenticated by Kamailio. If this behavior is expected, then that would be good to know as well.
This is the sip debug from ASTERISK (I have replaced IP's with the names of the servers):
<--- SIP read from TCP:kamailio:41205 --->
REGISTER sip:asteriskIP:5060;transport=tcp SIP/2.0
Via: SIP/2.0/TCP kamailio;branch=z9hG4bK998f.2846e405000000000000000000000000.0
To: <sip:40081@asteriskIP>
From: <sip:40081@asteriskIP>;tag=32fda68bf54efeeb04e3edc67b53c63d-cfb0
CSeq: 10 REGISTER
Call-ID: 0005ce130bcee5c4-26538@kamailio
Max-Forwards: 70
Content-Length: 0
User-Agent: kamailio (4.3.0 (x86_64/linux))
Contact: <sip:40081@kamailio:5060>
Expires: 3600
<------------->
--- (11 headers 0 lines) ---
Sending to kamailio:5060 (no NAT)
Sending to kamailio:5060 (no NAT)
<--- Transmitting (no NAT) to kamailio:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/TCP kamailio;branch=z9hG4bK998f.2846e405000000000000000000000000.0;received= kamailio
From: <sip:40081@asteriskIP>;tag=32fda68bf54efeeb04e3edc67b53c63d-cfb0
To: <sip:40081@asteriskIP>;tag=as404bac9a
Call-ID: 0005ce130bcee5c4-26538@ kamailio
CSeq: 10 REGISTER
Server: Asterisk PBX 11.6-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="262b338e"
Content-Length: 0
<------------>
Scheduling destruction of SIP dialog '0005ce130bcee5c4-26538@ kamailio' in 32000 ms (Method: REGISTER)
Scheduling destruction of SIP dialog '0005ce130bcee5c4-26538@ kamailio' in 32000 ms (Method: REGISTER)
Really destroying SIP dialog '0005ce130bcee5c1-26536@ kamailio' Method: REGISTER