-
Notifications
You must be signed in to change notification settings - Fork 56
fix(#2433): restore data consistency guard in EnsureOrgInMint #2436
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,26 @@ func (p *Provisioner) EnsureOrgInMint(ctx context.Context, expectedURL string, o | |
| } | ||
|
|
||
| allowedOrgs := trafficEnvVars["ALLOWED_ORGS"] | ||
|
|
||
| // Defense-in-depth: if ALLOWED_ORGS is empty but ROLE_APP_IDS has | ||
| // role-only entries, the mint has been bootstrapped and should have | ||
| // enrolled orgs. Empty ALLOWED_ORGS in this state indicates env var | ||
| // data loss (e.g., stale read from a diverged revision), not a first | ||
| // enrollment. Abort to prevent silently unenrolling all existing orgs. | ||
| if allowedOrgs == "" { | ||
| var roleAppIDMap map[string]string | ||
|
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. [medium] fail-open json.Unmarshal error is silently discarded. If ROLE_APP_IDS contains malformed JSON, roleAppIDMap stays nil, RoleOnlyAppIDs returns nil, and the guard is bypassed. This is a fail-open on parse failure in a guard designed to detect data corruption. Suggested fix: Check the error from json.Unmarshal. If ROLE_APP_IDS is non-empty but fails to parse, return an error (fail closed). |
||
| if raw := trafficEnvVars["ROLE_APP_IDS"]; raw != "" { | ||
| _ = json.Unmarshal([]byte(raw), &roleAppIDMap) | ||
| } | ||
| roleOnly := mintcore.RoleOnlyAppIDs(roleAppIDMap) | ||
| if len(roleOnly) > 0 { | ||
| return fmt.Errorf( | ||
| "data inconsistency: ALLOWED_ORGS is empty but ROLE_APP_IDS has %d configured roles; "+ | ||
| "this suggests env var data loss — run 'fullsend mint status --project=%s' to investigate", | ||
| len(roleOnly), p.cfg.ProjectID) | ||
| } | ||
| } | ||
|
|
||
| orgPresent := false | ||
| for _, o := range strings.Split(allowedOrgs, ",") { | ||
| if strings.EqualFold(strings.TrimSpace(o), org) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[low] error-message-consistency
Error message uses multi-line string concatenation with '+' operator, inconsistent with other fmt.Errorf calls in this file which use single-line format strings.
Suggested fix: Consolidate into a single-line format string.