mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
The Service Reference lists lambda:GetLayerVersion among the actions CreateFunction and UpdateFunctionConfiguration are authorized by, and the Lambda Developer Guide says what it is checked on: "Make sure that you have permission to call the GetLayerVersion API on the layer version". Floci checked neither operation as it, so a caller allowed to create or update functions added any layer version of its account, whatever its policies said about reading it. tools/aws/fetch_lambda_layer_permissions.py vendors that sentence from the adding-layers page, with the action and the resource it names, and refuses a page asking for permission to call an API in any other wording. The request-resources generator reads it (api_permission_resources): an operation the Service Reference lists as authorized by that action is also checked as it on each value of the request's member holding botocore's ARN shape for the type the words name (`<Type>Arn`, as minted_types reads it; `Layers`, a list of `LayerVersionArn`, for a `layerVersion`). CreateFunction and UpdateFunctionConfiguration now check lambda:GetLayerVersion on each layer version their Layers give, and a request giving none is not checked as it; no other operation changes. --verify reports an operation checked so whose action the Service Reference stops listing (verify_api_actions). CreateFunction is the first operation checked by parts that also tags what it creates, so IamEnforcementFilter now checks an operation's own action, where it is one of the parts, as it would be alone: with the request's tags (aws:RequestTag, aws:TagKeys) and carried values, not the bare part context. The checks made after it, the tagging action a create also needs, a companion and a forwarded action, are made on the resources that action was checked on, not on *, so lambda:TagResource is again checked on the function a tagged create makes. Another account's layer version is checked on its ARN alone: LambdaStoredResourceArns answers reachedInItsAccount for it, as Lambda reads such a layer in its owner's account through the owner's policy and never as the caller's layer of that name, where IAM also checked the caller's same-named layer before (GetLayerVersionByArn too). The table is regenerated against today's Service Reference too, which the online gate this change runs requires: AWS added SageMaker's leaderboard and model-monitor-config types (their ARN formats and tag keys, and the types of AddTags, DeleteTags and ListTags) and lists a backup-external namespace the table does not read. The docs and two comments in LambdaService and LambdaLayerService no longer say Floci implements no layer permissions.
43 lines
2.2 KiB
Python
43 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Tests for fetch_lambda_layer_permissions.py, on pages in the AWS Lambda Developer Guide's markup."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
import fetch_lambda_layer_permissions as f
|
|
|
|
ASKS = ("<p>Make sure that you have permission to call the <code>GetLayerVersion</code> API on the\n"
|
|
" layer version. For Event Functions in your AWS account, you must have this permission in\n"
|
|
" your <a href=\"#\">user policy</a>. To use a layer in another account, the owner of that account must "
|
|
"grant your account permission in a resource-based policy.</p>")
|
|
|
|
|
|
def page(*paragraphs: str) -> str:
|
|
return (f'<div id="main-col-body"><h1>Adding layers</h1><p>You can add layers.</p>{"".join(paragraphs)}'
|
|
f'<h2>Finding layer information</h2></div><div class="prev-next"></div>')
|
|
|
|
|
|
def test_the_sentence_asking_for_permission_to_call_an_api_is_read_with_its_action_and_resource():
|
|
built = f.build(page(ASKS))
|
|
assert built["apiPermissions"] == [{
|
|
"paragraph": "Make sure that you have permission to call the GetLayerVersion API on the layer version. For "
|
|
"Event Functions in your AWS account, you must have this permission in your user policy. To use "
|
|
"a layer in another account, the owner of that account must grant your account permission in a "
|
|
"resource-based policy.",
|
|
"sentence": "Make sure that you have permission to call the GetLayerVersion API on the layer version.",
|
|
"action": "lambda:GetLayerVersion", "on": "layer version"}]
|
|
|
|
|
|
def test_a_page_whose_layout_or_wording_changed_is_refused():
|
|
with pytest.raises(ValueError, match="asks for permission to call no API"):
|
|
f.build(page("<p>Layers are versioned.</p>"))
|
|
# A sentence asking for an API AWS rewords is refused rather than dropping its action.
|
|
with pytest.raises(ValueError, match="in no wording it used"):
|
|
f.build(page(ASKS.replace("Make sure that you have", "You need")))
|
|
|
|
|
|
def test_the_file_is_stale_when_the_page_says_something_else():
|
|
vendored = f.build(page(ASKS))
|
|
assert not f.stale(vendored, page(ASKS))
|
|
assert f.stale(vendored, page(ASKS.replace("on the\n layer version", "on the\n layer")))
|