A federal judge ruled Tuesday that an insurer is obligated to defend and indemnify a Boston contractor accused in an underlying $1.14 million lawsuit for negligently causing the collapse of a four-story brick building during renovations.