Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit access to the Admin REST API of SyncGateway

According to the documentation the Admin REST API of the SyncGateway shouldn't be exposed.

Quote:

By default, the Admin REST API runs on port 4985 (unless you change the adminInterface configuration parameter). Do not expose this port—It belongs behind your firewall. Anyone who can reach this port has free access to and control over your databases and user accounts.

This makes sense but I'm wondering how I can grant my Application Server which runs on Google AppEngine and which handles the sign-up / creation of sessions access to the API without exposing it? Is there an option to expose the Admin REST API but limit the access to a specific server sending the request or requiring a username / password combination like the GUI on the :8091 port?

Edit

Just for clarification I'm adding my comment to the question:

The app server (running on GAE) and the Couchbase server (running on DigitalOcean) are two different physical devices and thus have different IP addresses. Means: I can't change the adminInterface configuration parameter in my syncgateway_config.json to a loop-back address since a connection from my GAE Server to the Couchbase Server won't have any effect afterwards. The server would be unreachable from the outside if I'm not mistaken?!

like image 346
user3420815 Avatar asked Jan 27 '16 11:01

user3420815


People also ask

How do I manage access to my API in API gateway?

API Gateway supports multiple mechanisms for controlling and managing access to your API. The following mechanisms can be used for authentication and authorization: Resource policies let you create resource-based policies to allow or deny access to your APIs and methods from specified source IP addresses or VPC endpoints.

How can I control access to a REST API resource?

You can use the following mechanisms for performing other tasks related to access control: Cross-origin resource sharing (CORS) lets you control how your REST API responds to cross-domain resource requests. For more information, see Enabling CORS for a REST API resource .

How do I manage authentication and authorization for my API?

API Gateway supports multiple mechanisms for controlling and managing access to your API. You can use the following mechanisms for authentication and authorization: Resource policies let you create resource-based policies to allow or deny access to your APIs and methods from specified source IP addresses or VPC endpoints.

How do I track and limit access to my API?

You can use the following mechanisms for tracking and limiting the access that you have granted to authorized clients: Usage plans let you provide API keys to your customers—and then track and limit usage of your API stages and methods for each API key.


2 Answers

The usual expectation is that your database server and other servers that need admin-level access will be either on the same host, or on an internal network that's behind a firewall. In the latter case you can safely bind the admin port to the internal net. Then of course your firewall rules will allow external connections only to the Sync Gateway (SG) public port.

If you have an auth server that's on an entirely different network, things get a bit more complex.

One possibility is to use fancier options on the firewall so it can allow external access to the admin port, but only from the external auth server. A few ways I can imagine doing this are (a) hardcode only the auth server's IP address, (b) use an SSL connection with a client cert, or (c) open an SSH tunnel from the auth server to the SG server.

Another possibility is to use a distributed auth system like OAuth, which is designed to do exactly this kind of thing. So your mobile app would talk to the auth server to obtain a token, then present the token to SG, which then shows the token to the auth server to validate it. IIRC we don't have general purpose OAuth support in SG yet so you would need to write a small OAuth handler to run on the SG server that would do this work.

[Disclaimer: I'm an architect at Couchbase and have worked on Sync Gateway but I only work on Couchbase Lite these days so I'm not an expert on SG's current capabilities!]

like image 192
Jens Alfke Avatar answered Oct 16 '22 06:10

Jens Alfke


Well the new piece of info in your comments needs to be addressed. I'm not an expert in this area, but I think the assumption is that the auth service and sync gateway run on the same server. If not things get slightly more complicated, but I think it might be doable by changing the adminInterface section of your Sync Gateway configuration to be the internal IP address and port (e.g. 192.168.3.2:4985).

like image 37
borrrden Avatar answered Oct 16 '22 08:10

borrrden