fix: implement flexible account name matching for AWS ARN prefixes - #26
Merged
Merged
Conversation
Implements flexible matching to handle account names with or without the 'arn:' prefix. The ykman CLI tool displays AWS account names with 'arn:' prefix, but the yubikey-manager library returns them without the prefix, causing "Account not found" errors when using the daemon with AWS CLI credential_process integration. Changes: - Add _normalize_account_name() method to strip 'arn:' prefix - Add _find_matching_credential() method with flexible matching logic - Update generate_totp() to use flexible matching and correct result lookup - Add debug logging to understand credential structure from library - Add comprehensive unit tests for account name matching scenarios The implementation tries exact match first, then normalized match (without prefix), ensuring backward compatibility while fixing AWS CLI integration. Fixes #25
OlivierCloudar
force-pushed
the
fix/issue-25-account-name-mismatch
branch
from
October 30, 2025 17:32
005705c to
22fd724
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #25 - Implements account name matching using the
credential.idfield to support full ARN format, resolving "Account not found" errors when using the daemon with AWS CLI credential_process integration.Problem
The ykman CLI tool displays AWS account names with full ARN format (e.g.,
arn:aws:iam::123456:mfa/user), but when querying the daemon API, account lookup failed even though the account existed on the YubiKey.Root Cause
The yubikey-manager library splits credential IDs on the first
:to createissuerandnamefields:b'arn:aws:iam::123456:mfa/user'- full original value"arn""aws:iam::123456:mfa/user"- everything after first:The ykman CLI displays the full
credential.id, but the daemon was only matching againstcredential.name, causing mismatches.Solution
Simplified the matching logic to prioritize
credential.id(which contains the full original credential string) and fall back tocredential.namefor backward compatibility.Changes
Core Implementation (
src/yk_daemon/yubikey.py:73)_find_matching_credential()method that:credential.id(decoded from bytes)credential.namelist_accounts()to show credential structure (name, issuer, id)generate_totp()to use the new matching methodTests (
tests/test_yubikey.py)TestAccountNameMatchingwith 6 test cases:Test Results
All 182 tests pass:
Backward Compatibility
The implementation maintains full backward compatibility:
credential.idmatching is tried first (supports full ARN format)credential.namematching if id doesn't matchExample Usage
After this fix, both formats work correctly:
Both requests will successfully find and generate TOTP codes for the same account.
Debug Output
The debug logging added in this fix shows the actual credential structure:
This confirms that
credential.idcontains the full ARN that matches what ykman CLI displays.