Skip to content

Set the signing clock property #4341

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

Conversation

sugmanue
Copy link
Contributor

Motivation and Context

The new signer interface needs to be aware of any detected time offset to use that when signing. We cannot set that property properly since we don't have that information inside the auth interceptor, so unlike the other properties, we set this when we create the request. The way it's currently implemented follows the same logic that the previous signers were using before.

Modifications

Modified the sync/async signing stages to grab from the dependencies the current timeoffset and use it to construct a Clock that the signer can use to compute the singing date.

Testing

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@sugmanue sugmanue requested a review from a team as a code owner August 24, 2023 16:46
@sugmanue sugmanue requested a review from millems August 24, 2023 16:49
Comment on lines 21 to 23
/**
* Keeps common signing properties used by different signers.
*/
Copy link
Contributor

@millems millems Aug 24, 2023

Choose a reason for hiding this comment

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

This makes sense. I was thinking about this a bit when I was working on some of the v4+v4a attributes, but decided we probably shouldn't do it for those attributes. It makes a lot of sense for the signing clock, though.

I think we should be really strict in the javadoc about this. It should be things that CAN NEVER be signer-specific. A clock is universal, it makes sense here. We need to write the javadoc in a way that keeps future developers from wanting to push something like service signing name here. In my opinion, clock is probably the only thing that ever makes sense here, but who knows what the future will hold...

Copy link
Contributor

Choose a reason for hiding this comment

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

My initial thought was this goes in the HttpSigner interface itself and specific signers javadoc whether they use this property or not. What do folks think about that?

Comment on lines 240 to 241
// Assert that the time offset set was zero
assertThat(signRequest.property(SharedSignerProperty.SIGNING_CLOCK)).isNotNull();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think rather not set the property if offset is 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will introduce a branch that is not needed the way it's written now, so I think is better just to have a single code path. Can you please help me understand why you think is better not to set it?

Copy link
Contributor

@gosar gosar Aug 25, 2023

Choose a reason for hiding this comment

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

I thought it is better since with current approach the test is more fragile and can fail sometimes if for some reason Instant.now is actually beyond the within value?

Copy link
Contributor

Choose a reason for hiding this comment

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

The other test is still fragile like that. I think we can have a package-private constructor that takes in a Clock (instead of Clock.systemUTC), so that unit test can use a mock Clock and test exactly, instead of isCloseTo.

Copy link
Contributor

@gosar gosar Aug 25, 2023

Choose a reason for hiding this comment

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

That would address my main concern - test fragility. We could still chose to not set or set the clock property if offset is 0. I was thinking that if there is no need for offset, the SigningStage can let the HttpSigner decide whether it needs a clock at all or not. But I don't feel strongly about that, if the test fragility is addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather tackle the problem when and if arises, I'm know that what you describing is possible but I don't think is likely, for that to happen it would mean that the machine running the tests will need to park the thread for more than 100ms (~ 300 Million instructions). Were the previous tests brittle like actually failing every so often?

Copy link
Contributor

@gosar gosar left a comment

Choose a reason for hiding this comment

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

Approving this to not block on decision on what you do about test fragility.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 256 Code Smells

0.0% 0.0% Coverage
2.9% 2.9% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@@ -67,7 +70,7 @@

@RunWith(MockitoJUnitRunner.class)
public class AsyncSigningStageTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test (sync and async both) to assert that if the selected auth scheme has a SIGNING_CLOCK it is used over the default SIGNING_CLOCK? LGTM otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

good call about that use case!

@sugmanue sugmanue merged commit 6f8f150 into feature/master/sra-identity-auth Aug 29, 2023
@sugmanue sugmanue deleted the sugmanue/sra-ia-add-clock-signer-property branch August 30, 2023 16:42
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.

3 participants