Skip to content

Add Read Condition to Azure Role Assignments #1105

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 2 commits into from
Dec 23, 2024
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
4 changes: 2 additions & 2 deletions conductor/Cargo.lock

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

25 changes: 22 additions & 3 deletions conductor/src/azure/uami_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use azure_mgmt_msi::models::{
};
use futures::StreamExt;
use log::info;
use std::fmt::format;
use std::sync::Arc;

// Get credentials from workload identity
Expand Down Expand Up @@ -149,6 +150,7 @@ pub async fn create_role_assignment(
subscription_id: &str,
resource_group_prefix: &str,
storage_account_name: &str,
azure_backup_container: &str,
namespace: &str,
uami_principal_id: &str,
credentials: Arc<dyn TokenCredential>,
Expand All @@ -165,8 +167,25 @@ pub async fn create_role_assignment(
)
.await?;

// TODO(ianstanton) Set conditions for Role Assignment. These should allow for read / write
// Set conditions for Role Assignment. These should allow for read / write
// to the instance's directory in the blob
let blob_conditions = Some(format!(
"\
(
(
!(ActionMatches{{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'}})
)
OR
(
@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringEquals '{}'
AND
@Resource[Microsoft.Storage/storageAccounts/blobServices/containers/blobs:path] StringLike '{}/*'
)
)
",
azure_backup_container,
namespace
));

let storage_account_id = get_storage_account_id(
subscription_id,
Expand Down Expand Up @@ -199,8 +218,8 @@ pub async fn create_role_assignment(
principal_id: uami_principal_id.to_string(),
principal_type: Some(PrincipalType::ServicePrincipal),
description: None,
condition: None,
condition_version: None,
condition: blob_conditions,
condition_version: Some("2.0".to_string()),
created_on: None,
updated_on: None,
created_by: None,
Expand Down
2 changes: 2 additions & 0 deletions conductor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ pub async fn create_azure_storage_workload_identity_binding(
azure_resource_group_prefix: &str,
azure_region: &str,
azure_storage_account: &str,
azure_backup_container: &str,
namespace: &str,
) -> Result<String, ConductorError> {
let credentials = get_credentials().await?;
Expand All @@ -620,6 +621,7 @@ pub async fn create_azure_storage_workload_identity_binding(
azure_subscription_id,
azure_resource_group_prefix,
azure_storage_account,
azure_backup_container,
namespace,
&uami_principal_id,
credentials.clone(),
Expand Down
1 change: 1 addition & 0 deletions conductor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ async fn init_azure_storage_workload_identity(
&azure_resource_group,
&azure_region,
&azure_storage_account,
&backup_archive_bucket,
&read_msg.message.namespace,
)
.await?;
Expand Down
Loading