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

Add admin configuration #316

Merged
merged 1 commit into from
Jan 13, 2021
Merged

Add admin configuration #316

merged 1 commit into from
Jan 13, 2021

Conversation

ionut-arm
Copy link
Member

@ionut-arm ionut-arm commented Jan 12, 2021

This commit adds support for authenticators to identify admin
applications. The admin app names can be configured from the config.toml
file and lead to the ApplicationName having a flag set indicating
whether the app is an admin or not.

Fixes #308

@ionut-arm ionut-arm added enhancement New feature or request security Issues related to the security and privacy of the service labels Jan 12, 2021
@ionut-arm ionut-arm requested a review from hug-dev January 12, 2021 15:31
@ionut-arm ionut-arm self-assigned this Jan 12, 2021
@@ -24,7 +24,10 @@ use zeroize::Zeroize;

/// String wrapper for app names
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ApplicationName(String);
pub struct ApplicationName {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if I should just change this to Application

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this PR this is fine keeping the name to not trigger too many changes

}

impl Admin {
fn check_app_name(&self, app_name: &mut ApplicationName) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly - wasn't sure what name to give to this, but it felt better to keep the place where the actual check is done and set_admin is called contained, so it's easier to verify

@ionut-arm
Copy link
Member Author

Also, wasn't sure if I should add the checks in the backend or if you'd rather do it when implementing the operations that actually need them

Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks looks good! I agree with the general algorithm, just had some questions about method naming to maybe understand it better.

Also, wasn't sure if I should add the checks in the backend or if you'd rather do it when implementing the operations that actually need them

I guess we can do it when adding support for the first admin operations.

# WARNING: Admins have special privileges and access to operations that are not permitted for normal
# users of the service. Only enable this feature with some list of admins if you are confident
# about the need for those permissions.
# Read more here: https://parallaxsecond.github.io/parsec-book/parsec_client/operations/index.html#core-operations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

}

/// Verify if the app is an admin
fn admin_check(&self, app_name: &mut ApplicationName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer renaming this method to understand better that it modifies app_name, what about set_admin_status? And similarly for the one on Admin

let conn_metadata = None;
let status = authenticator
.authenticate(&RequestAuth::new(Vec::new()), conn_metadata)
.expect_err("Empty auth should have failed");

assert_eq!(status, ResponseStatus::AuthenticationError);
}

#[test]
fn admin_check() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests 👌

@@ -24,7 +24,10 @@ use zeroize::Zeroize;

/// String wrapper for app names
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ApplicationName(String);
pub struct ApplicationName {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this PR this is fine keeping the name to not trigger too many changes

}

/// Flag current application as being an admin
fn set_admin(&mut self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this method taking a boolean to set the field? I feel like set_admin(true) is nice to understand

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll change my approach here and just keep ApplicationName immutable, though that means I'll have to check whether a string is an admin name before calling the constructor.

AuthenticatorConfig::Direct { admins } => authenticators.push((
AuthType::Direct,
Box::from(DirectAuthenticator::new(
admins.as_ref().cloned().unwrap_or_default(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the Default yield to an empty vector?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the default for Vec

@ionut-arm ionut-arm force-pushed the admin branch 2 times, most recently from b4b40d9 to c42fdae Compare January 13, 2021 11:01
Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks better like that indeed!

Just one nitpick but feel free to ignore:

Ok(ApplicationName::new(
    app_name.clone(),
    self.admins.is_admin(&app_name),
))

could that be changed to:

let is_admin = self.admins.is_admin(&app_name);
Ok(ApplicationName::new(
    app_name,
    is_admin,
))

in order to avoid the clone?

@ionut-arm
Copy link
Member Author

Good point - was aware of the "tradeoff", but didn't think of performance, though if you do a lot of operations, it might matter

This commit adds support for authenticators to identify admin
applications. The admin app names can be configured from the config.toml
file and lead to the ApplicationName having a flag set indicating
whether the app is an admin or not.

Signed-off-by: Ionut Mihalcea <ionut.mihalcea@arm.com>
@ionut-arm ionut-arm marked this pull request as ready for review January 13, 2021 12:58
@ionut-arm ionut-arm merged commit 1e3a74a into parallaxsecond:master Jan 13, 2021
@ionut-arm ionut-arm deleted the admin branch January 13, 2021 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security Issues related to the security and privacy of the service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement admin logic
2 participants