# Unable to restore snapshot from URL repository with basic authentication

**URL:** <https://discuss.elastic.co/t/unable-to-restore-snapshot-from-url-repository-with-basic-authentication/245628>\
**Category:** Elasticsearch\
**Created:** [August 19, 2020, 2:51pm UTC](https://discuss.elastic.co/t/unable-to-restore-snapshot-from-url-repository-with-basic-authentication/245628 "2020-08-19T14:51:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aswin\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aswin_kumar/32/74172_2.png) [@Aswin\_Kumar](https://discuss.elastic.co/u/Aswin_Kumar)\
**Post date:** [August 19, 2020, 2:51pm UTC](https://discuss.elastic.co/t/unable-to-restore-snapshot-from-url-repository-with-basic-authentication/245628/1 "2020-08-19T14:51:04Z")

</div>

## Problem:

I'm trying to create snapshot on ES instance _ES1_, and restore to another instance _ES2_. It fails to restore when the remote URL requires _basic authentication_.

ES version: 6.5.4

## Success and failure cases:

Success case: When the website exposing the _ES1_ repository folder is open to the internet (no authentication), the listing/restore works fine. For example when the repo URL is "[http://snapshots.example-server.com](http://snapshots.example-server.com)"

Failure case: When I add basic authentication to the same URL, it doesn't work. For example when the repo URL is: "http:// **username:password** @snapshots.example-server.com"

When I try to list snapshots in the URL repository with basic authentication, the error I get is:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "repository_exception",
        "reason": "[remote-repo] could not read repository data from index blob"
      }
    ],
    "type": "repository_exception",
    "reason": "[remote-repo] could not read repository data from index blob",
    "caused_by": {
      "type": "i_o_exception",
      "reason": "Server returned HTTP response code: 401 for URL: http://username:password@snapshots.example-server.com/index.latest"
    }
  },
  "status": 500
}

```

## The Setup:

**Setting up _ES1_:**

Step 1: Modify config file:

```auto
path.repo: ["/path/to/es1_repo"]

```

Step 2: Creating the repo:

```auto
PUT /_snapshot/es1_repo
{
  "type": "fs",
  "settings": {
    "location": "/path/to/es1_repo"
  }
}

```

Step 3: Making the repository path accessible from internet:  
I have setup an nginx server on the _ES1_ machine, to expose `"/path/to/es1_repo”` directory listing, let's say at: [http://snapshots.example-server.com](http://snapshots.example-server.com). It has basic authentication enabled. You could, for example, access the repo as [http://username:password@snapshots.example-server.com](http://username:password@snapshots.example-server.com) and you would see the directory listing.

Step 4: Create the snapshot:

```auto
PUT /_snapshot/es1_repo/snapshot_1?wait_for_completion=true
{
  "indices": "the_index_name",
  "ignore_unavailable": true,
  "include_global_state": false
}

```

**Setting up _ES2_:**

Step 5: Add to elastic config:

```auto
repositories.url.allowed_urls: "http://username:password@snapshots.example-server.com"

```

Step 6: Register repo

```auto
PUT _snapshot/remote-repo
{
   "type": "url",
   "settings": {
       "url": "http://username:password@snapshots.example-server.com"
   }
}

```

Step 7: Check if the snapshot is accessible:

```auto
GET _snapshot/remote-repo/_all

```

At this step the error pasted at the top appears. If I disable basic authentication, it works fine.

What could be the issue here?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 16, 2020, 2:51pm UTC](https://discuss.elastic.co/t/unable-to-restore-snapshot-from-url-repository-with-basic-authentication/245628/2 "2020-09-16T14:51:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
