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

PXP-10250 PXP-10268 OIDC clients expliration #1057

Merged
merged 11 commits into from
Nov 30, 2022
Merged

Conversation

paulineribeyre
Copy link
Contributor

@paulineribeyre paulineribeyre commented Nov 11, 2022

Jira Tickets: PXP-10250 and PXP-10268

Goes with uc-cdis/cloud-automation#2075

New Features

  • Add --expires-in parameter to the fence-create client-create and client-modify commands to specify the number of days in which in a client expires
  • Add the fence-create client-delete-expired command to remove expired OIDC clients and optionally post warnings in Slack

@coveralls
Copy link

coveralls commented Nov 11, 2022

Pull Request Test Coverage Report for Build 13173

  • 60 of 65 (92.31%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 74.046%

Changes Missing Coverage Covered Lines Changed/Added Lines %
fence/scripting/fence_create.py 38 43 88.37%
Files with Coverage Reduction New Missed Lines %
fence/resources/ga4gh/passports.py 2 87.43%
Totals Coverage Status
Change from base Build 13167: 0.1%
Covered Lines: 6947
Relevant Lines: 9382

💛 - Coveralls

else:
expected_expires_at = now + expires_in * 24 * 60 * 60
# allow up to 4 seconds variation to account for test execution
assert saved_client.expires_at <= expected_expires_at + 4000
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't expires in seconds not ms? I think this should be +- 4 not 4000

Copy link
Contributor Author

@paulineribeyre paulineribeyre Nov 28, 2022

Choose a reason for hiding this comment

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

this made me go down a rabbit hole - there was a ~3600s difference. i assumed it was in ms and added 4s

but i found out this only happened for the expires_in=1000 days case. Turns out getting a timestamp is not as easy as now + <n_days> * 24 * 60 * 60. On March 10 2024 there is an additional hour to take into account, I couldn't really figure out why (the time change is supposed to be on March 12). But datetime.timestamp() does the job so i just replaced the manual calculation 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

oh shoot, yeah I bet that was fun to look into 😅 time is fun. I'm glad datetime just does everything for us :D

.all()
)
assert len(client_sa_after) == 0

Copy link
Contributor

Choose a reason for hiding this comment

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

you should clean up the non-expired clients here too (if that's not done elsewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the database is emptied after each test so it should be fine:

request.addfinalizer(drop_all)

else:
expected_expires_at = now + expires_in * 24 * 60 * 60
# allow up to 4 seconds variation to account for test execution
assert client.expires_at <= expected_expires_at + 4000
Copy link
Contributor

Choose a reason for hiding this comment

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

see above, I think this is 4000 seconds, not 4 seconds

@@ -184,9 +221,11 @@ class Client(Base, OAuth2ClientMixin):
_default_scopes = Column(Text)
_scopes = ["compute", "storage", "user"]

expires_at = Column(Integer, nullable=False, default=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

how are existing clients getting migrated to this since it's not nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

turns out the client table already has the expires_at column, it was added to match the authlib model. It's already non-nullable and defaults to 0 (so for backwards compatibility, 0=no expiration)

Column("expires_at", Integer, nullable=False, default=0),

Copy link
Contributor

Choose a reason for hiding this comment

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

if it already has it, why do we need to add it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's in the table but it's not declared in the model. looks like it works fine without declaring it, but isn't it better that it's explicit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's better. I was just worried if it was necessary to add it here to make things work. But it sounds like if the table already has it, then this is more just for clarity in the future and everything should work fine without needing to run this migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it all works fine with no migration 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@paulineribeyre paulineribeyre merged commit 254dac3 into master Nov 30, 2022
@paulineribeyre paulineribeyre deleted the feat/expire-client branch November 30, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants