Skip to content

Conversation

@ChenSammi
Copy link
Contributor

What changes were proposed in this pull request?

The current way of specify endDate( https://github.com/apache/ozone/blob/master/hadoop-hdds/framework/src/main/java/or[…]p/hdds/security/x509/certificate/authority/DefaultCAServer.java) works well on time zone which doesn’t have Daylight Saving, but it will cause the endDate one hour ahead or after the expected time, if the beginDate and endDate, one with Daylight Saving, while another without.

Refer to https://issues.apache.org/jira/browse/HDDS-13781 for more info.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-13781

How was this patch tested?

new unit tests

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

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

Thanks @ChenSammi for the patch. LGTM, have some suggestion to simplify the logic a bit.

}

private LocalDateTime expiryFor(LocalDateTime beginDate, NodeType role) {
private Duration getDuration(LocalDateTime beginDate, NodeType role) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: beginDate is no longer used, can be removed.

Comment on lines 254 to 258
LocalDateTime beginDate, Duration duration, PKCS10CertificationRequest csr, NodeType role, String certSerialId
) throws IOException, OperatorCreationException, CertificateException {

ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime endDate = beginDate.atZone(zoneId).plus(duration);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since beginDate is no longer needed in the signAndStoreCertificate's caller, and it's always now(), we can simplify.

Suggested change
LocalDateTime beginDate, Duration duration, PKCS10CertificationRequest csr, NodeType role, String certSerialId
) throws IOException, OperatorCreationException, CertificateException {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime endDate = beginDate.atZone(zoneId).plus(duration);
Duration duration, PKCS10CertificationRequest csr, NodeType role, String certSerialId
) throws IOException, OperatorCreationException, CertificateException {
ZonedDateTime beginDate = ZonedDateTime.now();
ZonedDateTime endDate = beginDate.plus(duration);

xcert = approver.sign(config,
getPrivateKey(),
getCACertificate(),
Date.from(beginDate.atZone(ZoneId.systemDefault()).toInstant()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Date.from(beginDate.atZone(ZoneId.systemDefault()).toInstant()),
Date.from(beginDate.toInstant()),

Comment on lines 489 to 496
LocalDateTime beginDate = LocalDateTime.now();
LocalDateTime endDate =
beginDate.plus(securityConfig.getMaxCertificateDuration());
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime endDate = beginDate.atZone(zoneId).plus(securityConfig.getMaxCertificateDuration());
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, here:

    ZonedDateTime beginDate = ZonedDateTime.now();
    ZonedDateTime endDate = beginDate.plus(securityConfig.getMaxCertificateDuration());

Copy link
Contributor

@adoroszlai adoroszlai Nov 10, 2025

Choose a reason for hiding this comment

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

Thanks @ChenSammi for updating the patch. It seems this comment was missed.

(Note: LocalDateTime and ZoneId imports will be unused after this change.)

.setSubject(this.subject)
.setScmID(this.scmID)
.setClusterID(this.clusterID)
.setBeginDate(beginDate)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.setBeginDate(beginDate)
.setBeginDate(beginDate.toLocalDateTime())

@ChenSammi
Copy link
Contributor Author

@adoroszlai , thanks for the review.

Comment on lines 38 to 39
import java.time.LocalDateTime;
import java.time.ZoneId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import java.time.LocalDateTime;
import java.time.ZoneId;

Comment on lines 494 to 495
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime endDate = beginDate.atZone(zoneId).plus(securityConfig.getMaxCertificateDuration());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime endDate = beginDate.atZone(zoneId).plus(securityConfig.getMaxCertificateDuration());
ZonedDateTime endDate = beginDate.plus(securityConfig.getMaxCertificateDuration());

SecurityConfig securityConfig, KeyPair key)
throws IOException, SCMSecurityException {
Preconditions.checkNotNull(this.config);
LocalDateTime beginDate = LocalDateTime.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LocalDateTime beginDate = LocalDateTime.now();
ZonedDateTime beginDate = ZonedDateTime.now();

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

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

Thanks @ChenSammi for updating the patch to use ZonedDateTime.

@ChenSammi ChenSammi merged commit 94a3016 into apache:master Nov 11, 2025
43 checks passed
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