-
Notifications
You must be signed in to change notification settings - Fork 9
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 TicketFlags class and Creds.ticket_flags attribute #43
Conversation
9634b23
to
b7957af
Compare
I'm a bit torn here, while this library does paper over some API differences that's more around some minor API/struct changes to expose the same data through a Python interface. This case is actually changing the results we get back to some more common standard. Without thinking about it too hard I'm probably against the idea for the following reasons
I'm wondering whether we should keep |
The reason I wrote it this way was to allow checking things like "does this ticket have the
I mostly chose the Heimdal version here because it is closer to the RFCs, and because it would in theory allow more than 32 flags. (The on-the-wire ASN1 structure allow more than 32 flags, but both the MIT and Heimdal APIs can return only 32 flags, and changing this would break the ABI.) But I understand the point that this might be confusing to people. Another thing is that python-gssapi also returns the raw ticket flags (in
I think I like the idea. Should I update the PR to
|
I think this might be the easiest option to me, change the existing
Makes sense to me, I would prefer that setup as well. I think as long as we document that |
fb27be2
to
429df05
Compare
I've updated the PR to do that. |
@@ -16,6 +17,24 @@ class TicketTimes(typing.NamedTuple): | |||
endtime: int | |||
renew_till: int | |||
|
|||
class TicketFlags(enum.IntFlag): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to add a docstring about this enum that links to the RFC where they are defined.
src/krb5/_creds.pyi
Outdated
@@ -25,6 +44,9 @@ class Creds: | |||
context: Krb5 context. | |||
""" | |||
|
|||
@property | |||
def addr(self) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you add this for a reason? AFAIK this isn't exposed on the actual Creds
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I thought it was exposed. Probably I added it at some point to the .pyx
file and then removed it again.
I'll remove it from the .pyi
file.
# This is to prevent python >= 3.11 from clearing unknown flags when doing: | ||
# flags = flags & ~TicketFlags.forwarded | ||
# (Under python 3.11, ~TicketFlags.forwarded will contain only known flags.) | ||
_all_flags = (1 << 32) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you share an actual scenario where this is required? When you say will contain only known flags
do you mean that unsetting the bit will clear out any values that aren't defined here or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you share an actual scenario where this is required?
This would be if the KDC sets some flag which is not known to the pykrb5 library and the application wants to see that flag.
When you say
will contain only known flags
do you mean that unsetting the bit will clear out any values that aren't defined here
Yes.
import enum
class MyFlags(enum.IntFlag):
A = 1
B = 2
print(int(MyFlags(15))) # Will print 15
print(int(MyFlags(15) & ~MyFlags.B)) # On python >= 3.11, will print 1, before 3.11 will print 13
print(int(~MyFlags.B)) # On python >= 3.11, will print 1, before then will print -3
That means without this on Python >= 3.11, a & ~TicketFlags.initial
will remove not only the initial
flag, but also all flags which are not defined in the TicketFlags
enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely surprising behaviour but if that's out of our control here :) Thanks for sharing the details.
429df05
to
4f7931b
Compare
Thanks for all your fantastic PRs for this library, please let me know if you have any more features you want to add anytime soon and I'll hold off on doing some integration testing for the next release. |
Thanks for the quick review and merging of the changes :-)
I opened one last PR #44, but other than that I'm not planning on any new features soon (the last PRs were mostly things I had in my local repository for the last 1-2 years). |
Note that this uses the heimdal definition of the ticket flags (where flag
i
is represented as1 << i
) instead of the MIT one (where flagi
is represented as1 << (31 - i)
) because this seems to make more sense to me. For MIT the values are converted when readingCreds.ticket_flags
.