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

fix bug in acl config validation #982

Merged
merged 10 commits into from
Apr 30, 2024

Conversation

snehilzs
Copy link
Contributor

This PR fixes input validation issue in access control config.

@@ -199,10 +199,24 @@ impl PolicyEnforcer {
) -> ZResult<PolicyInformation> {
let mut policy_rules: Vec<PolicyRule> = Vec::new();
for config_rule in config_rule_set {
// config validation
if config_rule.interfaces.is_empty()
Copy link
Member

Choose a reason for hiding this comment

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

It seems that with this PR the interface list becomes always required, am I correct?
If that's the case, then I believe this is not an acceptable behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for 0.11 it should be required in the rules field, since it will not make logical sense to have a rule without a subject to implement it for. For 1.0, this will be modified to have any one of : cert_name, username or interface fields present and non-empty.

Copy link
Member

Choose a reason for hiding this comment

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

Why? I could simply want to deny key_expression on any interface/operation a priori.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For that we will require explicit keywords like ALL (this lies in the territory of Groups and Roles). Equating empty list in our explicit rules to ALL is bad access control logic. For example, we already implement similar behavior for key-expressions where ALL is signified specifically using ** and not empty list.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we need some special keyword for all, IMHO, if filter filed absent it means that filter not applied for this field.
If filed interfaces absent - apply for all interfaces
If filed flows absent - apply for all flows
And for key-expressions will be better to have the same logic

Copy link
Member

Choose a reason for hiding this comment

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

I agree for interfaces and flows.
I'm still inclined to having key_exprs mandatory though...

@Mallets
Copy link
Member

Mallets commented Apr 29, 2024

@oteffahi can you help in reviewing this PR?

Copy link
Contributor

@oteffahi oteffahi left a comment

Choose a reason for hiding this comment

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

@Mallets @snehilzs I suggested some changes, apply them if you agree.
Else it LGTM.

@@ -66,7 +66,7 @@ pub(crate) fn acl_interceptor_factories(
enforcer: Arc::new(policy_enforcer),
}))
}
Err(e) => tracing::error!("Access control inizialization error: {}", e),
Err(e) => tracing::error!("Access control not enabled due to: {}", e),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since a security feature that the user wished to enable did not go through correctly, in my opinion it seems dangerous to proceed. Shouldn't we stop execution?

Suggested change
Err(e) => tracing::error!("Access control not enabled due to: {}", e),
Err(e) => panic!("Access control not enabled due to: {}", e),

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 the upper logic should decide what to do with the execution. The interceptor has the freedom to return an error here and it should do so. I wouldn't panic directly at this level.

zenoh/src/net/routing/interceptor/authorization.rs Outdated Show resolved Hide resolved
zenoh/src/net/routing/interceptor/authorization.rs Outdated Show resolved Hide resolved
zenoh/src/net/routing/interceptor/authorization.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@oteffahi oteffahi left a comment

Choose a reason for hiding this comment

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

@Mallets As you suggested, I put each list in a seperate if statement and return the aggregated error message at the end.

zenoh/src/net/routing/interceptor/authorization.rs Outdated Show resolved Hide resolved
oteffahi and others added 2 commits April 29, 2024 16:02
Co-authored-by: oteffahi <70609372+oteffahi@users.noreply.github.com>
@oteffahi
Copy link
Contributor

oteffahi commented Apr 29, 2024

@Mallets as requested, I added a way to allow empty flows and interfaces lists in ACL rules, and interpret them as "all interfaces" and "all flows" respectively.

I'd like to mention that I maintain my position regarding this change: implicit wildcards are in my opinion a bad practice for security-related features, and that we should not proceed with this change. I added warning logs to alert the user whenever these implicit wildcards are enabled. In the future it would be better to replace this with explicit wildcards that the user has to set for each list to be populated automatically, preferably in alternatively-named configuration fields for each list (i.e: all-flows: true and all-interfaces: true).

@Mallets
Copy link
Member

Mallets commented Apr 29, 2024

@Mallets as requested, I added a way to allow empty flows and interfaces lists in ACL rules, and interpret them as "all interfaces" and "all flows" respectively.

I'd like to mention that I maintain my position regarding this change: implicit wildcards are in my opinion a bad practice for security-related features, and that we should not proceed with this change. I added warning logs to alert the user whenever these implicit wildcards are enabled. In the future it would be better to replace this with explicit wildcards that the user has to set for each list to be populated automatically, preferably in alternatively-named configuration fields for each list (i.e: all-flows: true and all-interfaces: true).

There is a difference between implicit and not-specified. Here we are tackling the configuraiton-aspect of the problem and not the implementation of it. To me, interfaces are not mandatory as part of the ACL rules, especially looking at the evolution of this configuration. Let's assume we make the evolve this ACL towards a x509 certificate check. It goes without saying that the interface may be not relevant since I'd like to always apply it. If interfaces are something that make sense, then I can restrict the configuration to the specific interface. Same thing goes for the flows (egress vs ingress). Moreover, the more we add as mandatory fields to the config files, the more the config file becomes verbose, hard to debug, and more costly to transmit over the network.

@oteffahi
Copy link
Contributor

oteffahi commented Apr 30, 2024

@Mallets I changed it so the interfaces and flows lists are optional in the config file, they behave as follows:

  • If they are not provided they will be considered wildcards (apply to all).
  • If they are provided as empty: error case.

I also made it so we error out when ACL cannot be enabled (the function returns an Error which as you suggested is handled by upper logic, which was already setup to exit in case of a returned Error from interceptor factories)

@Mallets Mallets merged commit 371ca6b into eclipse-zenoh:main Apr 30, 2024
11 checks passed
@Mallets Mallets deleted the fix_bug_acl_config branch April 30, 2024 10:40
YuanYuYuan pushed a commit to ZettaScaleLabs/zenoh that referenced this pull request Apr 30, 2024
* fix bug in acl config validation

* Update ACL config error messages

* Apply suggestions from code review

Co-authored-by: oteffahi <70609372+oteffahi@users.noreply.github.com>

* Update zenoh/src/net/routing/interceptor/authorization.rs

Co-authored-by: oteffahi <70609372+oteffahi@users.noreply.github.com>

* Fix mistake in ACL config error message

* Allow empty interfaces and flows in config

* Add warning logs for implicit wildcard ACL config

* Fix linting

* Add support for undefined interfaces and flows lists

This reverts commits a2db2d7 5008e38 e204f2d.

* Error out when ACL cannot be enabled

---------

Co-authored-by: oteffahi <70609372+oteffahi@users.noreply.github.com>
Co-authored-by: Luca Cominardi <luca.cominardi@gmail.com>
Co-authored-by: Oussama Teffahi <oussama.teffahi@zettascale.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants