Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB Network Access

Tags:

ravendb

I'm having a difficult time finding information on how to get RavenDB to work on a network. Within the same network, I can have an instance of my app running, and it will show data from my RavenDB. However, when I try to write data, I get a 401 Unauthorized exception.

What is the correct way to set up a RavenDB to be accessed over the network?

Right now, I have this in Raven.Server.exe.config, which is just a short-term solution:

<add key="Raven/AnonymousAccess" value="All" />

What I don't understand, is that the RavenDB web site says to use something like this:

<connectionStrings>
  <add name="RavenDb" 
       connectionString="Url=http://serverName:8080;user=user;password=password"/>
</connectionStrings>

Ok, that's great for the application that's running, but how do I set the RavenDB server to allow that user and password? Is that just the wrong way to do it (somehow setting the RavenDB config file to allow those credentials)? If that's wrong, how am I supposed to define credentials on the server side?

Edit: Here are my attempts and results:

I'm running RavenDB by double-clicking Raven.Server.exe.

Scenario 1

Client app.Config:

  <connectionStrings>
    <add name="RavenDb" connectionString="Url = http://server:8080;domain=Xx;user=Xx\user;password=pw"/>
  </connectionStrings>

DocumentStore Setup:

DocumentStore documentStore = new DocumentStore();
documentStore.ConnectionStringName = "RavenDb";
documentStore.Initialize();

Save Operation:

Session.Store(objectToSave);

Result: "The remote server returned an error: (401) Unauthorized."

Scenario 2

Client app.config:

<add key="databaseUrl" value="http://server:8080"/>

DocumentStore Setup:

string databaseUrl = ConfigurationManager.AppSettings["databaseUrl"];            
DocumentStore documentStore = new DocumentStore();
documentStore.Url = databaseUrl;
documentStore.Initialize();

Save Operation:

Session.Store(objectToSave);

Result: "The remote server returned an error: (401) Unauthorized." Inner exception: "The target principal name is incorrect"

like image 647
Bob Horn Avatar asked Dec 29 '11 19:12

Bob Horn


3 Answers

Create a local user on the machine RavenDB runs on and use any credentials you'd like. Then assign read/write permissions for the /Data directory (and the /Tenants directory if needed) to this user.

If you're running RavenDB as a service or standalone application, remote auth should work with the (windows)users credentials. If you're running on IIS, please make sure you have Windows Authentication enabled (disabled by default!).

like image 124
Daniel Lang Avatar answered Oct 10 '22 02:10

Daniel Lang


For me, I had to add domain to the connection string on the prod machine, but NOT when accessing that same machine remotely... I dunno.

Of note: I created a windows user named RAVENDB, and assigned it full permissions to the data directory.

so my connection string that worked fine remotely was

<add name="raven" connectionString="Url=http://myserver.com:8080;user=RAVENDB;password=PASS" />

whereas on the actual server, i had to use

<add name="raven" connectionString="Url=http://myserver:8080;DOMAIN=MYSERVERNAME;user=RAVENDB;password=PASS" />
like image 22
Monsters X Avatar answered Oct 10 '22 02:10

Monsters X


Bob, By default, RavenDB uses Windows authentication. So if you create the user on the server machine, it would accept it. The alternative is to define ravendb specific users, but many people just use Windows Auth.

like image 36
Ayende Rahien Avatar answered Oct 10 '22 02:10

Ayende Rahien