The effective Hamiltonian that describes magnetic exchange interaction in a topological insulator is calculated, projecting bulk contact $s$-$d$ interaction onto surface electron states. This model consistently describes the indirect exchange between magnetic atoms mediated either by massless Dirac fermions in thick films or by massive excitations in a thin slab with tunneling between opposite surfaces. It is shown that an effective $s$-$d$ exchange is sensitive to the symmetry of surface wave functions and depends on the position of an impurity spin relative to slab surfaces. Under a vertical bias the indirect exchange between localized spins is switchable between opposite surfaces, and the oscillating range function reveals zero magnetic field beating as a signature of Rashba spin splitting.