Skip to content

Timezone aware datetimes + remove hack from #209#300

Merged
clalancette merged 5 commits intorollingfrom
timezone-aware-datetimes
Jul 29, 2025
Merged

Timezone aware datetimes + remove hack from #209#300
clalancette merged 5 commits intorollingfrom
timezone-aware-datetimes

Conversation

@mikaelarguedas
Copy link
Member

@mikaelarguedas mikaelarguedas commented May 7, 2024

This PR (basically a redo of #210) does:

  • Set timezone to UTC explicitly in all security artifacts
  • Make python datetime object timezone-aware, as this will be mandatory in future versions of python and reduces unexpected behaviors

I dont have a connext setup (license plugins etc right now) and the ROS 2 CI machines seem to be UTC so maybe they wont reflect the issue. If a reviewer that is behind UTC and has the right setup can give it a try that'd be awesome

@mikaelarguedas mikaelarguedas marked this pull request as ready for review May 7, 2024 09:48
@mikaelarguedas
Copy link
Member Author

@marcoag @clalancette is it possible to launch a round of CI for this PR please 🙏

@ahcorde
Copy link
Contributor

ahcorde commented May 7, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@mikaelarguedas
Copy link
Member Author

@ruffsl interested in having your feedback on this.

(all info in the description of the PR)

@mikaelarguedas
Copy link
Member Author

CI on WIndows is failing because CI is using a lower version of Python than the one defined in REP-2000.
More details at ros-infrastructure/ros2-cookbooks#69

@clalancette
Copy link
Contributor

CI on WIndows is failing because CI is using a lower version of Python than the one defined in REP-2000.
More details at ros-infrastructure/ros2-cookbooks#69

I commented over there, but in short, we are not going to be able to update Python. So we'll have to figure out another solution.

@mikaelarguedas mikaelarguedas force-pushed the timezone-aware-datetimes branch from 5006e37 to 1752d32 Compare May 8, 2024 13:23
@codecov
Copy link

codecov bot commented May 8, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.38%. Comparing base (1d36b11) to head (df3fdee).
⚠️ Report is 1 commits behind head on rolling.

Additional details and impacted files
@@             Coverage Diff             @@
##           rolling     #300      +/-   ##
===========================================
- Coverage    88.94%   88.38%   -0.56%     
===========================================
  Files           24       24              
  Lines          615      620       +5     
  Branches        64       66       +2     
===========================================
+ Hits           547      548       +1     
- Misses          50       52       +2     
- Partials        18       20       +2     
Flag Coverage Δ
unittests 88.38% <ø> (-0.56%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mikaelarguedas
Copy link
Member Author

mikaelarguedas commented May 8, 2024

@ahcorde @clalancette is it possible to launch CI on that version to see if Windows is happy with it ?

@mikaelarguedas
Copy link
Member Author

mikaelarguedas commented May 8, 2024

  • Linux Build Status

  • Linux-aarch64 Build Status

  • Windows Build Status

  • Windows debug Build Status

@mikaelarguedas mikaelarguedas force-pushed the timezone-aware-datetimes branch from fefd058 to 03a1e3e Compare May 8, 2024 21:43
<xsl:param name="not_valid_before" select="'2020-05-01T00:00:00'"/>
<xsl:param name="not_valid_after" select="'2030-05-01T00:00:00'"/>
<xsl:param name="not_valid_before" select="'2020-05-01T00:00:00+00:00'"/>
<xsl:param name="not_valid_after" select="'2030-05-01T00:00:00+00:00'"/>
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to use +00:00 or Z here?

From the OP ticket:

The time zone may be specified as Z (UTC) or (+|-)hh:mm.

Not sure if this (formatting choice) was the original point of issue here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I initially tried this 2754240 but one of the issues is that Python has pretty limited support for it.

The ability to parse a string in that format appeared in Python 3.11.
And even in Python 3.12, the printing in isoformat is not configurable and outputs the +HH:MM.

I guess we can revisit if the testing of this with connext show the issue still exists with version 6.0.1.

cert_content = _utilities.load_cert(cert_path)
kwargs['not_valid_before'] = etree.XSLT.strparam(cert_content.not_valid_before.isoformat())
kwargs['not_valid_after'] = etree.XSLT.strparam(cert_content.not_valid_after.isoformat())
# TODO replace "not_valid_before"/"not_valid_after" functions by
Copy link
Member

Choose a reason for hiding this comment

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

Sad to read about that window holding back and blocking the python REP updates, given the Qt release changes. I hope the latest minor release of cryptography is still secure and up-to-date for all platforms. :<

# when extracting it from the permissions file and thinking it's in the future
# https://github.com/ros2/ci/pull/436#issuecomment-624874296
utcnow - datetime.timedelta(days=1)
utcnow
Copy link
Member

Choose a reason for hiding this comment

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

I'm kind of the opinion if it still broken for a DDS vendor by now, then that's more concerning. I've no longer have an active licence, but I could go ask for a renewal to verify this if you'd like.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah so its a bit tricky,

the version shipped with the Jazzy binaries fails to run the launcher:

/opt/rti.com/rti_connext_dds-6.0.1/bin/rtilauncher
Gtk-Message: 09:06:35.729: Failed to load module "canberra-gtk-module"
No RTI workspace was created.
Please contact RTI Support (https://support.rti.com)

The only one I saw available on their website is 7.3.0.

And 7.3.0 is not API compatible with 6.0.1 so I cannot launch nodes

I could try to install the rtipkg from commandline but not sure where to download them if not from the rti website or launcher..


Maybe someone at Open Robotics could give this PR a try ? (as osrf has both license and installer backed up)

@clalancette do you know anyone we could reach out for that could test this ?


So there is a larger issue here, how do people install connext with security plugins for any active ROS 2 distro ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ahcorde Hey there 👋

The PR I dont have the ability to test myself we were chatting about offline today

Copy link
Contributor

Choose a reason for hiding this comment

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

this is the only concern before merge, everything else looks good to me.

@sloretz
Copy link
Contributor

sloretz commented May 16, 2024

@marcoag mind giving this a try with connect? 🧇

Copy link
Contributor

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm with green CI

# when extracting it from the permissions file and thinking it's in the future
# https://github.com/ros2/ci/pull/436#issuecomment-624874296
utcnow - datetime.timedelta(days=1)
utcnow
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the only concern before merge, everything else looks good to me.

@mikaelarguedas mikaelarguedas force-pushed the timezone-aware-datetimes branch from 03a1e3e to f30f050 Compare May 13, 2025 06:51
@mikaelarguedas
Copy link
Member Author

@sloretz @marcoag @fujitatomoya I rebased this, anyone has the ability to test it on Connext so we can decide if we merge this or if we need to downscope it ?

Thanks 🙏

@fujitatomoya
Copy link
Contributor

@mikaelarguedas how about starting CI? that should include the test with ConnextDDS, right?

@fujitatomoya
Copy link
Contributor

Pulls: #300
Gist: https://gist.githubusercontent.com/fujitatomoya/5410ada7801c7d53b9da50e950b6a99a/raw/5c2aeef052ae70656b4f52357d2f2d49421701c0/ros2.repos
BUILD args: --packages-above-and-dependencies sros2
TEST args: --packages-above sros2
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15976

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Python 3.8 compatible because windows

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
@mikaelarguedas mikaelarguedas force-pushed the timezone-aware-datetimes branch from f30f050 to 6890599 Compare July 26, 2025 10:32
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
@mikaelarguedas mikaelarguedas force-pushed the timezone-aware-datetimes branch from 6890599 to 4fde405 Compare July 26, 2025 10:45
cert_content = _utilities.load_cert(cert_path)
kwargs['not_valid_before'] = etree.XSLT.strparam(cert_content.not_valid_before.isoformat())
kwargs['not_valid_after'] = etree.XSLT.strparam(cert_content.not_valid_after.isoformat())
if _utilities.cryptography_version().major >= 42:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a huge fan of using semver and parsing the version number here. What we've done elsewhere is to be conditional on the API we want existing. In this case, I think we could do something more like:

if hasattr(cert_content, 'not_valid_before_utc'):
    kwargs = ...
else:
   kwargs = ...

(this also means we don't add another dependency to this package, which I'm always a fan of)

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

My original take was to get rid of comments stating which version was needed while keeping an easy way to track from which version legacy code could be removed.

I considered parsing the version string but it seemed more hacky than using a maintained package dedicated to that.


I am happy to update the code accordingly if this is the recommended approach. It is explicit in terms of what API is needed.

My only concern is that it hides the version of the module we're actually requiring for this API to be used. Which often leads to confusion or extra work when we ask "from what version can we get rid of this legacy code?" (similar to #347).

In which case I would add back a comment stating version numbers wherever the check are performed.

Would you prefer that to the current approach ? (I'm fine either way 👍)


It would look like this

    # TODO use `not_valid_before_utc` unconditionally once cryptography 42 is available on all target platforms
    if hasattr(cert_content, 'not_valid_before_utc'):
        cert_not_valid_before_value = cert.not_valid_before_utc
    else:
        cert_not_valid_before_value = cert.not_valid_before.replace(tzinfo=datetime.timezone.utc)

    # TODO use `not_valid_after_utc` unconditionally once cryptography 42 is available on all target platforms
    if hasattr(cert_content, 'not_valid_after_utc'):
        cert_not_valid_after_value = cert.not_valid_after_utc
    else:
        cert_not_valid_after_value = cert.not_valid_after.replace(tzinfo=datetime.timezone.utc)

v.s. current state:

    if _utilities.cryptography_version().major >= 42:
        cert_not_valid_before_value = cert.not_valid_before_utc
        cert_not_valid_after_value = cert.not_valid_after_utc
    else:
        cert_not_valid_before_value = cert.not_valid_before.replace(tzinfo=datetime.timezone.utc)
        cert_not_valid_after_value = cert.not_valid_after.replace(tzinfo=datetime.timezone.utc)

Copy link
Contributor

Choose a reason for hiding this comment

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

In which case I would add back a comment stating version numbers wherever the check are performed.

Would you prefer that to the current approach ? (I'm fine either way 👍)

Yeah, I think that would be better rather than adding the new dependency. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in df3fdee

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks! I'll run CI on it next.

@clalancette
Copy link
Contributor

Pulls: #300
Gist: https://gist.githubusercontent.com/clalancette/e34124a7f2e103824edb0b48ec20078c/raw/01711b92e4e8c5cd5d3935c696cf5f6cc2ca6d8b/ros2.repos
BUILD args: --packages-above-and-dependencies sros2
TEST args: --packages-above sros2
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16645

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@clalancette clalancette merged commit 46e031c into rolling Jul 29, 2025
6 of 7 checks passed
@clalancette clalancette deleted the timezone-aware-datetimes branch July 29, 2025 17:16
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.

7 participants