Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/scripts/iam_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,22 @@ def diff(old_dir, new_dir):
a, b = old.get(rel) or {}, new.get(rel) or {}
ra, rb = a.get("Resources") or {}, b.get("Resources") or {}
sa, sb = side(a), side(b)
# Roles, policies and resource policies: what the new release newly
# allows, every one of the file together (u.grant_difference).
grants = {lid for lid in set(ra) | set(rb) if u.grant_kind(ra.get(lid)) or u.grant_kind(rb.get(lid))}
changed = {lid: "Add" if lid not in ra else "Remove" if lid not in rb else "Modify" for lid in grants
if json.dumps(ra.get(lid), sort_keys=True) != json.dumps(rb.get(lid), sort_keys=True)}
widened, unknown = u.grant_difference(sa, sb, changed) if changed else ({}, {})
for lid in sorted(set(ra) | set(rb)):
if not (is_permission(ra.get(lid) or {}) or is_permission(rb.get(lid) or {})):
continue
kind = (rb.get(lid) or ra.get(lid) or {}).get("Type") or ""
if lid in grants:
if lid in unknown:
out.append((rel, lid, kind, f"couldn't be compared ({unknown[lid]})"))
elif widened.get(lid):
out.append((rel, lid, kind, "; ".join(widened[lid])))
continue
if lid not in ra:
out.append((rel, lid, kind, "added"))
continue
Expand All @@ -107,7 +119,7 @@ def diff(old_dir, new_dir):
def markdown(changes, from_tag):
since = f"since {from_tag}" if from_tag else "since the previous release"
if not changes:
return (f"## Permission changes {since}\n\nNone: every role, policy and resource policy grants exactly what "
return (f"## Permission changes {since}\n\nNone: every role, policy and resource policy allows no more than "
f"{from_tag or 'the previous release'}'s does (compared as the updater compares them).\n")
lines = [f"## Permission changes {since}", "",
"An update with these waits for an admin's OK; nothing else about permissions changes.", ""]
Expand Down
15 changes: 15 additions & 0 deletions .github/scripts/test_iam_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ def test_an_added_action_is_listed(self):
self.assertIn("## Permission changes since v1.0.0", md)
self.assertIn("dynamodb:PutItem", md)

def test_a_narrowed_or_moved_statement_is_no_change(self):
p = copy.deepcopy(POLICY)
p["Properties"]["PolicyDocument"]["Statement"][0]["Action"] = ["dynamodb:GetItem"]
self.assertEqual(self.run_diff(POLICY, p), [])
# The second statement moved to an overflow policy of the same role.
release(self.tmp / "old2", POLICY)
release(self.tmp / "new2", p)
t = json.loads((self.tmp / "new2" / "stacks" / "Worker.json").read_text())
moved = t["Resources"]["WorkerRoleDefaultPolicy"]["Properties"]["PolicyDocument"]["Statement"].pop()
t["Resources"]["WorkerRoleDefaultPolicy"]["Properties"]["PolicyDocument"]["Statement"][0]["Action"] = ["dynamodb:GetItem", "dynamodb:Query"]
t["Resources"]["WorkerRoleOverflowPolicy1"] = {"Type": "AWS::IAM::ManagedPolicy", "Properties": {
"Roles": [{"Ref": "WorkerRole"}], "PolicyDocument": {"Version": "2012-10-17", "Statement": [moved]}}}
(self.tmp / "new2" / "stacks" / "Worker.json").write_text(json.dumps(t))
self.assertEqual(iam_diff.diff(self.tmp / "old2", self.tmp / "new2"), [])

def test_a_change_in_a_branch_no_value_takes_is_listed(self):
p = copy.deepcopy(POLICY)
p["Properties"]["PolicyDocument"]["Statement"][1]["Resource"]["Fn::If"][1] = "*"
Expand Down
5 changes: 5 additions & 0 deletions docs/incidents/xs_update_continues_its_own_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# xs. `xs_update_continues_its_own_version`

**What happened:** A self-hosted install with auto-update on, on the beta channel at any hour, stayed on one release. Each beta was held for a person because it changed permissions, and a held update is not "running", so the next hourly check started the same release again: a new change set, and the one waiting was marked superseded, "replaced by the update to" the same version, every hour. None was ever applied. Half of each hold was no widening at all: aws-cdk-lib rewrote a log-read statement in a role's overflow policy with the log group's bare ARN beside its `:*` ARN, and compared policy by policy as text it read as "resources or conditions change". The other half was real, and still waits for a person: a new schedule allowed to send to a queue. When the hourly check couldn't start an update at all, it stopped the rest of the check and nobody was told.

**The guarantee:** An update never replaces an update to the same version. The next hourly check, or an admin's press of **Update**, continues the change set already prepared for that version, and an admin's press with their OK for permission changes lets that same change set apply. A newer release still replaces an older one that hasn't run. Permission changes are compared as what they allow, across every role, policy and resource policy of a part together: only a grant no running one covers, or a deny or boundary the new release drops, holds an update, and the hold names it in plain words. A move between policies of the same role, a different order, a log group's ARN with or without `:*`, a condition added or an action removed applies by itself. An hourly check that can't start its update writes the row, goes on with the rest of the check, and at the second refusal in a row emails the admins once. The Python tests in `lambda/tests/test_updater_same_version.py` and `lambda/tests/test_updater_grants.py` replay each one; this case holds the wiring.
8 changes: 4 additions & 4 deletions docs/self-host/updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ A new release doesn't email anyone, and neither does an update that finished: **
|---|---|
| **update to vX needs your OK** | A prepared update waits for an admin: to confirm the data or permission changes it lists, to press **Apply**, or for someone with administrator rights in the AWS account. Also when [the model check](#the-model-check) refuses a model the release calls. |
| **update to vX still needs your OK** | The same update still waits 7 days later. Sent once. |
| **update to vX failed** / **rolled back** | The update stopped, or CloudFormation put the previous release back. The email says where the install is now and what to do. |
| **update to vX failed** / **rolled back** | The update stopped, or CloudFormation put the previous release back. The email says where the install is now and what to do. Also when auto-update couldn't start vX at two hourly checks in a row (nothing changed): the email says what stopped it, and **Update history** has a row for each try. A wait (the release still publishing or being verified, another update still being prepared or applied) is never counted. |
| **the new address is live** / **the address change failed** / **back on the AWS address** | A [domain](./domains.md) change finished, failed, or was undone. |
| **what's new, up to vX** | The digest, below. |

Expand Down Expand Up @@ -132,7 +132,7 @@ The **Version** section of **Settings, then System** shows one state at a time,

Under the status, **Check for updates** sits next to when GitHub last answered ("Checked 2 min ago"). The steps of a running update read **Check the release**, **Prepare the change** and **Apply it**, with the current one marked; there is no percentage, because AWS doesn't give a reliable one.

There is only ever one update waiting. A newer prepared update replaces an older one that hasn't run, and the history lists the older one as **Replaced**. An update that AWS is still preparing or already applying is never replaced.
There is only ever one update waiting. A newer release's prepared update replaces an older one that hasn't run, and the history lists the older one as **Replaced**. A second start for the same version (the next hourly check, or another press of **Update**) continues the one prepared, and never replaces it. An update that AWS is still preparing or already applying is never replaced.

## Permissions

Expand Down Expand Up @@ -213,13 +213,13 @@ On an install made with Launch Stack, an update is a stack update of `coderhelm-
4. **Applies it, through the deploy role.** **Settings, then System** shows the change set's summary while it runs: how many resources are added, changed and removed, which ones are replaced, which parts it touches, and a link to it in the CloudFormation console if you want to look.
- **You pressed Update:** it applies as soon as it is prepared. The card says next to the button that one press includes any change to what CoderHelm's own roles may do; those always stay inside the install's permissions boundary, and the deploy role can't change itself or the boundary. When it would replace or remove data, it stops: the card lists what it replaces or removes, in words, and **Replace the data and apply** applies exactly those changes (if they changed since the page showed them, it asks again). The raw CloudFormation list is under **Technical details**.
- **The maintenance window started it (auto-update on):** it applies by itself, except when it would replace or remove data or change permissions: then it waits, admins get an email, and you confirm it on the page the same way. If auto-update was turned off before it ran, it waits for you to press **Apply**.
- **What counts as a permission change.** CloudFormation reports a policy that names another part's output as changed on every update, because that value is known only once the update runs. So the updater compares each such policy, role or resource policy with the running release's: both resolved the way the template resolves them, policy documents as IAM reads them (order doesn't matter). Only a difference in what it allows, on which resources or under which conditions, counts. A new role or policy, and one that can't be compared, always counts. Each release's notes list its permission changes against the release before it, compared the same way.
- **What counts as a permission change.** CloudFormation reports a policy that names another part's output as changed on every update, because that value is known only once the update runs. So the updater compares what the new release allows with what the running one allows, both resolved the way the template resolves them: every role, policy and resource policy of a part together, as grants of an action on a resource, to someone, under a condition. Only something newly allowed counts: a grant no running one covers, or a deny or a permissions boundary the new release drops. A statement moved to another policy of the same role (CDK splits a large role policy into overflow policies), a different order, a log group's ARN written with or without `:*`, a condition added, or an action or resource removed allows nothing new and applies by itself. A statement with `NotAction`, `NotResource` or `NotPrincipal`, and anything that can't be compared, counts whenever it differs. The hold names what becomes newly allowed, for example "newly allows sqs:SendMessage on TicketQueue for the AWS service events.amazonaws.com when aws:SourceArn is MonthTurnSchedule". Each release's notes list its permission changes against the release before it, compared the same way.
- **The deploy role and the permissions boundaries never change in an update.** The deploy role can't change itself or a boundary (that is what keeps it from giving itself more), and executing the change set in the AWS console doesn't get around it: the stack's service role is the deploy role, so AWS runs it as that role whoever presses **Execute**. So every update keeps your install's own deploy role and boundaries exactly as they are, and the rest of the release installs. A release that needs newer ones lists them under [Permissions](#permissions), as a separate step.
- **Before it runs**, the updater checks every IAM call the change set needs against the deploy role's own policy and boundary, as IAM has them now. If one would be refused, the update stops before anything changes and says which call and which rule refused it.
5. **Follows it.** The updater reads the change set and the stack every 5 minutes until the update ends, and again each time **Settings, then System** asks, so the page never shows an older state than CloudFormation's. An update executed outside the app (in the AWS console or the AWS CLI) is followed the same way, and the history records it as applied in the AWS console. Before it calls the update a success, it checks that the stack reports the new release. When the stack update starts, the install's own copy step checks every file of the release against the sha256 that `coderhelm.json` lists before any part changes. If a part fails, CloudFormation rolls the whole stack back to the previous release by itself.
6. **Reports.** The history in **Settings, then System** shows the version, when, who (or "auto") and the result: succeeded, failed, or rolled back. A try that didn't succeed says in plain words what happened, where your install is now and what to do next; CloudFormation's own text (for the first resource that failed) is under **Technical details**. Admins get an email when it failed or rolled back; a finished update is only in the history.

A change set that waits too long can go stale (the stack changed since it was made); the history then says so, and **Update** prepares a new one. Pressing **Update** while an older prepared update waits replaces it (nothing was changed by the older one), and the history lists the older one as **Replaced**. Pressing it while AWS still prepares or already applies an update is refused, with the reason; pressing it again for the update already in progress just shows that update.
A change set that waits too long can go stale (the stack changed since it was made); the history then says so, and **Update** prepares a new one. Pressing **Update** while an older prepared update waits replaces it (nothing was changed by the older one), and the history lists the older one as **Replaced**. An update is never replaced by one to the same version: pressing **Update** for the version already prepared (or the hourly check finding it again) continues that one, and your press counts as your OK for its permission changes. Pressing it while AWS still prepares or already applies an update is refused, with the reason; pressing it again for the update already in progress just shows that update.

Pressing **Update** while the release check still runs is never an error: the press is recorded (who, which version, when), the card shows **Checking vX before it can be applied**, and the update starts by itself once the check passes. If the check fails, the card says why. Pressing again, or a newer release coming out meanwhile, replaces the waiting press: **Update** always means the newest release. While an update is checked, prepared or applied, a newer release is only mentioned on the card ("it's next after this one"); it is offered once the current one finishes.

Expand Down
Loading