Scientists have shed fresh light on the mechanism used by certain types of bacteria to protect themselves against attack.