Skip to content

Issue #776: Obey access levels in the server #778

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 9 commits into from
Apr 7, 2025
Merged

Conversation

danomagnum
Copy link
Contributor

This adds the necessary checks to the NodeNamespace to verify access levels before setting or returning attribute values.

A couple integration test cases were added to verify this functionality. There are already some RO/RW integration tests but they weren't picking this up.

Further changes will eventually be needed to properly support both access types - user based and overall. Right now it treats them both the same. If server authentication is ever implemented, this will have to be revisited and the user data will somehow have to be provided to the attribute get/set functions or similar.

The issue also questions what the best way to get notifications from a node change event in the server is. This was not addressed - you can achieve this today with a custom Namespace implementation or though custom value functions on your nodes. I could add a generic notification mechanism to the server that would allow you to register a callback or channel to receive notifications on, but I'm not sure yet what would be a better solution so this is left for a future change.

There was also a problem with the new DataValueFromValue function introduced in the last change to the server which switched everything from variants to datavalues that would choke in certain cases. These have been addressed. In some future breaking change, I think this function should probably be renamed to MustDataValue or similar to match equivalent functions in other parts of the code.

-- Here's what copilot has to say about it --

This pull request introduces several improvements and new features to the server codebase, focusing on dynamic data value handling, access control, and enhanced testing. Below are the most important changes:

Dynamic Data Value Handling:

  • examples/server/node_server/server.go: Updated var2 to use server.DataValueFromValue instead of ua.MustVariant for better dynamic value handling. Added new nodes (var4, var5, var6) with different access levels and data values. [1] [2]

Access Control Enhancements:

  • server/namespace_node.go: Added access checks in Attribute and SetAttribute methods to enforce read and write permissions based on access levels. [1] [2]
  • server/node.go: Introduced Access method to Node struct to check user and global access levels.

Code Refactoring:

Testing Improvements:

Miscellaneous:

These changes collectively enhance the server's functionality, security, and maintainability, while also improving test coverage.

@danomagnum danomagnum force-pushed the server_accesslevels branch from 14b0390 to bccc341 Compare March 17, 2025 03:10
@magiconair magiconair added this to the v0.7.3 milestone Mar 17, 2025
@magiconair
Copy link
Member

I thought I got rid of the go1.22 requirement for the test yesterday. Let me check again. I'll release v0.7.2 today or tomorrow with some small fixes and then we can release this change if you're comfortable with it.

@danomagnum
Copy link
Contributor Author

Sounds good to me.

@magiconair magiconair modified the milestones: v0.7.3, v0.8.0 Apr 7, 2025
@magiconair magiconair force-pushed the server_accesslevels branch from 0c39ce5 to 1b47c9f Compare April 7, 2025 11:05
@magiconair magiconair enabled auto-merge April 7, 2025 11:06
@magiconair magiconair merged commit db5fdbf into main Apr 7, 2025
5 checks passed
@magiconair magiconair deleted the server_accesslevels branch April 7, 2025 11:09
@magiconair magiconair modified the milestones: v0.7.3, v0.7.4 Apr 7, 2025
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.

2 participants