I’d say it’s probably more like some kind of checksum against the DNA. If the body detects something has been changed from what was there before it dispatches the white blood cells to kill it off. Immunosuppressants are a way to bypass the checksum, but only for some limited time. Maybe we need a way to change the checksum values altogether, but then the whole body could be rendered rejected and cease to function (death).
We always reach for the analogies that match our experience most closely. If this were 200 years ago, we'd say that the immune system was like a lock-and-key mechanism, or perhaps we'd say it was like a bank checking for correct signatures.
Indeed, I remember a kid's cartoon about our bodies when I was growing up that showed germs that had evolved the correct antigens as being spies passing through passport control with forged passports.