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?

I just got to know, we can define anonymous user via env variables like below.

xpack.security.authc.anonymous.roles = 'some_role'
xpack.security.authc.anonymous.authz_exception = 'true'

I was not really aware of any elasticsearch.yaml/kibana.yaml configurations can be defined in env variable.

But it would be cool, if we can define new role and it's privileges here itself for assigning it to anonymous user.