<p>Actually, I use kubernetes service accounts mostly with NodeJS, and this works fine, but I have this one service made in Go and I can't seem to make it work with service accounts (I know that the service account is correctly configured because I tested it with a pod).</p>
<p>I'm using this lib <a href="https://github.com/aws/aws-sdk-go" rel="nofollow noreferrer">https://github.com/aws/aws-sdk-go</a></p>
<p>Up till now I tried this:</p>
<pre class="lang-golang prettyprint-override"><code>  sess := session.Must(session.NewSession())

  creds := stscreds.NewCredentials(sess, os.Getenv(&quot;AWS_ROLE_ARN&quot;))

  svc := s3.New(sess, &amp;aws.Config{Credentials: creds})
</code></pre>
<p>And also this (just in case):</p>
<pre class="lang-golang prettyprint-override"><code>  region := os.Getenv(&quot;AMAZON_REGION&quot;)
  sess := session.Must(session.NewSession(&amp;aws.Config{Region: &amp;region}))

  svc := s3.New(sess)
</code></pre>
<p>for the first case I got the following error:</p>
<pre><code>AccessDenied: User: arn:aws:sts::xxxxxxxx:assumed-role/staging-worker-node/i-0xxxxxxxxx is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::xxxxxxxx:role/EKSServiceAccount-app

</code></pre>
<p>and for the second case, I got a generic permission error.</p>
<p>I read the docs and tried a few things more (that may not be relevant here), but I can't see to make it work, maybe because I don't have much experience with golang.</p>

<p>There are a few things you can try to get your Go service to work with service accounts on Kubernetes:</p>
<p>Verify that your Go service is properly configured to use the Kubernetes service account. This can be done by checking that the service account is correctly mounted as a volume in the pod definition and that the service is able to read the credentials from the volume.</p>
<p>Make sure that the AWS SDK for Go you are using (<a href="https://github.com/aws/aws-sdk-go" rel="nofollow noreferrer">https://github.com/aws/aws-sdk-go</a>) is configured to use the correct credentials. The SDK supports several methods for providing credentials, including environment variables, shared credentials file, and IAM roles.</p>
<p>You can try using the <code>k8s.io/client-go</code> library instead of the <code>AWS SDK</code> for Go, this will help you to use the Kubernetes service account to authenticate with the Kubernetes API and obtain the required credentials for the AWS SDK.</p>
<p>If you are using the Kubernetes service account to authenticate with an external service such as AWS, you may also need to configure an IAM role that allows the service account to access the necessary resources.</p>
<p>Double check that your Go service is correctly using the Kubernetes service account token and is passing it along as an authentication token to the AWS SDK.</p>
<p>You can also try to use the <code>k8s.io/client-go</code> library to get the secret and use it in your go code.</p>
