GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(auth): verify workload cert and key match, retrying mid-rotation reads by nbayati · Pull Request #19043 · googleapis/google-cloud-python Conversation
Contributor
When the workload certificate and private key are separate files, re-read both (up to 3 attempts, 100ms apart) if the private key does not match the leaf certificate's public key, and raise ClientCertError if the mismatch persists. Keys or certificates that cannot be parsed (e.g. passphrase- encrypted keys) skip the check and keep the existing behavior. fixes b/545786900
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
…reads When the workload certificate and private key are separate files, re-read both (up to 3 attempts, 100ms apart) if the private key does not match the leaf certificate's public key, and raise ClientCertError if the mismatch persists. Keys or certificates that cannot be parsed (e.g. passphrase- encrypted keys) skip the check and keep the existing behavior.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code ReviewThis pull request introduces a retry mechanism when reading certificate and private key files in
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
macastelaz
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behaviour change worth stating in the description: on the 401 path a persistent mismatch is not raised to the caller. Before this change, a mismatched pair on disk was returned, the fingerprint differed, reconfiguration failed in Now the new That is arguably the better outcome, and nothing is cached so the next 401 re-checks. But the description says "raise ClientCertError if the mismatch persists", which is not what a 401-path caller sees. A caller-level test for this path would be a nice addition.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+628
to
+630
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loads the private key with full RSA validation on every call of Cost (cryptography 46.0.7, OpenSSL 3.6.5, per check): RSA-2048 ~41 ms, RSA-4096 ~286 ms, EC P-256 ~0.06 ms. Agent-identity pools are fixed to ECDSA P-256, but RSA keys are documented for this path: the X.509 Workload Identity Federation setup guide generates Not a gate: if validation fails, the Since only the public half is compared, suggest skipping the validation where the installed library supports it (needs # Only the key's public half is compared, so skip RSA private-key validation # where supported: it is slow (~40 ms for RSA-2048) and the TLS layer does not # perform it either. try: _SKIP_RSA_VALIDATION_SUPPORTED = ( "unsafe_skip_rsa_key_validation" in inspect.signature(serialization.load_pem_private_key).parameters ) except (TypeError, ValueError): _SKIP_RSA_VALIDATION_SUPPORTED = False _KEY_MATCH_LOAD_KWARGS = ( {"unsafe_skip_rsa_key_validation": True} if _SKIP_RSA_VALIDATION_SUPPORTED else {} ) ... key_public_key = serialization.load_pem_private_key( key, password=None, **_KEY_MATCH_LOAD_KWARGS ).public_key() I applied this to a copy of the branch:
The
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+600
to
+601
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The retry only covers "both files parse but the keys differ". These two reads are outside any A rotator that truncates and rewrites in place, or unlinks and recreates, produces an empty, partial, or missing file in the same window that produces a mismatched pair. I reproduced each of those states against this function: all raise immediately, even when the file would be valid again by the first sleep. Rotators that swap atomically never hit this. Not a regression, but the docstring justifies the loop by rotation, so it seems worth covering. Sketch (I ran this against the branch for healing, permanent-failure and mixed cases): last_exc = None for attempt in range(_CERT_KEY_MATCH_MAX_ATTEMPTS): if attempt: time.sleep(_CERT_KEY_MATCH_RETRY_INTERVAL) try: cert_data = _read_cert_file(cert_path) key_data = _read_key_file(key_path) except (OSError, exceptions.ClientCertError) as exc: last_exc = exc continue last_exc = None if not _has_cert_key_mismatch(cert_data, key_data): return cert_data, key_data ... if last_exc is not None: raise last_exc raise exceptions.ClientCertError(...) Trade-off: a permanently missing or malformed file then takes 0.2 s to raise. The existing failure tests in
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+858
to
+860
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only rewrites the key file during the wait, so nothing pins that the certificate is re-read too. Hoisting Rotation can land in either order. Suggest parametrizing on which file catches up, or adding a sibling case: start with a stale certificate and the new key, and have the side effect write the matching certificate to
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThis branch has not been deployedNo deployments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reviewers+1 more reviewerAt least 1 approving review is required to merge this pull request. Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | ||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |