Secure localhost registry (carry of #8898)

This carries @proppy's localhost registry patch but makes one big modification: all 127.0.0.1 registries are always treated as insecure.

/cc @tiborvass 
can you rebase to make sure?