diff options
author | Jason Carey <jcarey@argv.me> | 2017-07-21 11:54:18 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2017-07-26 15:53:42 -0400 |
commit | edfe3f3b1276ef3598b1af673d088e6b5c4b3ad5 (patch) | |
tree | 08f0efcdb6100dc315cf5e9ac98c0c6261be928d /src/mongo/db/logical_session_id_helpers.h | |
parent | cb36a96d7c96cf1b24c7ef3b8b086cfc04c77642 (diff) | |
download | mongo-edfe3f3b1276ef3598b1af673d088e6b5c4b3ad5.tar.gz |
SERVER-30298 Add UserDigest LogicalSessionID
Inclusion of a sha256 digest of the full username to the logical session
id (in addition to the current guid) is necessary to fully disambiguate
logical sessions in degraded clusters (when the authoritative record for
a session is unreachable).
Semantics for the uid are as follows:
session creation via startSession()
* Sessions can only be created with one, and only one, user authenticated
* The composite key is created from a guid created on the spot, as well
as the digest of the currently auth'd username
* Only the session guid is returned to the user
* This prevents outside users from attempting to send back a value
we'd have to check. It's preferable to decorate the guid with the
user digest per command, rather than having to check a value the user
might send.
session use for a command
* Sessions are passed via the lsid top level field in any command
* Sessions are only meaningful for commands which requireAuth. For
sessions which don't require auth, we strip session information from the
command at parse time
* Session ids are passed as an object, which can optionally include the
username digest
* It is illegal to pass the username digest unless the currently
auth'd user has the impersonate privilege (the __system user does).
This enables sessions on shard servers via mongos
Diffstat (limited to 'src/mongo/db/logical_session_id_helpers.h')
-rw-r--r-- | src/mongo/db/logical_session_id_helpers.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/mongo/db/logical_session_id_helpers.h b/src/mongo/db/logical_session_id_helpers.h new file mode 100644 index 00000000000..5f1ff3c854e --- /dev/null +++ b/src/mongo/db/logical_session_id_helpers.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2017 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#pragma once + +#include "mongo/db/logical_session_id.h" + +namespace mongo { + +LogicalSessionId makeLogicalSessionId(const LogicalSessionFromClient& lsid, + OperationContext* opCtx); +LogicalSessionId makeLogicalSessionId(OperationContext* opCtx); +LogicalSessionRecord makeLogicalSessionRecord(const LogicalSessionId& lsid, Date_t lastUse); +LogicalSessionToClient makeLogicalSessionToClient(const LogicalSessionId& lsid); + +/** + * Parses the session information from the body of a request and installs it on the current + * operation context. Must only be called once per operation and should be done right in the + * beginning. + * + * Throws if the sessionId/txnNumber combination is not properly formatted. + * + * requiresAuth specifies if the command we're initializing operationSessionInfo for requires + * authorization or not. This can be determined by invoking ->requiresAuth() on the parsed command. + */ +void initializeOperationSessionInfo(OperationContext* opCtx, + const BSONObj& requestBody, + bool requiresAuth); + +} // namespace mongo |