mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
Under IAM enforcement a request that tags the resource it creates was checked only for the operation's own action. AWS also checks the service's tagging action, as the SNS API reference says: "To be able to tag a topic on creation, you must have the sns:CreateTopic and sns:TagResource permissions." A caller allowed to create but not to tag could set at creation the tags that a tag-based policy trusts. The operation's own action did not see the tags either: aws:RequestTag and aws:TagKeys were set only for Logs, S3 and EC2 RunInstances, so a policy allowing sqs:CreateQueue only with aws:RequestTag/team never matched, and one denying it when aws:RequestTag/team is null refused a tagged create. AWS's Service Reference lists the tagging action among each operation's authorized actions and marks the actions that only tag, but does not say which request member carries the tags; botocore's models do. A new generator, tools/aws/regen_iam_tag_on_create.py, joins the two into src/main/resources/aws/iam-tag-on-create.json: 581 operations over 69 namespaces, those Floci authorizes by operation. An operation is in it when the reference lists, beside its own, an action that only tags and adds tags; its tags are read from a top-level member named Tags, TagList, TagSpecifications or the like that holds a tag list or map. 569 are read from the table (579 members), CloudWatch Logs CreateLogGroup is checked by hand as before, and 11 carry no tags this file can read, each with its reason. A correction gives SQS's Query name, Tag.N, and one drops an EC2 IPAM pool's allocation rule, which tags nothing. When a request carries tags, IamEnforcementFilter checks the tagging action for each resource's tags apart, with them as aws:RequestTag/<key> and aws:TagKeys, and, where the action takes it, the operation as its namespace's CreateAction key (ec2:CreateAction is RunInstances for an instance launched with tags). A tag specification's tags are checked on the resource of the type it names, from the ARN the reference gives the type with its name left open (arn:aws:ec2:<Region>:<account>:instance/*), which the table carries for EC2 and RDS; other tags on the resources the operation is checked on. Lambda's CreateFunction is now checked on the function its body names, which the reference gives it, rather than on *, so a grant scoped to the function covers both its action and its tags. The operation's own action is checked with the same two keys, once for each resource's tags, where the reference lists them for it or for a resource it acts on (542 of the 569), keeping any a service's own condition keys set. The table is keyed by operation, so the filter now carries the operation it resolved beside the action, which differs for an operation AWS authorizes under another name (Budgets' CreateBudget is budgets:ModifyBudget). The tags are read as the Floci handler that applies them reads them, so the check sees the tags the resource gets. A form's are read under the SDK's spelling, from 1 to the first number with no key, and under the further spellings the RDS, DocumentDB, Neptune, ElastiCache and Redshift handlers read, numbered as each numbers them; EC2's from every tag specification under either TagSpecification spelling, to the first naming no resource type. A body's member is read under its own name, and CloudWatch's PutMetricAlarm and PutCompositeAlarm also under tags, and a CodeDeploy tag as Key and Value or key and value, each as text whatever it holds, as its handler reads. The tagging action is also checked for tags under any other spelling a handler might read (a name, key or value in any case, any list spelling and number, an object's structures), so none a handler applies goes unchecked. The operation's own action is checked with every reading, its handler's, any other spelling's, and none where its handler reads none, and refused if any is denied, so a deny on a tag holds and a required tag counts only where the handler applies it. make iam-tag-on-create-check, part of aws-data-check, re-derives every member from the pinned botocore; make iam-tag-on-create-verify, part of iam-data-verify, checks every operation against AWS, and the IAM data drift workflow also runs on a change to the table or its generator. Not checked: sts:TagSession in a role's trust policy, service-specific request tag keys such as rds:req-tag, EC2 RequestSpotFleet's nested tags, and the REST services whose routes no rule maps yet.
81 lines
4.0 KiB
YAML
81 lines
4.0 KiB
YAML
name: IAM Data Drift
|
|
|
|
# Checks the five vendored files that come from AWS's live service reference rather than from a
|
|
# pinned dependency: the IAM service namespace list, the map of which resource each IAM action is
|
|
# authorized against, the map of operations AWS authorizes as an action of another name, the
|
|
# table of the operations that pass a role and the services they pass it to, and the table of the
|
|
# tagging actions operations that tag what they create need. That
|
|
# needs the live service reference index, so unlike every other check here it can
|
|
# fail without anything in the repository having changed: an AWS outage, or a namespace AWS has
|
|
# retired. It therefore runs on its own, never as part of a job that ordinary changes trigger.
|
|
#
|
|
# Two triggers, for two different failures:
|
|
#
|
|
# - On a pull request that touches a vendored file or its generator, which is where a
|
|
# hand-typed or mistyped entry would enter the repository. A pull request that does not touch
|
|
# them cannot introduce one, so it does not run and cannot be failed by an outage.
|
|
# - Weekly, because the files also go stale without anyone touching them: AWS ships services
|
|
# and actions, and occasionally retires them. Tying the only upstream check to pull request
|
|
# activity would mean a quiet month is a month with no drift detection at all.
|
|
#
|
|
# An entry AWS has *added* since the last sync is reported without failing: a new namespace makes
|
|
# the service-last-accessed report incomplete rather than wrong, and a new action or resource type
|
|
# leaves that action evaluated against `*`, which is where it was before any of this existed. The
|
|
# fix for a real failure is to run the matching sync target and commit the result.
|
|
#
|
|
# The offline shape check is hermetic and runs per pull request inside the "Vendored AWS data in
|
|
# sync" job in partition-literals.yml instead.
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'src/main/resources/aws/iam-service-namespaces.json'
|
|
- 'src/main/resources/aws/iam-action-resources.json'
|
|
- 'tools/aws/regen_service_namespaces.py'
|
|
- 'tools/aws/test_regen_service_namespaces.py'
|
|
- 'tools/aws/regen_iam_action_resources.py'
|
|
- 'tools/aws/test_regen_iam_action_resources.py'
|
|
- 'src/main/resources/aws/iam-authorized-actions.json'
|
|
- 'tools/aws/regen_iam_authorized_actions.py'
|
|
- 'tools/aws/test_regen_iam_authorized_actions.py'
|
|
- 'src/main/resources/aws/iam-passed-roles.json'
|
|
- 'tools/aws/regen_iam_passed_roles.py'
|
|
- 'tools/aws/test_regen_iam_passed_roles.py'
|
|
- 'src/main/resources/aws/iam-tag-on-create.json'
|
|
- 'tools/aws/regen_iam_tag_on_create.py'
|
|
- 'tools/aws/test_regen_iam_tag_on_create.py'
|
|
- '.github/workflows/iam-data-drift.yml'
|
|
schedule:
|
|
# Mondays at 06:00 UTC, before the working week rather than during it.
|
|
- cron: '0 6 * * 1'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
# One job, and one step that runs both verifies. They are kept in a single Makefile target rather
|
|
# than two steps because sequential steps stop at the first failure: while the namespace list was
|
|
# stale, the action resource check never ran at all, so the half that was still fine went
|
|
# unreported. The target runs both regardless and fails afterwards, naming which file drifted.
|
|
jobs:
|
|
iam-data-drift:
|
|
name: Vendored IAM data still matches upstream
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
with:
|
|
python-version: "3.x"
|
|
|
|
# No dependency install: the generators are deliberately stdlib-only, and this job runs no
|
|
# tests. The pinned botocore the sibling workflow needs is for the partition generator.
|
|
- name: Check every vendored IAM file still matches upstream
|
|
run: make iam-data-verify
|