Skip to content

Commit

Permalink
secure-installation will remove all users except root
Browse files Browse the repository at this point in the history
  • Loading branch information
fceller committed Jun 12, 2016
1 parent 7b6ff09 commit ed01dce
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 12 deletions.
10 changes: 8 additions & 2 deletions arangod/RestServer/InitDatabaseFeature.cpp
Expand Up @@ -34,8 +34,10 @@ using namespace arangodb::application_features;
using namespace arangodb::basics;
using namespace arangodb::options;

InitDatabaseFeature::InitDatabaseFeature(ApplicationServer* server)
: ApplicationFeature(server, "InitDatabase") {
InitDatabaseFeature::InitDatabaseFeature(ApplicationServer* server,
std::vector<std::string> const& nonServerFeatures)
: ApplicationFeature(server, "InitDatabase"),
_nonServerFeatures(nonServerFeatures) {
setOptional(false);
requiresElevatedPrivileges(false);
startsAfter("Logger");
Expand All @@ -62,6 +64,10 @@ void InitDatabaseFeature::validateOptions(
std::shared_ptr<ProgramOptions> options) {
ProgramOptions::ProcessingResult const& result = options->processingResult();
_seenPassword = result.touched("database.password");

if (_initDatabase || _restoreAdmin) {
ApplicationServer::forceDisableFeatures(_nonServerFeatures);
}
}

void InitDatabaseFeature::prepare() {
Expand Down
4 changes: 3 additions & 1 deletion arangod/RestServer/InitDatabaseFeature.h
Expand Up @@ -29,7 +29,8 @@ namespace arangodb {
class InitDatabaseFeature final
: public application_features::ApplicationFeature {
public:
explicit InitDatabaseFeature(application_features::ApplicationServer* server);
InitDatabaseFeature(application_features::ApplicationServer* server,
std::vector<std::string> const& nonServerFeatures);

public:
std::string const& defaultPassword() const { return _password; }
Expand All @@ -52,6 +53,7 @@ class InitDatabaseFeature final

private:
bool _seenPassword = false;
std::vector<std::string> _nonServerFeatures;
};
}

Expand Down
2 changes: 1 addition & 1 deletion arangod/RestServer/arangod.cpp
Expand Up @@ -120,7 +120,7 @@ static int runServer(int argc, char** argv) {
server.addFeature(new FileDescriptorsFeature(&server));
server.addFeature(new FoxxQueuesFeature(&server));
server.addFeature(new FrontendFeature(&server));
server.addFeature(new InitDatabaseFeature(&server));
server.addFeature(new InitDatabaseFeature(&server, nonServerFeatures));
server.addFeature(new LanguageFeature(&server));
server.addFeature(new LogfileManager(&server));
server.addFeature(new LoggerBufferFeature(&server));
Expand Down
8 changes: 7 additions & 1 deletion etc/arangodb3/arango-init-database.conf.in
@@ -1,4 +1,10 @@
@include arangod

[server]
rest-server = false

[log]
level = error

[database]
init-database = true
init-database = true
8 changes: 7 additions & 1 deletion etc/arangodb3/arango-secure-installation.conf.in
@@ -1,4 +1,10 @@
@include arangod

[server]
rest-server = false

[log]
level = error

[database]
restore-admin = true
restore-admin = true
3 changes: 3 additions & 0 deletions etc/relative/arango-init-database.conf
Expand Up @@ -3,5 +3,8 @@
[server]
rest-server = false

[log]
level = error

[database]
init-database = true
8 changes: 7 additions & 1 deletion etc/relative/arango-secure-installation.conf
@@ -1,4 +1,10 @@
@include arangod

[server]
rest-server = false

[log]
level = error

[database]
restore-admin = true
restore-admin = true
7 changes: 2 additions & 5 deletions js/server/restore-admin-user.js
Expand Up @@ -28,12 +28,9 @@
var args = global.UPGRADE_ARGS;
delete global.UPGRADE_ARGS;

const users = require("@arangodb/users");
require("internal").db._users.truncate();

try {
users.remove("root");
} catch (e) {
}
const users = require("@arangodb/users");

users.save("root", args.password, true);
users.grantDatabase("root", "*", "rw");
Expand Down

0 comments on commit ed01dce

Please sign in to comment.