Skip to content

Commit ba1c7ab

Browse files
committed
First skeleton of opa integration
1 parent 91ab3f3 commit ba1c7ab

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

deploy/helm/superset-operator/crds/crds.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ spec:
7171
- authenticationClass
7272
type: object
7373
type: array
74+
authorization:
75+
description: 'Authorziation options for Superset. Currently only role mapping is enabled. This means if a user logs in and Opa authorization is enabled user roles got synced from opa into superset roles. Roles get created automated. Warning: This will discard all roles managed by the superset administrator.'
76+
nullable: true
77+
properties:
78+
opa:
79+
description: Configure the OPA stacklet [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) and the name of the Rego package containing your authorization rules. Consult the [OPA authorization documentation](https://docs.stackable.tech/home/nightly/concepts/opa) to learn how to deploy Rego authorization rules with OPA.
80+
nullable: true
81+
properties:
82+
configMapName:
83+
description: The [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) for the OPA stacklet that should be used for authorization requests.
84+
type: string
85+
package:
86+
description: The name of the Rego package containing the Rego rules for the product.
87+
nullable: true
88+
type: string
89+
required:
90+
- configMapName
91+
type: object
92+
type: object
7493
clusterOperation:
7594
default:
7695
reconciliationPaused: false

rust/crd/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use stackable_operator::{
88
commons::{
99
affinity::StackableAffinity,
1010
cluster_operation::ClusterOperation,
11+
opa::OpaConfig,
1112
product_image_selection::ProductImage,
1213
resources::{
1314
CpuLimitsFragment, MemoryLimitsFragment, NoRuntimeLimits, NoRuntimeLimitsFragment,
@@ -175,6 +176,13 @@ pub struct SupersetClusterConfig {
175176
#[serde(default)]
176177
pub authentication: Vec<SupersetClientAuthenticationDetails>,
177178

179+
/// Authorziation options for Superset.
180+
/// Currently only role mapping is enabled. This means if a user logs in and Opa authorization is enabled
181+
/// user roles got synced from opa into superset roles. Roles get created automated.
182+
/// Warning: This will discard all roles managed by the superset administrator.
183+
#[serde(skip_serializing_if = "Option::is_none")]
184+
pub authorization: Option<SupersetAuthorization>,
185+
178186
/// The name of the Secret object containing the admin user credentials and database connection details.
179187
/// Read the
180188
/// [getting started guide first steps](DOCS_BASE_URL_PLACEHOLDER/superset/getting_started/first_steps)
@@ -239,6 +247,12 @@ impl CurrentlySupportedListenerClasses {
239247
}
240248
}
241249

250+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
251+
#[serde(rename_all = "camelCase")]
252+
pub struct SupersetAuthorization {
253+
pub opa: Option<OpaConfig>,
254+
}
255+
242256
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
243257
#[serde(rename_all = "camelCase")]
244258
pub struct SupersetCredentials {
@@ -472,6 +486,14 @@ impl SupersetCluster {
472486
}
473487
}
474488

489+
pub fn get_opa_config(&self) -> Option<&OpaConfig> {
490+
self.spec
491+
.cluster_config
492+
.authorization
493+
.as_ref()
494+
.and_then(|a| a.opa.as_ref())
495+
}
496+
475497
/// Retrieve and merge resource configs for role and role groups
476498
pub fn merged_config(
477499
&self,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod opa;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use stackable_operator::{
2+
client::Client,
3+
commons::opa::{OpaApiVersion, OpaConfig},
4+
};
5+
use stackable_superset_crd::SupersetCluster;
6+
7+
pub struct SupersetOpaConfig {
8+
opa_role_mapping: bool,
9+
}
10+
11+
impl SupersetOpaConfig {
12+
pub async fn from_opa_config(
13+
client: &Client,
14+
superset: &SupersetCluster,
15+
opa_config: &OpaConfig,
16+
) -> Result<Self, stackable_operator::commons::opa::Error> {
17+
Ok(SupersetOpaConfig {
18+
opa_role_mapping: true,
19+
})
20+
}
21+
}

rust/operator-binary/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use stackable_superset_crd::{druidconnection::DruidConnection, SupersetCluster,
2323
use crate::druid_connection_controller::DRUID_CONNECTION_CONTROLLER_NAME;
2424
use crate::superset_controller::SUPERSET_CONTROLLER_NAME;
2525

26+
mod authorization;
2627
mod commands;
2728
mod config;
2829
mod controller_commons;

rust/operator-binary/src/superset_controller.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use stackable_superset_crd::{
7575
use strum::{EnumDiscriminants, IntoStaticStr};
7676

7777
use crate::{
78+
authorization::opa::SupersetOpaConfig,
7879
commands::add_cert_to_python_certifi_command,
7980
config::{self, PYTHON_IMPORTS},
8081
controller_commons::{self, CONFIG_VOLUME_NAME, LOG_CONFIG_VOLUME_NAME, LOG_VOLUME_NAME},
@@ -283,6 +284,10 @@ pub enum Error {
283284
InvalidSupersetCluster {
284285
source: error_boundary::InvalidObject,
285286
},
287+
#[snafu(display("invalid OpaConfig"))]
288+
InvalidOpaConfig {
289+
source: stackable_operator::commons::opa::Error,
290+
},
286291
}
287292

288293
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -371,6 +376,15 @@ pub async fn reconcile_superset(
371376
)
372377
.context(CreateClusterResourcesSnafu)?;
373378

379+
let superset_opa_config = match superset.get_opa_config() {
380+
Some(opa_config) => Some(
381+
SupersetOpaConfig::from_opa_config(client, superset, opa_config)
382+
.await
383+
.context(InvalidOpaConfigSnafu)?,
384+
),
385+
None => None,
386+
};
387+
374388
let (rbac_sa, rbac_rolebinding) = build_rbac_resources(
375389
superset,
376390
APP_NAME,

0 commit comments

Comments
 (0)