# IMDSv2 Support

**URL:** https://meta.discourse.org/t/imdsv2-support/272379
**Category:** Self-hosting
**Created:** [July 21, 2023, 9:50am UTC](https://meta.discourse.org/t/imdsv2-support/272379 "2023-07-21T09:50:44Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![chocecil](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@chocecil](https://meta.discourse.org/u/chocecil)
#### Post date: [July 21, 2023, 9:50am UTC](https://meta.discourse.org/t/imdsv2-support/272379/1 "2023-07-21T09:50:44Z")

</div>

I am writing to inquire about the support of IMDSv2 through instance profiles in Discourse. We are in the process of migrating our service to use IMDSv2, as IMDSv1 is not an secure option.

We would like to understand if Discourse currently supports IMDSv2 through instance profiles and if not, what are the plans to support it in the near future. Additionally, are there any workarounds or patches available that would allow us to use IMDSv2 with Discourse?

It is important for us to ensure that our security requirements are met, and we believe that using temporary credentials through IMDSv2 is a critical aspect of that.

Desired behavior for accessing security credentials provided through the instance profile is

- An application on the instance retrieves the security credentials provided by the role from the instance metadata item `iam/security-credentials/` _role-name_.
- The application is granted the permissions for the actions and resources that we have defined for the role through the security credentials associated with the role. These security credentials are temporary and are rotated automatically. We make new credentials available at least five minutes before the expiration of the old credentials.

We have noted that there are differences between the IMDSv1 and IMDSv2 calls.

IMDSv1 call:

```plaintext
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access

```

While the IMDSv2 call requires the use of a **metadata token** , and can be made using the following commands:

```plaintext
TOKEN=`curl -X PUT "<http://169.254.169.254/latest/api/token>" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \\\\\\\\
&& curl -H "X-aws-ec2-metadata-token: $TOKEN" -v <http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access>

```

We would appreciate any information you can provide on how we can use IMDSv2 with Discourse, or if there are any workarounds or patches available.

Reference:

- IMDSv2 Migration : [Transition to using Instance Metadata Service Version 2 - Amazon Elastic Compute Cloud](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-transition-to-version-2.html)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 21, 2023, 7:01pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/3 "2023-07-21T19:01:21Z")

</div>

I’m not aware of any way that Discourse itself uses IMDS. Have you installed Discourse on AWS somehow? Are you somehow using IMDSv1 with Discourse already?

What is your use case?

---

<div class="post-metadata">

### Author: ![chocecil](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@chocecil](https://meta.discourse.org/u/chocecil)
#### Post date: [July 21, 2023, 7:47pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/5 "2023-07-21T19:47:14Z")

</div>

I found one related code.

> <https://github.com/discourse/discourse/blob/v3.1.0.beta5/spec/lib/s3_helper_spec.rb#L39>

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [July 25, 2023, 7:32pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/6 "2023-07-25T19:32:29Z")

</div>

> [@chocecil](#):
>
> I found one related code.
> 
> [discourse/spec/lib/s3\_helper\_spec.rb at v3.1.0.beta5 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/v3.1.0.beta5/spec/lib/s3_helper_spec.rb#L39)

This is in the testing spec.

Discourse uses a version of the AWS SDK (3.130.2) above the minimum required to support IMDSv2 and from what I can tell looking at the `MetadataNoToken` metric in our AWS deployments, we have no calls to IMDSv1.

From what I can tell we’re already using IMDSv2 everywhere.

---

<div class="post-metadata">

### Author: ![Hans\_Homan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hans_homan/32/262076_2.png) [@Hans\_Homan](https://meta.discourse.org/u/Hans_Homan)
#### Post date: [July 10, 2024, 7:30am UTC](https://meta.discourse.org/t/imdsv2-support/272379/7 "2024-07-10T07:30:27Z")

</div>

We started using Discourse on an AWS EC2 instance a year ago. And this week we updated our instance to only use IMDSv2, this broke our AWS S3 uploads with the error message “unable to sign request without credentials set”. We also utilise the “s3 use iam profile” setting.

The local IMDS service is used by Discourse to get credentials for doing other AWS related service API calls. This is done using Ruby aws-sdk-s3

> <https://github.com/discourse/discourse/blob/c9775d5f728b5383ea21281470a0e0032cb5e992/Gemfile.lock#L69>

---

<div class="post-metadata">

### Author: ![nskerl](https://avatars.discourse-cdn.com/v4/letter/n/13edae/32.png) [@nskerl](https://meta.discourse.org/u/nskerl)
#### Post date: [August 8, 2024, 5:36pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/8 "2024-08-08T17:36:31Z")

</div>

We are also seeing this backup issue after disabling IMDSv1 due to security reasons.

We can see the use of IMDSv1 (in 3.3.0.beta1-dev) via the MetadataNoToken metric, so we are wondering what version of Discourse switched to using v2 everywhere?

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [November 23, 2024, 7:25pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/9 "2024-11-23T19:25:21Z")

</div>

We too were bitten by this today once we changed our AWS instance to use IMDSv2 only: our users could no longer upload images to S3.

Probably relevant here: we are also using the `s3 use iam profile` option.

For now we [switched](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-existing-instances.html) it to “Optional” which basically means IMDSv1 is still enabled which isn’t the best security wise, but that made uploads work again.

---

<div class="post-metadata">

### Author: ![marco.palumbo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marco.palumbo/32/206919_2.png) [@marco.palumbo](https://meta.discourse.org/u/marco.palumbo)
#### Post date: [November 5, 2025, 3:05pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/10 "2025-11-05T15:05:01Z")

</div>

Does anyone had a solution/workaround to have Discourse work wit IMDSv2?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 13, 2025, 11:56pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/11 "2025-11-13T23:56:25Z")

</div>

We are making changes to allow/expect more configuration to be possible via the `.aws/config` file which might happen to overlap with this and make it possible.

---

<div class="post-metadata">

### Author: ![marco.palumbo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marco.palumbo/32/206919_2.png) [@marco.palumbo](https://meta.discourse.org/u/marco.palumbo)
#### Post date: [November 17, 2025, 4:20pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/15 "2025-11-17T16:20:29Z")

</div>

@supermathie the most weird thing that I cannot figure out is that I personally set up 2 discourse instances (dev/prod) that are identically configured (s3 uploads for files and backup using IAM profile) and updated to identical version ([9436f5e3d4](https://github.com/discourse/discourse/commits/9436f5e3d4cd92514844a8f9a44155a3e6ee2d17)) and when I disabled IMDSv1… in dev everything kept working as expected meanwhile in prod it doesn’t and keeps throwing something like “unable to sign request without credentials set” …quite puzzling

If you have any idea about test/check that I could do just let me know

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 17, 2025, 4:45pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/16 "2025-11-17T16:45:41Z")

</div>

@ducks identified the timeouts in the SDK for acquiring IMDS credentials are very aggressive (1 second, no retries) so it’s possible that it’s hitting that timeout.

But that’s just a guess.

If you console into prod can you do it interactively, e.g.:

```plaintext
discourse(prod)> c = Aws::S3::Client.new(region: ENV['DISCOURSE_S3_REGION'])
=> #<Aws::S3::Client>

discourse(prod)> c.list_objects_v2(bucket: ENV['DISCOURSE_S3_BUCKET']).contents.count
=> 1000

```

---

<div class="post-metadata">

### Author: ![marco.palumbo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marco.palumbo/32/206919_2.png) [@marco.palumbo](https://meta.discourse.org/u/marco.palumbo)
#### Post date: [November 24, 2025, 4:01pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/17 "2025-11-24T16:01:56Z")

</div>

I figured out what was wrong and I just have to blame myself but the issue was quite subtle.  
The problem was with “HttpPutResponseHopLimit” set to 1 that did not allowed IMDSv2 to be called from inside the container

Issuing this command I got this answer:

```plaintext
> aws ec2 describe-instances --instance-ids i-00000000000000000 --query “Reservations[0].Instances[0].MetadataOptions”`
{
“State”: “applied”,
“HttpTokens”: “optional”,
“HttpPutResponseHopLimit”: 1,
“HttpEndpoint”: “enabled”,
“HttpProtocolIpv6”: “disabled”,
“InstanceMetadataTags”: “disabled”
}

```

Adjusting the setting the correct output is

```plaintext
> aws ec2 describe-instances --instance-ids i-00000000000000000 --query “Reservations[0].Instances[0].MetadataOptions”`
{
“State”: “applied”,
“HttpTokens”: “required”,
“HttpPutResponseHopLimit”: 2,
“HttpEndpoint”: “enabled”,
“HttpProtocolIpv6”: “disabled”,
“InstanceMetadataTags”: “disabled”
}

```

…and finally the mistery is solved 😅

Thanks everyone for your help

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 24, 2025, 5:25pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/18 "2025-11-24T17:25:46Z")

</div>

This is great to know!

And hopefully this applies to others as well.

But I’m wondering why this isn’t a problem for us. We have this set to 1 and yet it works?

```plaintext
discourse(prod)> ENV['AWS_EC2_METADATA_V1_DISABLED'] = 'true'
=> "true"
discourse(prod)> c = Aws::S3::Client.new(region: ENV['DISCOURSE_S3_REGION'])
=> #<Aws::S3::Client>
discourse(prod)> c.config.credentials.disable_imds_v1
=> true
discourse(prod)> c.list_objects_v2(bucket: ENV['DISCOURSE_S3_BUCKET']).contents.count
=> 1000

```

and that instance has this metadata as per the same query command:

```plaintext
{
    "State": "applied",
    "HttpTokens": "optional",
    "HttpPutResponseHopLimit": 1,
    "HttpEndpoint": "enabled",
    "HttpProtocolIpv6": "disabled",
    "InstanceMetadataTags": "disabled"
}

```

We’re running Discourse in a docker container on EC2, same as others, so… what’s the difference?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 25, 2025, 2:00pm UTC](https://meta.discourse.org/t/imdsv2-support/272379/19 "2025-11-25T14:00:17Z")

</div>

This topic was automatically closed after 21 hours. New replies are no longer allowed.
