mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 00:21:51 -05:00
Under enforcement a REST route no vendored model names runs unchecked, and AWS Backup was among them: a caller could start a backup job or assign resources to a backup plan with any role and no iam:PassRole, and a grant scoped to one backup vault or plan covered every one, as #6255 reports. Backup's model routes are vendored, so each request is checked as its operation's action, and Backup joins the tables of request resources, passed roles and tags on create. The Service Reference passes most of Backup's roles to one service, which the passed-roles generator reads alone: IamRoleArn to backup.amazonaws.com, a backup plan's scan settings' ScannerRoleArn to malware-protection.guardduty.amazonaws.com, and a restore testing selection's to restore-testing.backup.amazonaws.com. It passes StartScanJob's IamRoleArn and ScannerRoleArn to both of the first two without saying which goes where, so a vendored source, tools/aws/sources/backup-roles.json, written by tools/aws/fetch_backup_roles.py from the developer guide's malware protection page, gives each: the scanner role "trusts malware-protection.guardduty.amazonaws.com", and the backup role is "the same role found in ... the BackupSelection API", linking CreateBackupSelection, whose role the Service Reference passes to backup alone. The generator reads such a role as going where the reference passes that operation's roles, when that is one service. A backup vault is checked by its name and a backup plan by its id; BackupStoredResourceArns answers the tags Backup holds on either, which an aws:ResourceTag condition reads. A recovery point's format the Service Reference gives with a literal * account, which the reader matches as written, so a request naming a recovery point by its ARN is checked on *, as one naming a DMS endpoint is. A namespace the table reads is served on the shared tag routes only with a method its model gives on the path, as it already was only on the paths its model gives: Backup removes tags with POST /untag/{resourceArn}, so a DELETE on its /tags/{resourceArn}, which no Backup operation is and no action checks, was let through and removed tags an aws:ResourceTag deny relies on. It is now refused with MethodNotAllowedException (405), as a tag call sent with the other verb is. Closes #6255.
69 lines
3.7 KiB
Python
69 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Tests for fetch_backup_roles.py, on pages in the AWS Backup API reference's and developer guide's markup."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
import fetch_backup_roles as f
|
|
|
|
API = f.API_REFERENCE
|
|
|
|
|
|
def entry(member: str, description: str) -> str:
|
|
return (f'<dl><dt id="Backup-StartScanJob-request-{member}"><b><code class="code">{member}</code></b></dt>'
|
|
f'<dd><p>{description}</p><p>Type: String</p></dd></dl>')
|
|
|
|
|
|
BACKUP_ROLE = ('<li class="listitem"><p>First, the <a href="https://docs.aws.amazon.com/aws-managed-policy/latest/'
|
|
'reference/AWSBackupServiceRolePolicyForScans.html">AWSBackupServiceRolePolicyForScans</a> managed '
|
|
'policy must be attached to your existing or new backup role. This is the same role found in the '
|
|
'resource assignment for your backup plan in the console, or through the <a href="' + API
|
|
+ 'API_CreateBackupSelection.html">BackupSelection API</a>.</p></li>')
|
|
SCANNER_ROLE = ('<li class="listitem"><p>Second, a new scanner role is required that trusts <code class="code">'
|
|
'malware-protection.guardduty.amazonaws.com</code>. This is the same role found in the scan settings '
|
|
'in your <a href="' + API + 'API_CreateBackupPlan.html">BackupPlan API</a>.</p></li>')
|
|
|
|
|
|
def malware(items: str) -> str:
|
|
return ('<div id="main-col-body"><h2 id="malware-access">Access</h2><p>AWS Backup malware scanning requires two '
|
|
f'IAM roles:</p><ul class="itemizedlist">{items}</ul><h2 id="next">Incremental vs full scans</h2></div>')
|
|
|
|
|
|
PAGES = {
|
|
API + "API_StartScanJob.html": (
|
|
entry("IamRoleArn", "Specifies the IAM role ARN used to create the target recovery point.")
|
|
+ entry("ScannerRoleArn", "Specified the IAM scanner role ARN.")),
|
|
f.MALWARE_PROTECTION: malware(BACKUP_ROLE + SCANNER_ROLE),
|
|
}
|
|
|
|
|
|
def test_each_member_is_read_with_what_the_guide_says_of_its_role():
|
|
built = f.build(lambda url: PAGES[url])
|
|
by_member = {m["member"]: m for m in built["members"]}
|
|
# The scanner role trusts its service; the backup role is CreateBackupSelection's, the operation its item links.
|
|
assert by_member["ScannerRoleArn"]["trustedBy"] == ["malware-protection.guardduty.amazonaws.com"]
|
|
assert "sameRoleAs" not in by_member["ScannerRoleArn"]
|
|
assert by_member["IamRoleArn"]["sameRoleAs"] == {"operation": "CreateBackupSelection"}
|
|
assert "trustedBy" not in by_member["IamRoleArn"]
|
|
assert by_member["IamRoleArn"]["description"].startswith("Specifies the IAM role ARN used to create")
|
|
assert by_member["IamRoleArn"]["roleText"].startswith("First, the AWSBackupServiceRolePolicyForScans")
|
|
|
|
|
|
def test_a_page_whose_layout_changed_is_refused():
|
|
for url, page, message in (
|
|
(API + "API_StartScanJob.html", entry("ScannerRoleArn", "A role."), "has no entry"),
|
|
(f.MALWARE_PROTECTION, "<div id=\"main-col-body\"></div>", "has no section"),
|
|
(f.MALWARE_PROTECTION, malware(SCANNER_ROLE), "names the backup role in 0 items"),
|
|
(f.MALWARE_PROTECTION, malware(BACKUP_ROLE.replace("This is the same role found in", "It is like")
|
|
+ SCANNER_ROLE), "neither what the backup role trusts")):
|
|
changed = dict(PAGES, **{url: page})
|
|
with pytest.raises(ValueError, match=message):
|
|
f.build(lambda u: changed[u])
|
|
|
|
|
|
def test_the_file_is_stale_when_a_page_says_something_else():
|
|
vendored = f.build(lambda url: PAGES[url])
|
|
assert not f.stale(vendored, PAGES)
|
|
assert f.stale(vendored, dict(PAGES, **{f.MALWARE_PROTECTION: malware(
|
|
BACKUP_ROLE + SCANNER_ROLE.replace("malware-protection.guardduty", "guardduty"))}))
|