fix(aws): final review wave (incomplete badge, removable bad connections, partition regions, format chars, store modify, docs)
Secret Scan / scan (push) Successful in 11s
Build App (Preview) / compute-version (pull_request) Successful in 14s
Build App (Preview) / create-release (pull_request) Successful in 10s
Build App (Preview) / build-linux (pull_request) Successful in 11m3s
Build App (Preview) / build-macos (pull_request) Successful in 5m33s
Build App (Preview) / build-windows (pull_request) Successful in 11m27s
Build App (Preview) / prune-previews (pull_request) Successful in 21s
Secret Scan / scan (pull_request) Successful in 11s
Build App (Preview) / test (pull_request) Successful in 7m56s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-14 18:16:19 -08:00
1 parent 4694ae60c2
commit 8ec2cfece6
8 files changed
+278 -39

No files matched your search

+6
View File
@@ -814,6 +814,12 @@ a project's Docker volumes are deliberately out of scope — this is not a proje
inside a generic "settings replaced" summary. Read this as the standing example of the class of
thing to keep checking for in this feature, not a one-off fixed bug — any other field that looks
like config but is actually a live credential would have the same problem.
- **AWS connection keys travel in `ExportedSecrets::aws_connection_keys`** (keyed by connection id),
exported and restored like the marketplace tokens. `hosts` are **store-owned**: `update_settings`
restores them via `restore_host_fields`, and `apply_settings_import` re-applies them through
`StoreOwned`. `validate_imported_hosts` runs before any keychain write. The import preview
discloses AWS connections, key counts, overwrites (naming the local connection), failed key
checks and removals.
- **Marketplace account tokens travel in `ExportedSecrets`, not in `AppSettings`.** `Token` and
`GhContainer` accounts' tokens live in the keychain (`triple-c-marketplace-account-<id>`), so
they follow the same "carve out of the keychain, restore before the settings replace, only
+96 -24
View File
@@ -9,7 +9,7 @@ use crate::aws::permissions::{check_permissions, PermissionReport, SdkPermission
use crate::aws::policies::{policy_json, Tier};
use crate::aws::{caller_identity, sdk_config, sdk_config_for_keys, AwsError, CallerIdentity};
use crate::models::{
validate_connection_name, validate_profile_name, validate_region, AppSettings, AwsAuth,
validate_connection_name, validate_profile_name, validate_supported_region, AppSettings, AwsAuth,
HostConnection, HostKind,
};
use crate::storage::secure::{self, AwsKeys};
@@ -66,10 +66,10 @@ where
if let Some(k) = &keys {
store_keys(&conn.id, k).map_err(other)?;
}
// Read after the keychain step to keep the read-modify-write window short.
let mut all = settings.get();
all.hosts.push(conn.clone());
if let Err(e) = settings.update(all) {
if let Err(e) = settings.modify(|all| {
all.hosts.push(conn.clone());
Ok(())
}) {
if keys.is_some() {
let _ = delete_keys(&conn.id);
}
@@ -78,6 +78,35 @@ where
Ok(conn)
}
/// Removes the stored connection with this id, however malformed its other
/// fields are (a broken entry must stay removable). Its keychain entry is
/// deleted only for a `Keys` connection whose `keyring_ref` is its own valid id.
pub(crate) fn remove_connection_with(
id: &str,
delete_keys: impl Fn(&str) -> Result<(), String>,
settings: &SettingsStore,
) -> Result<AppSettings, String> {
check_id(id)?;
let existing = settings
.get()
.hosts
.into_iter()
.find(|h| h.id == id)
.ok_or_else(|| "Connection not found".to_string())?;
let HostKind::Aws { auth, .. } = &existing.kind;
if let AwsAuth::Keys { keyring_ref } = auth {
if keyring_ref == id && secure::is_valid_connection_id(keyring_ref) {
delete_keys(keyring_ref)?;
}
}
settings
.modify(|s| {
s.hosts.retain(|h| h.id != id);
Ok(())
})
.map(|(saved, ())| saved)
}
async fn real_identity(c: Credentials) -> Result<CallerIdentity, AwsError> {
let cfg = match c {
Credentials::Profile(conn) => {
@@ -100,7 +129,7 @@ fn aws_conn(id: &str, settings: &AppSettings) -> Result<HostConnection, String>
// Defense in depth: stored values are re-checked before they reach the
// keychain, the SDK or a subprocess.
let HostKind::Aws { auth, default_region } = &conn.kind;
validate_region(default_region)?;
validate_supported_region(default_region)?;
match auth {
AwsAuth::Profile { name } => {
validate_profile_name(name)?;
@@ -116,7 +145,7 @@ fn aws_conn(id: &str, settings: &AppSettings) -> Result<HostConnection, String>
fn validated(name: &str, region: &str) -> Result<(String, String), AwsError> {
Ok((
validate_connection_name(name).map_err(other)?,
validate_region(region).map_err(other)?,
validate_supported_region(region).map_err(other)?,
))
}
@@ -187,14 +216,17 @@ pub async fn update_aws_connection(
state: State<'_, AppState>,
) -> Result<HostConnection, AwsError> {
let (name, region) = validated(&name, &default_region)?;
let mut settings = state.settings_store.get();
aws_conn(&id, &settings).map_err(other)?;
let conn = settings.hosts.iter_mut().find(|h| h.id == id).expect("checked above");
conn.name = name;
let HostKind::Aws { default_region, .. } = &mut conn.kind;
*default_region = region;
let updated = conn.clone();
state.settings_store.update(settings).map_err(other)?;
let (_, updated) = state
.settings_store
.modify(|settings| {
aws_conn(&id, settings)?;
let conn = settings.hosts.iter_mut().find(|h| h.id == id).expect("checked above");
conn.name = name;
let HostKind::Aws { default_region, .. } = &mut conn.kind;
*default_region = region;
Ok(conn.clone())
})
.map_err(other)?;
Ok(updated)
}
@@ -203,14 +235,7 @@ pub async fn remove_host_connection(
id: String,
state: State<'_, AppState>,
) -> Result<AppSettings, String> {
let conn = aws_conn(&id, &state.settings_store.get())?;
let HostKind::Aws { auth, .. } = &conn.kind;
if let AwsAuth::Keys { keyring_ref } = auth {
secure::delete_aws_keys(keyring_ref)?;
}
let mut settings = state.settings_store.get();
settings.hosts.retain(|h| h.id != id);
state.settings_store.update(settings)
remove_connection_with(&id, secure::delete_aws_keys, &state.settings_store)
}
#[tauri::command]
@@ -247,7 +272,7 @@ pub async fn check_aws_permissions(
let conn = aws_conn(&id, &state.settings_store.get()).map_err(other)?;
let HostKind::Aws { default_region, .. } = &conn.kind;
let region = match region {
Some(r) => validate_region(&r).map_err(other)?,
Some(r) => validate_supported_region(&r).map_err(other)?,
None => default_region.clone(),
};
let cfg = sdk_config(&conn, &region).await?;
@@ -450,4 +475,51 @@ mod tests {
assert!(aws_conn("c1", &with("dev", "not a region")).is_err());
assert!(aws_conn("c1", &with("a b", "us-west-2")).is_err());
}
#[test]
fn a_connection_with_an_invalid_stored_region_can_still_be_removed() {
let dir = tempfile::tempdir().unwrap();
let settings = store_in(&dir);
let mut c = keys_conn();
c.kind = HostKind::Aws {
auth: AwsAuth::Keys { keyring_ref: "c2".into() },
default_region: "not a region".into(),
};
settings.update(AppSettings { hosts: vec![c, profile_conn()], ..AppSettings::default() }).unwrap();
let deleted = RefCell::new(Vec::<String>::new());
let after = remove_connection_with(
"c2",
|id| { deleted.borrow_mut().push(id.to_string()); Ok(()) },
&settings,
)
.unwrap();
assert_eq!(after.hosts, vec![profile_conn()]);
assert_eq!(settings.get().hosts, vec![profile_conn()]);
assert_eq!(*deleted.borrow(), vec!["c2".to_string()]);
}
#[test]
fn removal_leaves_the_keychain_alone_when_keyring_ref_is_not_the_id() {
let dir = tempfile::tempdir().unwrap();
let settings = store_in(&dir);
let mut c = keys_conn();
c.kind = HostKind::Aws {
auth: AwsAuth::Keys { keyring_ref: "someone-else".into() },
default_region: "us-west-2".into(),
};
settings.update(AppSettings { hosts: vec![c], ..AppSettings::default() }).unwrap();
remove_connection_with("c2", |_| panic!("must not touch the keychain"), &settings).unwrap();
assert!(settings.get().hosts.is_empty());
assert!(remove_connection_with("c2", |_| Ok(()), &settings).is_err());
assert!(remove_connection_with("bad id!", |_| Ok(()), &settings).is_err());
}
#[test]
fn china_and_govcloud_regions_are_refused_for_connections() {
for r in ["cn-north-1", "us-gov-west-1"] {
let e = validated("Prod", r).unwrap_err();
assert!(matches!(&e, AwsError::Other { message } if message == "China and GovCloud regions aren't supported yet."), "{e:?}");
}
assert!(validated("Prod", "eu-west-1").is_ok());
}
}
@@ -247,7 +247,7 @@ fn validate_imported_hosts(
keys: &BTreeMap<String, String>,
) -> Result<(), String> {
use crate::models::host_connection::{
validate_connection_name, validate_profile_name, validate_region,
validate_connection_name, validate_profile_name, validate_supported_region,
};
let wrap = |e: String| format!("The file's host connections were refused: {e}");
@@ -261,7 +261,7 @@ fn validate_imported_hosts(
}
h.name = validate_connection_name(&h.name).map_err(wrap)?;
let HostKind::Aws { auth, default_region } = &h.kind;
validate_region(default_region).map_err(wrap)?;
validate_supported_region(default_region).map_err(wrap)?;
match auth {
AwsAuth::Profile { name } => {
validate_profile_name(name).map_err(wrap)?;
@@ -1043,6 +1043,14 @@ mod tests {
};
assert!(check(vec![bad_region], none.clone()).is_err());
let mut cn = profile_host("p1");
cn.kind = HostKind::Aws {
auth: AwsAuth::Profile { name: "default".into() },
default_region: "cn-north-1".into(),
};
let err = check(vec![cn], none.clone()).unwrap_err();
assert!(err.contains("China and GovCloud regions aren't supported yet."), "{err}");
let mut bad_profile = profile_host("p1");
bad_profile.kind = HostKind::Aws {
auth: AwsAuth::Profile { name: "a b".into() },
+41 -3
View File
@@ -25,15 +25,24 @@ pub enum AwsAuth {
Keys { keyring_ref: String },
}
/// Trimmed, 1..=64 characters, no control characters.
/// Unicode format characters (category Cf): invisible, but able to reorder or
/// hide text (bidi overrides, zero-width spaces). `char::is_control` is Cc only.
fn is_format_char(c: char) -> bool {
matches!(c as u32,
0x00AD | 0x0600..=0x0605 | 0x061C | 0x06DD | 0x070F | 0x180E
| 0x200B..=0x200F | 0x202A..=0x202E | 0x2060..=0x2064 | 0x2066..=0x206F
| 0xFEFF | 0xFFF9..=0xFFFB | 0xE0001 | 0xE0020..=0xE007F)
}
/// Trimmed, 1..=64 characters, no control or invisible format characters.
pub fn validate_connection_name(name: &str) -> Result<String, String> {
let name = name.trim();
let len = name.chars().count();
if len == 0 || len > 64 {
return Err("Connection name must be 1 to 64 characters".into());
}
if name.chars().any(char::is_control) {
return Err("Connection name must not contain control characters".into());
if name.chars().any(|c| c.is_control() || is_format_char(c)) {
return Err("Connection name must not contain control or invisible formatting characters".into());
}
Ok(name.to_string())
}
@@ -68,6 +77,21 @@ pub fn validate_region(region: &str) -> Result<String, String> {
}
}
/// A region Triple-C's policies and checks can work with. Every policy and check
/// template hard-codes the `aws` partition (`arn:aws:`), so China, GovCloud and
/// the isolated partitions would always check as Insufficient. `validate_region`
/// stays general (it only checks the shape); connection add/update/import use this.
pub fn validate_supported_region(region: &str) -> Result<String, String> {
let region = validate_region(region)?;
if ["cn-", "us-gov-", "us-iso-", "us-isob-", "eu-isoe-", "us-isof-"]
.iter()
.any(|p| region.starts_with(p))
{
return Err("China and GovCloud regions aren't supported yet.".into());
}
Ok(region)
}
/// Non-empty, at most 128 characters of `[A-Za-z0-9_.@+=,-]`.
pub fn validate_profile_name(name: &str) -> Result<String, String> {
if name.is_empty() || name.len() > 128 {
@@ -116,6 +140,16 @@ mod tests {
for ok in ["us-west-2", "eu-central-1", "cn-north-1", "us-gov-west-1"] {
assert_eq!(validate_region(ok).unwrap(), ok);
}
for ok in ["us-west-2", "eu-central-1", "ap-southeast-4"] {
assert_eq!(validate_supported_region(ok).unwrap(), ok);
}
for other in ["cn-north-1", "cn-northwest-1", "us-gov-west-1", "us-gov-east-1"] {
assert_eq!(
validate_supported_region(other).unwrap_err(),
"China and GovCloud regions aren't supported yet."
);
}
assert!(validate_supported_region("nope").unwrap_err().contains("not a valid"));
for bad in ["", "US-WEST-2", "us-west", "us-west-2; rm"] {
assert!(validate_region(bad).is_err(), "{bad:?}");
}
@@ -138,6 +172,10 @@ mod tests {
assert_eq!(validate_connection_name(" Prod ").unwrap(), "Prod");
assert!(validate_connection_name(" ").is_err());
assert!(validate_connection_name("a\tb").is_err());
for c in ['\u{202E}', '\u{200B}', '\u{2066}', '\u{2069}', '\u{FEFF}'] {
assert!(validate_connection_name(&format!("ab{c}cd")).is_err(), "{c:?}");
}
assert!(validate_connection_name("Prod é 日本").is_ok());
assert!(validate_connection_name(&"a".repeat(65)).is_err());
}
}
@@ -80,4 +80,72 @@ impl SettingsStore {
*settings = new_settings.clone();
Ok(new_settings)
}
/// Read-modify-save under the store's lock, so concurrent callers cannot
/// lose each other's updates. `f` edits a copy; if it fails, or the save
/// fails, memory and disk are unchanged. Returns the saved settings and
/// whatever `f` returned.
pub fn modify<R, F>(&self, f: F) -> Result<(AppSettings, R), String>
where
F: FnOnce(&mut AppSettings) -> Result<R, String>,
{
let mut settings = self.lock();
let mut copy = settings.clone();
let out = f(&mut copy)?;
self.save(&copy)?;
*settings = copy.clone();
Ok((copy, out))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn modify_saves_and_returns_the_closure_result() {
let dir = tempfile::tempdir().unwrap();
let store = SettingsStore::at_path(dir.path().join("settings.json"));
let (saved, n) = store
.modify(|s| {
s.hosts.clear();
Ok(7)
})
.unwrap();
assert_eq!(n, 7);
assert_eq!(
serde_json::to_value(&saved).unwrap(),
serde_json::to_value(store.get()).unwrap()
);
assert!(dir.path().join("settings.json").exists());
}
#[test]
fn modify_does_not_change_memory_when_save_fails() {
let dir = tempfile::tempdir().unwrap();
let store = SettingsStore::at_path(dir.path().join("missing/settings.json"));
let before = serde_json::to_value(store.get()).unwrap();
let err = store.modify(|s| {
s.hosts.push(crate::models::HostConnection {
id: "x".into(),
name: "x".into(),
kind: crate::models::HostKind::Aws {
auth: crate::models::AwsAuth::Profile { name: "p".into() },
default_region: "us-west-2".into(),
},
});
Ok(())
});
assert!(err.is_err());
assert_eq!(serde_json::to_value(store.get()).unwrap(), before);
}
#[test]
fn modify_does_not_save_when_the_closure_fails() {
let dir = tempfile::tempdir().unwrap();
let store = SettingsStore::at_path(dir.path().join("settings.json"));
let err = store.modify(|_| -> Result<(), String> { Err("no".into()) }).unwrap_err();
assert_eq!(err, "no");
assert!(!dir.path().join("settings.json").exists());
}
}
@@ -160,6 +160,26 @@ describe("HostsSettings", () => {
expect(screen.getByRole("button", { name: "Copy admin policy" })).toBeInTheDocument();
});
it("shows a neutral Incomplete badge when the only blockers are failed checks", async () => {
invoke.mockImplementation(async (cmd: string) => {
if (cmd === "list_aws_profiles") return [];
if (cmd === "check_aws_permissions")
return report({
tiers: [
{ tier: "workspace_user", results: [{ action: "ecs:RunTask", verdict: "unverified", note: "throttled" }] },
{ tier: "environment_admin", results: [] },
],
});
throw new Error(`unexpected ${cmd}`);
});
render(<HostsSettings />);
fireEvent.click(screen.getByRole("button", { name: "Check Prod" }));
const badge = await screen.findByText("Incomplete — check again");
expect(badge.className).not.toContain("--error");
expect(screen.queryByText("Insufficient")).not.toBeInTheDocument();
expect(screen.getByText(/Some checks couldn't complete/)).toBeInTheDocument();
});
it("explains denied own-principal checks as the first thing to ask an admin for", async () => {
invoke.mockImplementation(async (cmd: string) => {
if (cmd === "list_aws_profiles") return [];
@@ -192,7 +212,7 @@ describe("HostsSettings", () => {
render(<HostsSettings />);
fireEvent.click(screen.getByRole("button", { name: "Check Prod" }));
expect(await screen.findByText(/Throttling/)).toBeInTheDocument();
expect(screen.getByText(/Check again/)).toBeInTheDocument();
expect(screen.getAllByText(/Check again/).length).toBeGreaterThan(0);
});
it("a probed check says writes are unverified", async () => {
+21 -3
View File
@@ -96,10 +96,22 @@ function ErrorLine({
function PermissionReportView({ report }: { report: PermissionReport }) {
const [copyNote, setCopyNote] = useState<string | null>(null);
const probed = typeof report.method === "object";
const badge =
report.summary === "workspace_user" && probed
// Insufficient only because checks couldn't complete (no denied row in the
// workspace tier, only rows with a note): don't claim the permissions are missing.
const workspaceTier = report.tiers.find((t) => t.tier === "workspace_user");
const incomplete =
report.summary === "insufficient" &&
!!workspaceTier &&
!workspaceTier.results.some((r) => r.verdict === "denied") &&
workspaceTier.results.some((r) => r.note);
const badge = incomplete
? "Incomplete — check again"
: report.summary === "workspace_user" && probed
? "Workspace user (unverified)"
: SUMMARY_LABEL[report.summary];
const badgeStyle = incomplete
? "text-[var(--text-secondary)] border-[var(--border-color)]"
: SUMMARY_STYLE[report.summary];
const flagged = report.tiers
.map((t) => ({ ...t, results: t.results.filter((r) => r.verdict !== "allowed") }))
.filter((t) => t.results.length > 0);
@@ -122,7 +134,7 @@ function PermissionReportView({ report }: { report: PermissionReport }) {
<div className="space-y-2 pt-2" data-testid="permission-report">
<div className="flex items-center gap-2 flex-wrap">
<span
className={`px-2 py-0.5 text-xs font-medium rounded-full border ${SUMMARY_STYLE[report.summary]}`}
className={`px-2 py-0.5 text-xs font-medium rounded-full border ${badgeStyle}`}
>
{badge}
</span>
@@ -130,6 +142,12 @@ function PermissionReportView({ report }: { report: PermissionReport }) {
{report.identity.arn} · {report.region}
</span>
</div>
{incomplete && (
<p className="text-xs text-[var(--text-secondary)] leading-snug">
Some checks couldn't complete (for example because AWS throttled the requests), so the
permissions couldn't be fully assessed. Check again in a moment.
</p>
)}
{typeof report.method === "object" && (
<p className="text-xs text-[var(--text-secondary)] leading-snug">
{`Simulation not permitted (${report.method.probed.reason}). Read access was probed; write actions are unverified and will be confirmed on first use.`}
+15 -6
View File
@@ -96,8 +96,9 @@ the role carries the `triple-c-permissions-boundary` managed policy as its permi
- ECS Exec channels;
- reading `triple-c/*` secrets;
- decrypting only through Secrets Manager, and only with environment (component-tagged) keys;
- mounting and writing only environment (component-tagged) file systems, with no root access,
because access points fix the POSIX user;
- mounting and writing only environment (component-tagged) file systems; whether that excludes
root access depends on access points fixing the POSIX user and root directory, which is only
true once phase 6 enforces them (see "Enforced access-point roots" under Phase 6 gaps);
- `sts:GetCallerIdentity`;
- invoking Bedrock models.
- The boundary grants nothing in IAM.
@@ -172,10 +173,11 @@ Create each file as a **customer managed policy** and attach it. In the console,
**IAM → Policies → Create policy → JSON**, paste the file, and attach the policy to a user, group
or role. Inline policies do not fit: a role's inline policies share 10,240 characters and an
environment admin needs both tiers (about 11,500), and a user's share 2,048. A managed policy may
hold 6,144 characters, not counting whitespace; the workspace policy is about 6,110, and a unit
test (`every_policy_fits_a_managed_policy`) fails before it outgrows that. For IAM Identity
Center, add the files as inline policies on the permission set (up to 32,768 characters) or
reference the managed policies.
hold 6,144 characters, not counting whitespace; the workspace policy is about 6,110 (roughly 30
characters of headroom, so phase 4 must split `workspace-user.json` into two policies before
adding anything to it), and a unit test (`every_policy_fits_a_managed_policy`) fails before it
outgrows that. For IAM Identity Center, add the files as inline policies on the permission set
(the "up to 32,768 characters" limit is unverified) or reference the managed policies.
With the CLI:
@@ -208,6 +210,13 @@ aws iam attach-user-policy --user-name <user> \
manages component-tagged secrets through the admin's credentials, that Deny will block
`PutSecretValue`/`DeleteSecret` for them.
**Phase 5**
- **No secrets in task definitions or `RunTask` overrides.** Nothing sensitive (the agent token,
git credentials) may travel in task-definition environment variables or in `RunTask`
`containerOverrides`: every workspace user can read them through `ecs:Describe*` on `*`. Use
Secrets Manager (`triple-c/*`) references instead.
**Phase 6**
- **Enforced access-point roots.** A workspace user creates their own access points. The