Skip to content

Password auth #32131

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

Merged
merged 40 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
285f43a
Start parsing the new role options
DAlperin Mar 27, 2025
e1ac835
catalog boilerplate
DAlperin Mar 27, 2025
bb90724
Add a first pass at auth
DAlperin Apr 1, 2025
e75023d
add hashing code
DAlperin Apr 2, 2025
31f1cc3
plumb hashing through
DAlperin Apr 2, 2025
41b06eb
Increase salt size
DAlperin Apr 7, 2025
73db029
Superuser support
DAlperin Apr 7, 2025
7508711
Add a flag to enable self hosted auth in environmentd/pgwire
DAlperin Apr 8, 2025
b76e54c
Add a dyncfg for self managed auth
DAlperin Apr 8, 2025
e8478be
Add seperate config flag for internal port
DAlperin Apr 8, 2025
39260a0
Merge remote-tracking branch 'upstream/main' into dov/password-auth-s…
DAlperin Apr 8, 2025
fdf36fd
lint fixes
DAlperin Apr 8, 2025
8304edb
fix catalog-default
DAlperin Apr 8, 2025
80dff8b
remove superflous reference
DAlperin Apr 8, 2025
472967e
This is suboptimal but likely fine
DAlperin Apr 8, 2025
3ac78c2
fix clippy
DAlperin Apr 8, 2025
cb4c0df
fix a bunch of tests
DAlperin Apr 9, 2025
ea34d34
fix tests and errant comments
DAlperin Apr 9, 2025
01d9d62
rust tests for self managed auth
DAlperin Apr 9, 2025
9e6877d
Fix slt
DAlperin Apr 9, 2025
b0051bc
fix snapshot
DAlperin Apr 9, 2025
11db523
clippy
DAlperin Apr 9, 2025
e198ae9
more test failures
DAlperin Apr 9, 2025
9d63e11
Support the LOGIN/NOLOGIN attributes, and unsetting passwords
DAlperin Apr 10, 2025
26133eb
Adress comments. Fix role drop
DAlperin Apr 10, 2025
7353864
fix snapshot
DAlperin Apr 10, 2025
2df6d81
Enforce+test rbac and consistency
DAlperin Apr 10, 2025
27d6974
Use custom password type
DAlperin Apr 10, 2025
060b91a
password header + rule allows
DAlperin Apr 10, 2025
002efd7
Merge remote-tracking branch 'upstream/main' into dov/password-auth-s…
DAlperin Apr 10, 2025
df1638e
adress feedback
DAlperin Apr 10, 2025
cb235ef
switch to aws_lc_rs
DAlperin Apr 10, 2025
c2ad82c
fix snapshot
DAlperin Apr 10, 2025
d9e3656
update bazel files
DAlperin Apr 10, 2025
516c6a9
fix cargo deny
DAlperin Apr 10, 2025
2058f50
Swap out aws-lc-rs for openssl
DAlperin Apr 14, 2025
2315dd3
fix tests
DAlperin Apr 14, 2025
ffc4d59
Merge remote-tracking branch 'upstream/main' into dov/password-auth-s…
DAlperin Apr 14, 2025
dc35cac
fix clippy hopefully
DAlperin Apr 14, 2025
0e9174f
fix last few notes
DAlperin Apr 14, 2025
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
43 changes: 43 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"src/alloc-default",
"src/arrow-util",
"src/audit-log",
"src/auth",
"src/avro",
"src/aws-secrets-controller",
"src/aws-util",
Expand Down Expand Up @@ -236,6 +237,7 @@ default-members = [
"src/workspace-hack",
"test/metabase/smoketest",
"test/test-util",
"src/auth",
]

exclude = [
Expand Down
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ crates_repository(
"//:test/metabase/smoketest/Cargo.toml",
"//:test/test-util/Cargo.toml",
"//:misc/bazel/cargo-gazelle/Cargo.toml",
"//:src/auth/Cargo.toml",
],
rust_version = RUST_VERSION,
# Restricting the set of platform triples we support _greatly_ reduces the
Expand Down
8 changes: 8 additions & 0 deletions src/adapter-types/src/dyncfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ pub const ENABLE_MULTI_REPLICA_SOURCES: Config<bool> = Config::new(
"Enable multi-replica sources.",
);

/// Whether to enable self-managed authentication.
pub const ENABLE_SELF_MANAGED_AUTH: Config<bool> = Config::new(
"enable_self_managed_auth",
false,
"Enable self-managed authentication.",
);

pub const CONSTRAINT_BASED_TIMESTAMP_SELECTION: Config<&'static str> = Config::new(
"constraint_based_timestamp_selection",
ConstraintBasedTimestampSelection::const_default().as_str(),
Expand Down Expand Up @@ -148,6 +155,7 @@ pub fn all_dyncfgs(configs: ConfigSet) -> ConfigSet {
.add(&ENABLE_CONTINUAL_TASK_BUILTINS)
.add(&ENABLE_EXPRESSION_CACHE)
.add(&ENABLE_MULTI_REPLICA_SOURCES)
.add(&ENABLE_SELF_MANAGED_AUTH)
.add(&CONSTRAINT_BASED_TIMESTAMP_SELECTION)
.add(&PERSIST_FAST_PATH_ORDER)
}
6 changes: 6 additions & 0 deletions src/adapter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rust_library(
deps = [
"//src/adapter-types:mz_adapter_types",
"//src/audit-log:mz_audit_log",
"//src/auth:mz_auth",
"//src/build-info:mz_build_info",
"//src/catalog:mz_catalog",
"//src/cloud-provider:mz_cloud_provider",
Expand Down Expand Up @@ -104,6 +105,7 @@ rust_test(
deps = [
"//src/adapter-types:mz_adapter_types",
"//src/audit-log:mz_audit_log",
"//src/auth:mz_auth",
"//src/build-info:mz_build_info",
"//src/catalog:mz_catalog",
"//src/cloud-provider:mz_cloud_provider",
Expand Down Expand Up @@ -153,6 +155,7 @@ rust_doc_test(
deps = [
"//src/adapter-types:mz_adapter_types",
"//src/audit-log:mz_audit_log",
"//src/auth:mz_auth",
"//src/build-info:mz_build_info",
"//src/catalog:mz_catalog",
"//src/cloud-provider:mz_cloud_provider",
Expand Down Expand Up @@ -223,6 +226,7 @@ rust_test(
":mz_adapter",
"//src/adapter-types:mz_adapter_types",
"//src/audit-log:mz_audit_log",
"//src/auth:mz_auth",
"//src/build-info:mz_build_info",
"//src/catalog:mz_catalog",
"//src/cloud-provider:mz_cloud_provider",
Expand Down Expand Up @@ -293,6 +297,7 @@ rust_test(
":mz_adapter",
"//src/adapter-types:mz_adapter_types",
"//src/audit-log:mz_audit_log",
"//src/auth:mz_auth",
"//src/build-info:mz_build_info",
"//src/catalog:mz_catalog",
"//src/cloud-provider:mz_cloud_provider",
Expand Down Expand Up @@ -363,6 +368,7 @@ rust_test(
":mz_adapter",
"//src/adapter-types:mz_adapter_types",
"//src/audit-log:mz_audit_log",
"//src/auth:mz_auth",
"//src/build-info:mz_build_info",
"//src/catalog:mz_catalog",
"//src/cloud-provider:mz_cloud_provider",
Expand Down
1 change: 1 addition & 0 deletions src/adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ launchdarkly-server-sdk = { version = "2.5.1", default-features = false }
maplit = "1.0.2"
mz-adapter-types = { path = "../adapter-types" }
mz-audit-log = { path = "../audit-log" }
mz-auth = { path = "../auth" }
mz-build-info = { path = "../build-info" }
mz-catalog = { path = "../catalog" }
mz-cloud-provider = { path = "../cloud-provider", default-features = false }
Expand Down
6 changes: 5 additions & 1 deletion src/adapter/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use mz_catalog::expr_cache::{ExpressionCacheHandle, GlobalExpressions, LocalExpr
use mz_catalog::memory::error::{Error, ErrorKind};
use mz_catalog::memory::objects::{
CatalogCollectionEntry, CatalogEntry, CatalogItem, Cluster, ClusterReplica, Database,
NetworkPolicy, Role, Schema,
NetworkPolicy, Role, RoleAuth, Schema,
};
use mz_compute_types::dataflows::DataflowDescription;
use mz_controller::clusters::ReplicaLocation;
Expand Down Expand Up @@ -1114,6 +1114,10 @@ impl Catalog {
self.state.try_get_role_by_name(role_name)
}

pub fn try_get_role_auth_by_id(&self, id: &RoleId) -> Option<&RoleAuth> {
self.state.try_get_role_auth_by_id(id)
}

/// Creates a new schema in the `Catalog` for temporary items
/// indicated by the TEMPORARY or TEMP keywords.
pub fn create_temporary_schema(
Expand Down
29 changes: 26 additions & 3 deletions src/adapter/src/catalog/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ use mz_catalog::builtin::{
BUILTIN_LOG_LOOKUP, BUILTIN_LOOKUP, Builtin, BuiltinLog, BuiltinTable, BuiltinView,
};
use mz_catalog::durable::objects::{
ClusterKey, DatabaseKey, DurableType, ItemKey, NetworkPolicyKey, RoleKey, SchemaKey,
ClusterKey, DatabaseKey, DurableType, ItemKey, NetworkPolicyKey, RoleAuthKey, RoleKey,
SchemaKey,
};
use mz_catalog::durable::{CatalogError, SystemObjectMapping};
use mz_catalog::memory::error::{Error, ErrorKind};
use mz_catalog::memory::objects::{
CatalogEntry, CatalogItem, Cluster, ClusterReplica, DataSourceDesc, Database, Func, Index, Log,
NetworkPolicy, Role, Schema, Source, StateDiff, StateUpdate, StateUpdateKind, Table,
NetworkPolicy, Role, RoleAuth, Schema, Source, StateDiff, StateUpdate, StateUpdateKind, Table,
TableDataSource, TemporaryItem, Type, UpdateFrom,
};
use mz_compute_types::config::ComputeReplicaConfig;
Expand Down Expand Up @@ -75,6 +76,7 @@ use crate::util::index_sql;
#[derive(Debug, Clone, Default)]
struct InProgressRetractions {
roles: BTreeMap<RoleKey, Role>,
role_auths: BTreeMap<RoleAuthKey, RoleAuth>,
databases: BTreeMap<DatabaseKey, Database>,
schemas: BTreeMap<SchemaKey, Schema>,
clusters: BTreeMap<ClusterKey, Cluster>,
Expand Down Expand Up @@ -214,6 +216,9 @@ impl CatalogState {
StateUpdateKind::Role(role) => {
self.apply_role_update(role, diff, retractions);
}
StateUpdateKind::RoleAuth(role_auth) => {
self.apply_role_auth_update(role_auth, diff, retractions);
}
StateUpdateKind::Database(database) => {
self.apply_database_update(database, diff, retractions);
}
Expand Down Expand Up @@ -283,6 +288,22 @@ impl CatalogState {
Ok(())
}

#[instrument(level = "debug")]
fn apply_role_auth_update(
&mut self,
role_auth: mz_catalog::durable::RoleAuth,
diff: StateDiff,
retractions: &mut InProgressRetractions,
) {
apply_with_update(
&mut self.role_auth_by_id,
role_auth,
|role_auth| role_auth.role_id,
diff,
&mut retractions.role_auths,
);
}

#[instrument(level = "debug")]
fn apply_role_update(
&mut self,
Expand Down Expand Up @@ -1256,7 +1277,8 @@ impl CatalogState {
.pack_network_policy_update(&policy.id, diff)
.expect("could not pack audit log update"),
StateUpdateKind::StorageCollectionMetadata(_)
| StateUpdateKind::UnfinalizedShard(_) => Vec::new(),
| StateUpdateKind::UnfinalizedShard(_)
| StateUpdateKind::RoleAuth(_) => Vec::new(),
}
}

Expand Down Expand Up @@ -1814,6 +1836,7 @@ fn sort_updates_inner(updates: Vec<StateUpdate>) -> Vec<StateUpdate> {
let diff = update.diff.clone();
match update.kind {
StateUpdateKind::Role(_)
| StateUpdateKind::RoleAuth(_)
| StateUpdateKind::Database(_)
| StateUpdateKind::Schema(_)
| StateUpdateKind::DefaultPrivilege(_)
Expand Down
6 changes: 6 additions & 0 deletions src/adapter/src/catalog/consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ impl CatalogState {
}
}
}
for (role_id, _) in &self.role_auth_by_id {
if !self.roles_by_id.contains_key(role_id) {
inconsistencies.push(RoleInconsistency::RoleAuth(role_id.clone()));
}
}
for (default_priv, privileges) in self.default_privileges.iter() {
if !self.roles_by_id.contains_key(&default_priv.role_id) {
inconsistencies.push(RoleInconsistency::DefaultPrivilege(default_priv.clone()));
Expand Down Expand Up @@ -647,6 +652,7 @@ enum RoleInconsistency {
Cluster(ClusterId, RoleId),
ClusterReplica(ClusterId, ReplicaId, RoleId),
DefaultPrivilege(DefaultPrivilegeObject),
RoleAuth(RoleId),
DefaultPrivilegeItem {
grantor: RoleId,
grantee: RoleId,
Expand Down
2 changes: 2 additions & 0 deletions src/adapter/src/catalog/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl Catalog {
roles_by_name: BTreeMap::new(),
roles_by_id: BTreeMap::new(),
network_policies_by_id: BTreeMap::new(),
role_auth_by_id: BTreeMap::new(),
network_policies_by_name: BTreeMap::new(),
system_configuration,
default_privileges: DefaultPrivileges::default(),
Expand Down Expand Up @@ -266,6 +267,7 @@ impl Catalog {
for (kind, ts, diff) in updates {
match kind {
BootstrapStateUpdateKind::Role(_)
| BootstrapStateUpdateKind::RoleAuth(_)
| BootstrapStateUpdateKind::Database(_)
| BootstrapStateUpdateKind::Schema(_)
| BootstrapStateUpdateKind::DefaultPrivilege(_)
Expand Down
11 changes: 9 additions & 2 deletions src/adapter/src/catalog/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use mz_catalog::memory::error::{Error, ErrorKind};
use mz_catalog::memory::objects::{
CatalogCollectionEntry, CatalogEntry, CatalogItem, Cluster, ClusterReplica, CommentsMap,
Connection, DataSourceDesc, Database, DefaultPrivileges, Index, MaterializedView,
NetworkPolicy, Role, Schema, Secret, Sink, Source, SourceReferences, Table, TableDataSource,
Type, View,
NetworkPolicy, Role, RoleAuth, Schema, Secret, Sink, Source, SourceReferences, Table,
TableDataSource, Type, View,
};
use mz_controller::clusters::{
ManagedReplicaAvailabilityZones, ManagedReplicaLocation, ReplicaAllocation, ReplicaLocation,
Expand Down Expand Up @@ -129,6 +129,8 @@ pub struct CatalogState {
pub(super) network_policies_by_name: BTreeMap<String, NetworkPolicyId>,
#[serde(serialize_with = "mz_ore::serde::map_key_to_string")]
pub(super) network_policies_by_id: BTreeMap<NetworkPolicyId, NetworkPolicy>,
#[serde(serialize_with = "mz_ore::serde::map_key_to_string")]
pub(super) role_auth_by_id: BTreeMap<RoleId, RoleAuth>,

#[serde(skip)]
pub(super) system_configuration: SystemVars,
Expand Down Expand Up @@ -277,6 +279,7 @@ impl CatalogState {
roles_by_name: Default::default(),
roles_by_id: Default::default(),
network_policies_by_id: Default::default(),
role_auth_by_id: Default::default(),
config: CatalogConfig {
start_time: Default::default(),
start_instant: Instant::now(),
Expand Down Expand Up @@ -863,6 +866,10 @@ impl CatalogState {
.map(|id| &self.roles_by_id[id])
}

pub(super) fn try_get_role_auth_by_id(&self, id: &RoleId) -> Option<&RoleAuth> {
self.role_auth_by_id.get(id)
}

pub(super) fn try_get_network_policy_by_name(
&self,
policy_name: &str,
Expand Down
Loading