Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(facade): Do not include / use server from facade #2211

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/facade/acl_commands_def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2023, DragonflyDB authors. All rights reserved.
// See LICENSE for licensing terms.
//

#pragma once
chakaz marked this conversation as resolved.
Show resolved Hide resolved

namespace dfly::acl {
// Special flag/mask for all
constexpr uint32_t NONE = 0;
constexpr uint32_t ALL = std::numeric_limits<uint32_t>::max();
} // namespace dfly::acl
7 changes: 7 additions & 0 deletions src/facade/conn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <memory>

#include "facade/acl_commands_def.h"
#include "facade/facade_types.h"
#include "facade/reply_builder.h"

Expand Down Expand Up @@ -80,6 +81,12 @@ class ConnectionContext {
// How many async subscription sources are active: monitor and/or pubsub - at most 2.
uint8_t subscriptions;

std::string authed_username{"default"};
uint32_t acl_categories{dfly::acl::ALL};
std::vector<uint64_t> acl_commands;
// Skip ACL validation, used by internal commands and commands run on admin port
bool skip_acl_validation = false;

private:
Connection* owner_;
Protocol protocol_ = Protocol::REDIS;
Expand Down
10 changes: 4 additions & 6 deletions src/facade/dragonfly_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "facade/memcache_parser.h"
#include "facade/redis_parser.h"
#include "facade/service_interface.h"
#include "server/conn_context.h"
#include "util/fibers/proactor_base.h"

#ifdef DFLY_USE_SSL
Expand Down Expand Up @@ -239,12 +238,11 @@ void Connection::DispatchOperations::operator()(const MonitorMessage& msg) {
}

void Connection::DispatchOperations::operator()(const AclUpdateMessage& msg) {
auto* ctx = static_cast<dfly::ConnectionContext*>(self->cntx());
if (ctx) {
if (self->cntx()) {
for (size_t id = 0; id < msg.username.size(); ++id) {
if (msg.username[id] == ctx->authed_username) {
ctx->acl_categories = msg.categories[id];
ctx->acl_commands = msg.commands[id];
if (msg.username[id] == self->cntx()->authed_username) {
self->cntx()->acl_categories = msg.categories[id];
self->cntx()->acl_commands = msg.commands[id];
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/server/acl/acl_commands_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#include "absl/container/flat_hash_map.h"
#include "base/logging.h"
#include "facade/acl_commands_def.h"

namespace dfly::acl {
/* There are 21 ACL categories as of redis 7
Expand Down Expand Up @@ -65,9 +65,7 @@ enum AclCat {
JSON = 1ULL << 31
};

// Special flag/mask for all
constexpr uint32_t NONE = 0;
constexpr uint32_t ALL = std::numeric_limits<uint32_t>::max();
// See definitions for NONE and ALL in facade/acl_commands_def.h

inline const absl::flat_hash_map<std::string_view, uint32_t> CATEGORY_INDEX_TABLE{
{"KEYSPACE", KEYSPACE},
Expand Down
6 changes: 0 additions & 6 deletions src/server/conn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ class ConnectionContext : public facade::ConnectionContext {
// Reference to a FlowInfo for this connection if from a master to a replica.
FlowInfo* replication_flow;

std::string authed_username{"default"};
uint32_t acl_categories{acl::ALL};
std::vector<uint64_t> acl_commands;
// Skip ACL validation, used by internal commands and commands run on admin port
bool skip_acl_validation = false;

private:
void EnableMonitoring(bool enable) {
subscriptions++; // required to support the monitoring
Expand Down
Loading