-
Notifications
You must be signed in to change notification settings - Fork 138
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
[t] Add Group with custom GID fails with type error #2807
Comments
Nice find! |
I suspect we might have some more candidates that take advantage of the run_command(cmd) or similar, where usually integers are passed instead of strings? ... Non-exhaustive list mind you: like this if there is a numeric connection name: rockstor-core/src/rockstor/system/network.py Lines 344 to 349 in 4d60a2c
possibly this: rockstor-core/src/rockstor/scripts/qgroup_maxout_limit.py Lines 53 to 57 in 4d60a2c
rockstor-core/src/rockstor/system/acl.py Lines 31 to 34 in 4d60a2c
only relevant, if a numeric domain is used (which I believe I have seen in the past, whereas the rule exists that a computer belonging to an AD domain cannot have only numerals in its name - apparently a DNS restriction): rockstor-core/src/rockstor/smart_manager/views/active_directory.py Lines 105 to 110 in 4d60a2c
and finally, we have this issue open, which likely has the same root cause: |
Looking further into the rockstor-core/src/rockstor/system/osi.py Lines 228 to 245 in 6c86e38
based on this PR: and this commit: For this specific error message, when checking the comparable rockstor-core/src/rockstor/system/users.py Lines 239 to 246 in 6c86e38
whereas in the rockstor-core/src/rockstor/system/users.py Lines 250 to 254 in 6c86e38
which would explain the above that the error occurs for a group addition, but not a user addition. It could be fixed here (probably should for consistency purposes in the group/user management), but that would leave examples like the above, where, if a numeric AD name was passed, the So, not sure, whether it's more secure to force the string conversion in the Finally, for my own education, when looking at the security consideration here: |
@Hooverdan96 Another simple reproducer for the original issue here is of course creating a custom group:
I think we should be more TYPE orientated here, and rather than force map all elements passed to run_command we should pass correct types in the first place. I.e. fix in place; rather than work around incorrect types. Maybe a type hint of sorts in run_command and fix all other code to use only the new str type as command list elements. |
sounds good to me. Pardon my ignorance, when you talk about hint, do you mean adding some comment in the code, indicating that the caller should have string only elements or are you referring to some other "hinting"? |
@Hooverdan96 Re:
My apologies, I was referencing what @FroggyFlox began within Rockstor's code, once we were a little more 'modern' on the Python version front: "type hinting", introduced in Py3.5: |
ah, ok, so you mean like this: rockstor-core/src/rockstor/system/osi.py Lines 209 to 218 in 4d60a2c
turning into something like this:
I know, probably a little overboard 😄 in the type hinting - I guess, the important one would be for the |
@Hooverdan96 yes, that was the type of thing I was thinking. But our
Not at all. Plus there is no typing on the return type! I like this extra stringency. Early Python was just too loose. Hence this more recent introduction. And besides helping with errors at run-time: i.e. wrong type being more informative, the IDE's are also informed by this and can help us by hinting that we are doing it wrong: via their being informed from the hints themselves. All good stuff. I should have taken this approach from the get-go when doing the initial Python 2 to 3 migration. But alas there was much to do and I had thought type hints were not yet available for some reason. Then saw @FroggyFlox popping them in and was much relieved to finally have them available. All our newer code, and significant code changes, should be, at least trying to use these to their fullest extend now. Take a look at my recent replication fixes, they were super helpful there as we had some major str() / byte type issues going on there from our Py2.7 days. |
Add type hints to run_command() to ensure callers are passing the expected argument types.
Ultimately "name" is from: requests here: rockstor-core/src/rockstor/storageadmin/views/network.py Lines 285 to 286 in d270ba2
So I think we are OK there. |
Likewise qgourp_ids is constructed from strings: but I'll pop in a type-hint anyway. Cheers. |
I wouldn't have though that would float ! I'll look to add some casting maybe. |
Add type hints to run_command() to ensure callers are passing the expected argument types.
Another potential inadvertent int left over from our Py2.7 to Py3.11 modifications. Create a docker net 111: fine.
After further investigation this looks like something in it's own right. I have, as a result, spun off the following issue: |
@phillxnet, interesting timing... I was just refreshing myself on that part of the code due to #2775. |
@FroggyFlox Thanks for taking a look at this. Agreed something is a drift here, and it looked a little different from my current draft pr against this issue hence the spin-off issue I've just created. Also I'm now on the home run for my current draft PR so will likely present that shortly. You may want to rebase and work on it once it's merged as there are a few hopefully useful type hint additions etc. But again, it looks like it's something a little different to what I'm currently working on. |
Add type hints to run_command() to ensure callers are passing the expected argument types and add some type hints &/or typecasts to run_command callers in: - user.py - active_directory.py - qgourp_ids list to enforce str() members only in qgroup_maxout_limit.py. - acl.py to enforce str() members of run_command() args.
…-GID-fails-with-type-error [t] Add Group with custom GID fails with type error #2807
Closing as: |
When trying to create a new User Group using a custom GID (e.g., 1001), the system will throw a syntax error. Here is the traceback:
[Edit: see also commit: https://github.com//issues/2807#issuecomment-1995226097 for another reproducer]
when leaving the field blank, i.e. allow AutoGenerate, this is not an issue. I assume, in that case the
-g
parameter is not passed and the OS assigns a new number.Note, when creating a new user with a custom GID, this error does not occur.
The text was updated successfully, but these errors were encountered: