mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* perf(iam): cache parsed policy documents in IamPolicyEvaluator Every evaluate call parsed each policy document with Jackson again. A caller with a large managed policy such as ReadOnlyAccess (94 KB) paid that parse on every request under IAM enforcement. The evaluator now keeps the parsed statements per document text in a ConcurrentHashMap. Parsing is a pure function of the text, so entries never go stale. The map is bounded at 2048 entries and cleared when the bound is reached, which only matters for many distinct session policies. A document that fails to parse is cached as failed, so the warning is logged once instead of on every request. AWS managed policy catalog has 1566 documents. All 1566 parsed take about 9.5 MB of heap, and AWS caps a customer managed policy at 6144 characters and a session policy at 2048, so 2048 entries stay within tens of MBs in the worst case. * perf(iam): store policy patterns lowercased in the parsed statement cache Action and Resource matching is case-insensitive. globMatches lowercased both the pattern and the request value on every comparison, which for a policy like ReadOnlyAccess meant about 5800 new strings per request. The patterns are now lowercased once when the document is parsed and cached, and the request action and resource are lowercased once per evaluation. The public globMatches helper used by the trust policy and S3 public access evaluators is unchanged. * fix(iam): compare resource ARNs case-sensitively AWS documents the Action element as case-insensitive, but the Resource element is not: the IAM user name in a Resource ARN is case sensitive, and so are S3 object keys. The evaluator lowercased both sides of every Resource and NotResource comparison, so a grant on user/Bob also matched user/bob and a grant on bucket/Private/* also matched bucket/private/*. Resource and NotResource patterns are now kept as written in the parsed statement cache and the request resource is compared as is. Action and NotAction patterns stay lowercased once at parse time.