<p>I am currently using the KubernetesPodOperator to run a Pod on a Kubernetes cluster. I am getting the below error:</p>
<blockquote>
<p>kubernetes.client.rest.ApiException: (403) Reason: Forbidden</p>
<p>HTTP response headers: HTTPHeaderDict({'Audit-Id': '',
'Cache-Control': 'no-cache, private', 'Content-Type':
'application/json', 'X-Content-Type-Options': 'nosniff', 'Date': 'Mon,
30 Aug 2021 00:12:57 GMT', 'Content-Length': '309'})</p>
<p>HTTP response body:
{&quot;kind&quot;:&quot;Status&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;metadata&quot;:{},&quot;status&quot;:&quot;Failure&quot;,&quot;message&quot;:&quot;pods
is forbidden: User
&quot;system:serviceaccount:airflow10:airflow-worker-serviceaccount&quot;
cannot list resource &quot;pods&quot; in API group &quot;&quot; in the namespace
&quot;default&quot;&quot;,&quot;reason&quot;:&quot;Forbidden&quot;,&quot;details&quot;:{&quot;kind&quot;:&quot;pods&quot;},&quot;code&quot;:403}</p>
</blockquote>
<p>I can resolve this by running the below commands:</p>
<blockquote>
<p>kubectl create clusterrole pod-creator --verb=create,get,list,watch
--resource=pods</p>
<p>kubectl create clusterrolebinding pod-creator-clusterrolebinding
--clusterrole=pod-creator --serviceaccount=airflow10:airflow-worker-serviceaccount</p>
</blockquote>
<p>But I want to be able to setup the service account with the correct permissions inside airflow automatically. What would be a good approach to do this without having to run the above commands?</p>

<p>You can't really. You need to assign and create the roles when you deploy airflow, otherwise that would mean that you have huge security risk because deployed application would be able to give more permissions.</p>
<p>This can be done in multiple ways &quot;automatically&quot; if your intention was to somewhat automate the deployment. For example if your airflow deployment is done via Helm chart, the chart can add an configure the right resources to create appropriate role bindings. You can see how our Official Helm chart does it:</p>
<ul>
<li><a href="https://github.com/apache/airflow/blob/main/chart/templates/rbac/pod-launcher-role.yaml" rel="nofollow noreferrer">https://github.com/apache/airflow/blob/main/chart/templates/rbac/pod-launcher-role.yaml</a></li>
<li><a href="https://github.com/apache/airflow/blob/main/chart/templates/rbac/pod-launcher-rolebinding.yaml" rel="nofollow noreferrer">https://github.com/apache/airflow/blob/main/chart/templates/rbac/pod-launcher-rolebinding.yaml</a></li>
</ul>
