fix(profile): preserve "." in profile names so credentials are stored as a literal key - #1854
Open
pranav-new-relic wants to merge 1 commit into
Open
fix(profile): preserve "." in profile names so credentials are stored as a literal key#1854pranav-new-relic wants to merge 1 commit into
pranav-new-relic wants to merge 1 commit into
Conversation
Profile names with a "." (e.g. "ava.morgan") were being interpreted as
nested gjson/sjson paths in the JSON-backed credentials store. As a
result, "newrelic profile add --profile ava.morgan ..." silently wrote
{"ava":{"morgan":{...}}}, GetScopes returned only "ava", and follow-up
commands reported the profile did not exist.
Escape "." (and "\") in user-controlled path segments — profile name and
the optional global scope — before joining them with the literal "."
separator that gjson/sjson uses for nesting. The well-known field keys
defined inside the package never contain dots, so behavior for existing
non-dotted profiles is unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
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.
What broke
Creating a CLI profile whose name contains a
.— for examplenewrelic profile add --profile ava.morgan ...— appeared to succeed, but every subsequent command reportedFATAL profile ava.morgan does not exist. The root cause is that the credentials store is JSON-backed viagjson/sjson, and those libraries treat.as a path separator for nested objects. So writing the value at the pathava.morgan.apiKeyproduced{"ava":{"morgan":{"apiKey":"..."}}}instead of{"ava.morgan":{"apiKey":"..."}}. Because the top-level key was nowavaand notava.morgan,GetScopes()lost the original name, and any read or delete keyed onava.morganfailed. Underscores worked because they are not special characters togjson/sjson. The customer-reported thread referenced this exact symptom with a profile name likefirstname.lastname.What changed
The fix lives in
internal/config/json_store.go: a small helperescapePathSegmentruns over the user-controlled segments (the profile name passed as scope, and the optional global scope) before they're joined with the literal.separator used to build agjson/sjsonpath. It escapes\first and then., which is the documented escape syntax both libraries accept, so a name likeava.morganbecomes the pathava\.morgan.apiKeyand is stored as a single literal top-level key. The same helper is also applied inRemoveScopeso deleting a dotted profile no longer also nukes its siblings. Three new unit tests injson_store_test.gocover set+get, list-scopes, and remove for dotted names (ava.morgan,riley.chen,prod.us-east-1,team.platform,team.observability) and confirm that two profiles sharing a prefix liketeam.*are stored independently. The fix is a no-op for any profile name that does not contain.or\, so existing on-disk credentials and the common profile-naming case stay completely untouched.