Skip to content

fix: enhance token refresh handling and improve error reporting - #138

Merged
synackd merged 4 commits into
mainfrom
fix/smd-token-refresh-hardening
Oct 20, 2026
Merged

synackd merged 4 commits into
mainfrom
fix/smd-token-refresh-hardening

Conversation

@alexlovelltroy

Copy link
Copy Markdown
Member

Description

This pull request improves the reliability and test coverage of the SMD client’s access token refresh logic. The most important changes include stricter error handling and validation in token refresh, dedicated HTTP client usage for token requests, and new tests to ensure correct behavior when token refresh fails.

Error Handling and Validation Improvements:

  • The refreshTokenWithContext method now returns detailed errors for various failure modes, such as missing HTTP client, non-2xx responses, malformed or empty tokens, and JSON decoding errors. It also trims whitespace from the received token and rejects empty tokens.
  • In getSMD, if the token refresh fails after a rejected access token, the error is now returned immediately instead of being silently ignored, providing better visibility and preventing retries with invalid tokens.

HTTP Client Usage and Struct Changes:

  • Added a dedicated tokenClient field to SMDClient, ensuring token refresh requests use a separate HTTP client from regular SMD requests. Constructors and tests are updated to initialize this field appropriately. [1] [2] [3] [4]

Testing Improvements:

  • Added tests to verify that failed token refresh attempts (due to non-2xx responses, empty access tokens, or malformed JSON) do not overwrite the previous access token.
  • Added a test to ensure that getSMD returns a refresh failure error without retrying, and that the access token remains unchanged.

Code Consistency:

  • Standardized struct field names in oidcTokenData to use Go naming conventions (e.g., AccessToken instead of Access_token).

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • I have updated the relevant documentation (CLI examples, man pages, README, other docs, etc.)
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Dependency update
  • Build system/CI

Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov>

@synackd synackd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just one concern (with suggested patch) about separate HTTP client for token refresh.

Comment thread internal/smdclient/SMDclient.go Resolved
Reuse the SMD HTTP transport and timeout in the dedicated token client
so token refresh honors the configured TLS trust and insecure settings.

Assign the loaded CA pool to the outer variable instead of shadowing it,
ensuring the configured certificate reaches the shared TLS transport.

Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
Exercise NewSMDClient against a local HTTPS server with a custom CA and
with TLS verification disabled. Reject the initial token to verify that
token refresh honors the configured TLS settings and cache loading
succeeds after retrying with the refreshed token.

Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
@synackd
synackd requested a review from travisbcotton October 20, 2026 15:28
@synackd
synackd enabled auto-merge (squash) October 20, 2026 15:28
Raise the Go requirement to 1.26.9 and update golang.org/x/net to
v0.60.0 to address the vulnerabilities reported by govulncheck.

Update the required transitive modules and tidy the module sums. Align
the debug image with Go 1.26.9 so debug builds also use the patched
standard library.

Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
@synackd

synackd commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

@travisbcotton Checks are passing now, this should be ready for review. Auto merge is enabled so this will be merged after your approval.

@synackd
synackd disabled auto-merge October 20, 2026 16:08
@synackd
synackd merged commit dfbe364 into main Oct 20, 2026
14 checks passed
@synackd
synackd deleted the fix/smd-token-refresh-hardening branch October 20, 2026 16:08
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