Enable anonymous access via api/env variables in elasticsearch with xpack enabled

I want to setup my elasticsearch in such a way that it is readable by everyone (without authentication header) but write access needs authentication. Of course, I can use anonymous user, but I don't find any article showing how to setup this anonymous access with rest api/env variables (except .yml configs).

Is there any other way?